Hi! On Tue, Nov 12, 2019 at 02:35:54PM +0000, Wilco Dijkstra wrote: > Support common idioms for count trailing zeroes using an array lookup. > The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic > constant which when multiplied by a power of 2 contains a unique value > in the top 5 or 6 bits. This is then indexed into a table which maps it > to the number of trailing zeroes. When the table is valid, we emit a > sequence using the target defined value for ctz (0): > > int ctz1 (unsigned x) > { > static const char table[32] = > { > 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, > 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 > }; > > return table[((unsigned)((x & -x) * 0x077CB531U)) >> 27]; > }
Out of interest, what uses this? I have never seen it before. Segher