On Tue, Jul 09, 2013 at 10:20:18AM +0100, Richard Earnshaw wrote: > On ARM, CLZ has a defined result at zero (32). Furthermore, the > ACLE specification defines (in the header arm_acle.h) __clz(n) as > an intrinsic aimed at the CLZ instruction; __clz() has a defined > result at 0. We want to use __builtin_clz as the implementation for > __clz rather than inventing another one; but that would require the > compiler to handle zero correctly.
The patch that has been committed is the conservative one, so it handles any __builtin_clz{,l,ll,imax} (0) returning the mode bitsize (because that is pretty much the only value used for 0 by targets if they specify it). __builtin_ctz{,l,ll,imax} (0) is a different matter, because the value at 0 varries a lot (-1, mode bitsize, undefined) for the cases where there is optab, and for the case where __builtin_ctz needs to be implemented say using clz, or in wider mode, or through library routines you really can't expect anything meaningful. So, for CTZ you get the target defined value for 0 if there is one only if you have a ctz optab for that mode and CTZ_DEFINED_VALUE_AT_ZERO, otherwise the patch treats it as undefined. Jakub