From 0af0295acf508dac297b99e6b95e607282b56c1b Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sat, 26 Aug 2023 02:43:47 -0500 Subject: [PATCH] feat: support lib use at compile-time --- src/lib.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.zig b/src/lib.zig index c521a44..083b5fd 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -53,6 +53,8 @@ const Log2Int = std.math.Log2Int; /// match("1ab0", @as(u4, 0b1010)) // true /// ``` pub fn match(comptime bit_string: []const u8, value: anytype) bool { + @setEvalBranchQuota(std.math.maxInt(u32)); // FIXME: bad practice + const ValT = @TypeOf(value); comptime verify(ValT, bit_string); @@ -139,7 +141,7 @@ pub fn extract(comptime bit_string: []const u8, value: anytype) Bitfield(bit_str // // we're confident in this because it's guaranteed to be the same bit_string, // and it's the same linear search. If you're reading this double check that this is still the case lol - break :blk @truncate(if (bmi2) pext.hardware(u32, value, masked_val) else pext.software(u32, value, masked_val)); + break :blk @truncate(if (bmi2 and !@inComptime()) pext.hardware(u32, value, masked_val) else pext.software(u32, value, masked_val)); }; }