2019-05-01 02:17:16 +08:00
|
|
|
const std = @import("std");
|
|
|
|
const expect = std.testing.expect;
|
|
|
|
const math = std.math;
|
|
|
|
|
2020-07-11 19:09:04 +08:00
|
|
|
fn ctz(x: anytype) usize {
|
2019-12-10 04:56:19 +08:00
|
|
|
return @ctz(@TypeOf(x), x);
|
2019-05-01 02:17:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
test "fixed" {
|
2021-05-05 02:23:22 +08:00
|
|
|
try testClz();
|
|
|
|
comptime try testClz();
|
2019-05-01 02:17:16 +08:00
|
|
|
}
|
|
|
|
|
2021-05-05 02:23:22 +08:00
|
|
|
fn testClz() !void {
|
|
|
|
try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
|
|
|
|
try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
|
|
|
|
try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
|
|
|
|
try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
|
2019-05-01 02:17:16 +08:00
|
|
|
}
|