Re:EABitTricks.h
by danbruc on Tuesday December 20, 2022 @03:19AM
(#34063083)
Two shifts? I think ctz plus a single shift should do.
With all the fancy bit level instruction, this could probably be simplified in general, but I usually avoid them because I mostly see this as an exercise in making it work if you only have access to the basic arithmetic and logic operations and shifts.
[ Parent
| on HN ]
Re:EABitTricks.h
by anonymoushn on Tuesday December 20, 2022 @02:54PM
(#34071536)
You need two shifts in C++ because shifting a uint32_t by 32 is UB. Every actual computer probably gives you 0 if you shift 0 right by a too-large amount though...