Basically, it just directly translates the OpenCL built-in 'select' into the SPIR-V OpCode "ExtInst Select".
However, in OpenCL.ExtendedInstructionSe.100.pdf from Khronos website: page 51
2.5 Relational instructions
This section describes the list of relational instructions that take scalar or vector arguments. The vector versions of the integer functions operate component-wise. The description is per-component.
select
Each bit of the result is the corresponding bit of a if the corresponding bit of c is 0. Otherwise it is the corresponding
bit of b.
Apparently, the OpenCL built-in "select" has a different meaning from the SPIR-V's "ExtInst select".
OpenCL select:
result[i] = if MSB of c[i] is set ? b[i] : a[i].
SPIR-V "Ext select": bit by bit
result[i] = c[i] ? b[i] : a[i].
It is not correct by simply converting 'select' built-in into 'Ext select'. Is it right?
OpenCL 1.2 SPec Table 6.14:
gentype select (gentype a, gentype b, igentype c)
For each component of a vector type, result[i] = if MSB of c[i] is set ? b[i] : a[i].
I write the following simple kernel:
typedef int4 T;
kernel void test(global T* result, global T* a, global T* b, __global T* c) { result[0] = select( a[0], b[0], c[0] ); }
And the tool generates the following SPV file:
5 Function 2 7 0 6 3 FunctionParameter 5 8 3 FunctionParameter 5 9 3 FunctionParameter 5 10 3 FunctionParameter 5 11
2 Label 12 5 InBoundsPtrAccessChain 5 14 9 13 6 Load 4 15 14 2 16 5 InBoundsPtrAccessChain 5 16 10 13 6 Load 4 17 16 2 16 5 InBoundsPtrAccessChain 5 18 11 13 6 Load 4 19 18 2 16 8 ExtInst 4 20 1 select 15 17 19 5 InBoundsPtrAccessChain 5 21 8 13 5 Store 21 20 2 16 1 Return
1 FunctionEnd
Basically, it just directly translates the OpenCL built-in 'select' into the SPIR-V OpCode "ExtInst Select".
However, in OpenCL.ExtendedInstructionSe.100.pdf from Khronos website: page 51
2.5 Relational instructions This section describes the list of relational instructions that take scalar or vector arguments. The vector versions of the integer functions operate component-wise. The description is per-component.
select
Each bit of the result is the corresponding bit of a if the corresponding bit of c is 0. Otherwise it is the corresponding bit of b.
Apparently, the OpenCL built-in "select" has a different meaning from the SPIR-V's "ExtInst select".
OpenCL select: result[i] = if MSB of c[i] is set ? b[i] : a[i].
SPIR-V "Ext select": bit by bit result[i] = c[i] ? b[i] : a[i].
It is not correct by simply converting 'select' built-in into 'Ext select'. Is it right?