Bithacks.h - bit hack macros
catonmat.net
catonmat.net
http://miller.cs.wm.edu/lxr3.linux/http/source/include/linux...
http://miller.cs.wm.edu/lxr3.linux/http/source/include/linux...
http://miller.cs.wm.edu/lxr3.linux/http/source/lib/bitmap.c?...
The comments accompanying the code are interesting too.
Link: http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...
and probably alan mycrofts more useful c-interpretation: http://www.cl.cam.ac.uk/~am21/hakmemc.html
A smart compiler could theoretically transform your crappy implementation of "is the Nth bit set?" into something more intelligent, but it is rarely profitable enough to do so, as programmers who write code in which bit-banging is the bottleneck typically know how to do this themselves; in fact, most of the macros linked are what I consider to be the most parsimonious implementation.
One thing where an intrinsic will definitely beat a C-level implementation is population count (how many bits are set in this int/long?) Many recent x86 parts and many DSPs implement a POPCOUNT/BC instruction which will outperform even a smart LUT-based implementation (without the memory capacity/bandwidth requirement too). There's an interesting anecdote about that instruction here (http://www.moyogo.com/blog/2005/09/secret-opcodes.html ), no idea if it's true.
That, and the fact that this belief persists as they turn off their digital televisions, click their garage door remotes, text a friend on their phone, fire up the engine in their personal vehicle, and drive to work stopping carefully at all the carefully automated traffic lights, swipe their ID card and sit at their desk where they can finally get to see some software.