branch divergence ?


what happens if I replace

if (a>1) 





b = (a>1) * a

concerning branch divergence ? Can (a>1) be executed as a algebraic calculation ?

Greetings, Uwe

the under policy is better

This falls into the category of premature optimization, which is bad. At the very least, if you’re going to trade readability for performance, make sure you get at least some performance.

I did a test, and the above two compile to the exact same ptx: 	%p1, %r3, %r4;   	// 

	selp.s32 	%r5, %r1, %r2, %p1; 	//

Use the form that is more clear. For me, I find the if/else to be more readable. Or, another good option in my opinion is b = (a > 1) ? a : 0; which also generates the same ptx.