In my code I have the following situation (somewhat simplified here):

uint x =0;

uint a = ‘some math’;

uint b = ‘some other math’;

uint c = 'some more math;

now I would like to select the maximum value: x = max(x,a,b,c)

Whatever I use the max-function or construct if-statements (which max does I imagine), the performance drops by several factors. Is it true this come from warp divergence?

And is there some basic expression to select the maximum value? I’ve tried stuff like:

(( a-b ) >>(sizeof(uint)*8-1))*b but this is even slower than using if-statements…

Any help would be highly appreciated!

Edit: removed wierd smily from code…