authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-19 10:26:51+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-21 01:30:46+01:00
log018262d537959701566f2dfece66a462c3bbc976
treea4d09b23dfd649ffa61313891560b5b33e17810b
parentceb76b2ba705f362dbd5437ec5804b670298b420
signaturelock-open Commit is signed but in an unrecognized format.

std: update eval branch quotas after bdbc485

Also, update `std.math.Log2Int[Ceil]` to more efficient implementations that don't use up so much damn quota!

8 files changed, 17 insertions(+), 21 deletions(-)

lib/std/crypto/aes/soft.zig+2
...@@ -629,6 +629,8 @@ fn generateSbox(invert: bool) [256]u8 {...@@ -629,6 +629,8 @@ fn generateSbox(invert: bool) [256]u8 {
629629
630// Generate lookup tables.630// Generate lookup tables.
631fn generateTable(invert: bool) [4][256]u32 {631fn generateTable(invert: bool) [4][256]u32 {
632 @setEvalBranchQuota(50000);
633
632 var table: [4][256]u32 = undefined;634 var table: [4][256]u32 = undefined;
633635
634 for (generateSbox(invert), 0..) |value, index| {636 for (generateSbox(invert), 0..) |value, index| {
lib/std/crypto/blake2.zig+2-2
...@@ -786,7 +786,7 @@ test "blake2b384 streaming" {...@@ -786,7 +786,7 @@ test "blake2b384 streaming" {
786786
787test "comptime blake2b384" {787test "comptime blake2b384" {
788 comptime {788 comptime {
789 @setEvalBranchQuota(10000);789 @setEvalBranchQuota(20000);
790 var block = [_]u8{0} ** Blake2b384.block_length;790 var block = [_]u8{0} ** Blake2b384.block_length;
791 var out: [Blake2b384.digest_length]u8 = undefined;791 var out: [Blake2b384.digest_length]u8 = undefined;
792792
...@@ -878,7 +878,7 @@ test "blake2b512 keyed" {...@@ -878,7 +878,7 @@ test "blake2b512 keyed" {
878878
879test "comptime blake2b512" {879test "comptime blake2b512" {
880 comptime {880 comptime {
881 @setEvalBranchQuota(10000);881 @setEvalBranchQuota(12000);
882 var block = [_]u8{0} ** Blake2b512.block_length;882 var block = [_]u8{0} ** Blake2b512.block_length;
883 var out: [Blake2b512.digest_length]u8 = undefined;883 var out: [Blake2b512.digest_length]u8 = undefined;
884884
lib/std/enums.zig+1-1
...@@ -6,7 +6,7 @@ const testing = std.testing;...@@ -6,7 +6,7 @@ const testing = std.testing;
6const EnumField = std.builtin.Type.EnumField;6const EnumField = std.builtin.Type.EnumField;
77
8/// Increment this value when adding APIs that add single backwards branches.8/// Increment this value when adding APIs that add single backwards branches.
9const eval_branch_quota_cushion = 5;9const eval_branch_quota_cushion = 10;
1010
11/// Returns a struct with a field matching each unique named enum element.11/// Returns a struct with a field matching each unique named enum element.
12/// If the enum is extern and has multiple names for the same value, only12/// If the enum is extern and has multiple names for the same value, only
lib/std/hash/xxhash.zig+1-1
...@@ -890,7 +890,7 @@ test "xxhash32 smhasher" {...@@ -890,7 +890,7 @@ test "xxhash32 smhasher" {
890 }890 }
891 };891 };
892 try Test.do();892 try Test.do();
893 @setEvalBranchQuota(75000);893 @setEvalBranchQuota(85000);
894 comptime try Test.do();894 comptime try Test.do();
895}895}
896896
lib/std/math.zig+8-16
...@@ -749,31 +749,23 @@ test rotl {...@@ -749,31 +749,23 @@ test rotl {
749 try testing.expect(rotl(@Vector(1, u32), @Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);749 try testing.expect(rotl(@Vector(1, u32), @Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
750}750}
751751
752/// Returns an unsigned int type that can hold the number of bits in T752/// Returns an unsigned int type that can hold the number of bits in T - 1.
753/// - 1. Suitable for 0-based bit indices of T.753/// Suitable for 0-based bit indices of T.
754pub fn Log2Int(comptime T: type) type {754pub fn Log2Int(comptime T: type) type {
755 // comptime ceil log2755 // comptime ceil log2
756 if (T == comptime_int) return comptime_int;756 if (T == comptime_int) return comptime_int;
757 comptime var count = 0;757 const bits: u16 = @typeInfo(T).Int.bits;
758 comptime var s = @typeInfo(T).Int.bits - 1;758 const log2_bits = 16 - @clz(bits - 1);
759 inline while (s != 0) : (s >>= 1) {759 return std.meta.Int(.unsigned, log2_bits);
760 count += 1;
761 }
762
763 return std.meta.Int(.unsigned, count);
764}760}
765761
766/// Returns an unsigned int type that can hold the number of bits in T.762/// Returns an unsigned int type that can hold the number of bits in T.
767pub fn Log2IntCeil(comptime T: type) type {763pub fn Log2IntCeil(comptime T: type) type {
768 // comptime ceil log2764 // comptime ceil log2
769 if (T == comptime_int) return comptime_int;765 if (T == comptime_int) return comptime_int;
770 comptime var count = 0;766 const bits: u16 = @typeInfo(T).Int.bits;
771 comptime var s = @typeInfo(T).Int.bits;767 const log2_bits = 16 - @clz(bits);
772 inline while (s != 0) : (s >>= 1) {768 return std.meta.Int(.unsigned, log2_bits);
773 count += 1;
774 }
775
776 return std.meta.Int(.unsigned, count);
777}769}
778770
779/// Returns the smallest integer type that can hold both from and to.771/// Returns the smallest integer type that can hold both from and to.
lib/std/math/hypot.zig+1
...@@ -114,6 +114,7 @@ test "hypot.precise" {...@@ -114,6 +114,7 @@ test "hypot.precise" {
114}114}
115115
116test "hypot.special" {116test "hypot.special" {
117 @setEvalBranchQuota(2000);
117 inline for (.{ f16, f32, f64, f128 }) |T| {118 inline for (.{ f16, f32, f64, f128 }) |T| {
118 try expect(math.isNan(hypot(nan(T), 0.0)));119 try expect(math.isNan(hypot(nan(T), 0.0)));
119 try expect(math.isNan(hypot(0.0, nan(T))));120 try expect(math.isNan(hypot(0.0, nan(T))));
lib/std/math/nextafter.zig+1-1
...@@ -144,7 +144,7 @@ test "int" {...@@ -144,7 +144,7 @@ test "int" {
144}144}
145145
146test "float" {146test "float" {
147 @setEvalBranchQuota(3000);147 @setEvalBranchQuota(4000);
148148
149 // normal -> normal149 // normal -> normal
150 try expect(nextAfter(f16, 0x1.234p0, 2.0) == 0x1.238p0);150 try expect(nextAfter(f16, 0x1.234p0, 2.0) == 0x1.238p0);
lib/std/unicode.zig+1
...@@ -535,6 +535,7 @@ fn testUtf16CountCodepoints() !void {...@@ -535,6 +535,7 @@ fn testUtf16CountCodepoints() !void {
535}535}
536536
537test "utf16 count codepoints" {537test "utf16 count codepoints" {
538 @setEvalBranchQuota(2000);
538 try testUtf16CountCodepoints();539 try testUtf16CountCodepoints();
539 try comptime testUtf16CountCodepoints();540 try comptime testUtf16CountCodepoints();
540}541}