cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

viscocoa
Adept I

how to dynamically index to vector component

I have a piece of code as below:

...

int4 vec;

...

if (condition == 0)

    vec.x = 100;

else if (condition == 1)

    vec.y ++;

else if (condition == 2)

    vec.z ++;

else

    vec.w ++;

Is it possible to index to the component dynamically to avoid branching? Ideally, I can do this:

vec.condition ++;

But the above code does not work

0 Likes
1 Solution

No, vectors cannot be dynamically indexed. Your best bet is to push the vector into private array, index into it and hope that the compiler can optimize it into register based indexing.

View solution in original post

0 Likes
10 Replies