This code snippet demonstrates how to jump to a label by its index with brx.idx
instruction.
Unlike the regular if (a == 2) { ... } else { ... }
code (as well as switch (...) { ... }
), the brx.idx
solution avoids multiple setp.ne.s32
comparisons.
> make
nvcc -arch=sm_50 branchtargets.cu -o branchtargets
> ./branchtargets 0
Testing tgt = 0
tgt = 0
BLK0
> ./branchtargets 1
Testing tgt = 1
tgt = 1
BLK1
> ./branchtargets 2
Testing tgt = 2
tgt = 2
BEXIT