From the previous question about Set n least significant bits to 1, and the great answer from that, I've written a function to find if a positive integer is a power-of-two:
# Is 16 a multiple of 8 (2^3)? Yes
mov $16, %edi
mov $3, %esi
call pow_2_short
pow_2_short:
mov $1, %eax
mov %sil, %cl # move low byte of %esi (the power of 2) into %cl for the shift
shl %cl, %eax
dec %rax
test %eax, %edi
jz _set_true; jnz _set_false
_set_false:
xor %eax, %eax
ret
_set_true:
mov $1, %eax
ret
My main question about this is the conditional part which seems a bit odd to me. Is the above pattern a common way to basically do:
if x:
// do this
else:
// something else
If not, what's a more idiomatic way to do that?