diff options
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/src/value.zig b/src/value.zig index 94769b4da7..a029be6c7b 100644 --- a/src/value.zig +++ b/src/value.zig @@ -1677,22 +1677,8 @@ pub const Value = extern union { @panic("TODO implement i64 Value clz"); }, .int_big_positive => { - // TODO: move this code into std lib big ints const bigint = val.castTag(.int_big_positive).?.asBigInt(); - // Limbs are stored in little-endian order but we need - // to iterate big-endian. - var total_limb_lz: u64 = 0; - var i: usize = bigint.limbs.len; - const bits_per_limb = @sizeOf(std.math.big.Limb) * 8; - while (i != 0) { - i -= 1; - const limb = bigint.limbs[i]; - const this_limb_lz = @clz(limb); - total_limb_lz += this_limb_lz; - if (this_limb_lz != bits_per_limb) break; - } - const total_limb_bits = bigint.limbs.len * bits_per_limb; - return total_limb_lz + ty_bits - total_limb_bits; + return bigint.clz(ty_bits); }, .int_big_negative => { @panic("TODO implement int_big_negative Value clz"); @@ -1703,6 +1689,12 @@ pub const Value = extern union { return ty_bits; }, + .lazy_align, .lazy_size => { + var bigint_buf: BigIntSpace = undefined; + const bigint = val.toBigIntAdvanced(&bigint_buf, target, null) catch unreachable; + return bigint.clz(ty_bits); + }, + else => unreachable, } } @@ -1721,16 +1713,8 @@ pub const Value = extern union { @panic("TODO implement i64 Value ctz"); }, .int_big_positive => { - // TODO: move this code into std lib big ints const bigint = val.castTag(.int_big_positive).?.asBigInt(); - // Limbs are stored in little-endian order. - var result: u64 = 0; - for (bigint.limbs) |limb| { - const limb_tz = @ctz(limb); - result += limb_tz; - if (limb_tz != @sizeOf(std.math.big.Limb) * 8) break; - } - return result; + return bigint.ctz(); }, .int_big_negative => { @panic("TODO implement int_big_negative Value ctz"); @@ -1741,6 +1725,12 @@ pub const Value = extern union { return ty_bits; }, + .lazy_align, .lazy_size => { + var bigint_buf: BigIntSpace = undefined; + const bigint = val.toBigIntAdvanced(&bigint_buf, target, null) catch unreachable; + return bigint.ctz(); + }, + else => unreachable, } } |
