Consider the following OpenCL code in which each element in a vector-type variable gets its value via array lookup:
float* tbl = get_data();
int4 offsets = get_offsets();
float4 my_elements = {
tbl[offsets.x],
tbl[offsets.y],
tbl[offsets.z],
tbl[offsets.w]
};
... and never mind the specific types and vector-size I used, i.e. I used float
and int
and size-4 vectors, but it might have been, say, ushort
values, long
indices and a size-8 vector.
I don't like the repetitiveness of that code. What is a better OpenCL idiom for doing this kind of "elementwise lookup" without the excessive repetition?
float
,int
and 4 specifically is not material here, it's just an example.