unfortunately the ffs/clz/ctz/popcount/parity builtins are defined to return signed types despite the fact they are either undefined or return a non-negative integer. as a result unnecessary sign extension occurs. for example in this case the result of bsf could be used directly in the mask[] index.
-dean % cat ctz.c unsigned mask[8]; unsigned foo(unsigned y, unsigned char x) { return y & mask[__builtin_ctz(x)]; } % ~/gcc/bin/gcc -g -O3 -Wall -c ctz.c % objdump -dr ctz.o ctz.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <foo>: 0: 40 0f b6 f6 movzbl %sil,%esi 4: 0f bc f6 bsf %esi,%esi 7: 48 63 f6 movslq %esi,%rsi a: 23 3c b5 00 00 00 00 and 0x0(,%rsi,4),%edi d: R_X86_64_32S mask 11: 89 f8 mov %edi,%eax 13: c3 retq % ~/gcc/bin/gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../gcc/configure --prefix=/home/odo/gcc --enable-languages=c --enable-targets=x86_64-unknown-linux-gnu x86_64-unknown-linux-gnu : (reconfigured) ../gcc/configure --prefix=/home/odo/gcc --enable-languages=c --without-mudflap --disable-biarch x86_64-unknown-linux-gnu : (reconfigured) ../gcc/configure --prefix=/home/odo/gcc --enable-languages=c --disable-multilib --disable-biarch x86_64-unknown-linux-gnu Thread model: posix gcc version 4.3.0 20061104 (experimental) -- Summary: result of ffs/clz/ctz/popcount/parity are already sign- extended Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dean at arctic dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29776