I'm trying to perform a right shift on Y86-64
To do a left shift I know that I need to multiply by 2^n where n is the number of bit shift we want for example if we want to shift by 4 it's 2^4 = 16 and do a loop of additions to perform multiplication on it but I'm not sure what to do for right shifts I think I need to perform division but not sure on how to approach that
pcount_do:
movq $0, %rax
.L2: movq %rdi, %rdx
shrq %rdi
ret
Given that the instruction set of Y86 misses shifts and divisions, I'd go for something equivalent to this C code:
This should all be doable with just add/sub/and/or plus a lookup table.
If we want to be smarter, as @PeterCordes suggests we can use an 8 entries lookup table and work on whole bytes, but that requires significantly more bookkeeping than looping over each bit.
--- update ---
@PeterCordes correctly notes that the lookup table is actually useless, as I'm looping over bits, so calculating the next power of two using a sum is trivial: