KhronosGroup / KhronosGroup/OpenCL-Docs

Specify truthiness for consumption of vector components for logical operators

Open
#177 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
420
Forks
131
Avg merge
5d 13h
Merged PRs (30d)
11

Description

The OpenCL C specification does not define the semantics for the _consumption_ of integer vector components as logic values for the operands of the binary logical operators (i.e. `&&` and `||`). I.e. although it is not stated, it must be the case that `((int2)(-1, -1) || (int2)(x, y)) == (int2)(-1, -1)` and that `((int2)(0, 0) && (int2)(x, y)) == (int2)(0, 0)`, but it is not clear how the binary logical operators are defined for integer vector component values other than 0 and -1. (The version of Clang that I have tested constant-folds `((int2)(1, 1) || (int2)(x, y))` into `(int2)(-1, -1)`.)

~~The specification also does not explicitly define the semantics of implicit casts from `bool` for the integer vector components of vector literals. I.e. is `(int2)((bool)true, (bool)true)` equivalent to `(int2)(1, 1)` or `(int2)(-1, -1)`? (The version of Clang that I have tested uses `(int2)(1, 1)`.) [Note: this is incorrect: the semantics are well-defined.]~~

It would be good to clarify these semantics, if possible.

Note: the semantics for the representation of logic values as integer vector components for _results_ are clearly defined for all operators including casts from `bool` scalars to the integer vector types, and for the relational built-in functions. The semantics for the _consumption_ of integer vector components as logic values are clearly defined for the unary logical (negation) operator (i.e. `!`), the `select()` built-in function, the ternary selection operator (`?`), and the `any()` and `all()` built-in functions.

The OpenCL C conformance test suite has code in the `integer_ops` test to check that the binary and unary logical operators determine truth for integer vector components by comparing against 0. (Somewhat confusingly, the test for `!` has been implemented as a binary operator test.)

Contributor guide

Open the contributing guide

Research direction

Start with the OpenCL C specification rules for binary logical operators and compare them with the conformance suite's `integer_ops` test. Determine and document how nonzero integer vector components are consumed as logic values, then ensure the specification and the referenced tests agree for `&&` and `||`.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
documentation, testing-qa
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.