Meteorhead

conditional operator behaviour on vector operand

Discussion created by Meteorhead on Jul 21, 2010
Latest reply on Jul 28, 2010 by douglas125

Hi all!

I wanted to neatly vectorize a highly paralellable physics code, which requires only bit operations, so when one vector processor goes through an integer bit by bit to process it, it can do it with 3 neighbouring integers also, all operations are identical.

There is one point where flow control would be needed, but since only the outcome of a single variable depends on it, I thought of avoiding it with the "?" operator. The OpenCL computing doc mentioned a subtle difference between vector and scalar conditional operator behaviour. My first question is simple C:

Where does it matter what the output of the "?" operator is when you must always specify what the output should be through the ":" statement after?

Second question:

If used on vector types, can the outcome be different separately on each element? If I wanted to compare two vectors, and have the result differ by elements based on the elements of the input vectors, is there any way to achieve this without flow control?

Outcomes