Skip to contentSkip to conversation

cntlzw

DISCUSSION Kevin Diggs 3 participants 3 messages Jun 3, 2008 – Jun 6, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

x86 has bsf and bsr. PPC has cntlzw which I think is equivalent to bsr.
Anyone know of a sneaky algorithm to do bsf?

kevin

#1 lore raw
Quoted 4 lines · Kevin Diggs

Hi,

x86 has bsf and bsr. PPC has cntlzw which I think is equivalent to
bsr. Anyone know of a sneaky algorithm to do bsf?

wordsize - 1 - cntlzw(x & ~(x - 1));

-Scott

#2 lore raw

It's in the Compiler Writer's Guide with explanation; section 5-10.

http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF7785256996007558C6

There are lots of clever examples in there, it's definitely recommended reading (I should make a cheat sheet of chapter 5 though so I can pin it to my wall)

Signature · 2 lines
Matt Sealey <[email protected]>
Genesi, Manager, Developer Relations
Quoted 13 lines · Scott Wood
Quoted 4 lines · Kevin Diggs

Hi,

x86 has bsf and bsr. PPC has cntlzw which I think is equivalent to
bsr. Anyone know of a sneaky algorithm to do bsf?

wordsize - 1 - cntlzw(x & ~(x - 1));

-Scott
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev