How fast does this code need to be? David's ffs64 looked pretty good to my inexpert eye, I think you would have to be running it very frequently for something to be measurably faster.

There are some similar discussions here, including some branchless techniques that probably would be faster (not necessarily detectably):
http://stackoverflow.com/questions/757059/position-of-least-significant-bit-that-is-set

One answer also talks about clearing the lowest set bit.

Andrew Rowley


On 24/07/2013 07:49, Charles Mills wrote:
Is there a quick way to reverse MSB to LSB the bits of a 64-bit register? If
I have a register that contains 01234567_89ABCDEF to convert it to
F7B3D591_E6A2C480? (I think I got that at least mostly right.) A bit-wise
Load Reversed?

Yes, I am familiar with the Pops. Hard to find an instruction when you don't
know its name or even if it actually exists.

Why? Those of you following another thread I started know I am looking to
implement a 64-bit version of the UNIX library function ffs(), which returns
the bit number of the least significant one bit of a word. z architecture
provides the FLOGR instruction but it works MSB to LSB. I could potentially
live with that but it would introduce some new complications, one of them
being that counting from the LSB is much more compatible with how C promotes
integer types. If I could flip the bits of a word in one or two hardware
instructions I would have a solution. FLOGR provides an additional benefit
for me because I ultimately want to do the other chore that FLOGR does,
resetting the found bit.

I guess you could do it with TR (to reverse the bits) and then LRVG (to
reverse the bytes) but that is overly complex and probably slow (IMHO).

Thanks in advance,
Charles

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to