aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-11-29 13:40:57 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-11-29 23:30:38 -0700
commitf4666678886c2a7a993ad30b63de4ff25594085a (patch)
tree45cbb5b3ebbe23a46e27b04aa5898a6c00ec4a61 /src/value.zig
parentceb0a632cfd6a4eada6bd27bf6a3754e95dcac86 (diff)
downloadzig-f4666678886c2a7a993ad30b63de4ff25594085a.tar.gz
zig-f4666678886c2a7a993ad30b63de4ff25594085a.zip
stage2: fix crash on comptime lazy `@ctz` and `@clz`
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig38
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,
}
}