| 1 | inline fn bit_count(value: i32) i32 { |
| 2 | var i = value; |
| 3 | // Algo from : http://aggregate.ee.engr.uky.edu/MAGIC/#Population%20Count%20(ones%20Count) |
| 4 | i -= ((i >> 1) & 0x55555555); |
| 5 | i = (i & 0x33333333) + ((i >> 2) & 0x33333333); |
| 6 | i = (((i >> 4) + i) & 0x0F0F0F0F); |
| 7 | i += (i >> 8); |
| 8 | i += (i >> 16); |
| 9 | return (i & 0x0000003F); |
| 10 | } |
| 11 | |
| 12 | inline fn number_of_trailing_zeros(i: i32) u32 { |
| 13 | return @as(u32, bit_count((i & -i) - 1)); |
| 14 | } |
| 15 | |
| 16 | export fn entry() void { |
| 17 | _ = number_of_trailing_zeros(0); |
| 18 | } |
| 19 | |
| 20 | // error |
| 21 | // |
| 22 | // :13:30: error: expected type 'u32', found 'i32' |
| 23 | // :13:30: note: unsigned 32-bit int cannot represent all possible signed 32-bit values |
| 24 | // :17:33: note: called inline here |