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 {
629629
630630// Generate lookup tables.
631631fn generateTable(invert: bool) [4][256]u32 {
632 @setEvalBranchQuota(50000);
633
632634 var table: [4][256]u32 = undefined;
633635
634636 for (generateSbox(invert), 0..) |value, index| {
lib/std/crypto/blake2.zig+2-2
......@@ -786,7 +786,7 @@ test "blake2b384 streaming" {
786786
787787test "comptime blake2b384" {
788788 comptime {
789 @setEvalBranchQuota(10000);
789 @setEvalBranchQuota(20000);
790790 var block = [_]u8{0} ** Blake2b384.block_length;
791791 var out: [Blake2b384.digest_length]u8 = undefined;
792792
......@@ -878,7 +878,7 @@ test "blake2b512 keyed" {
878878
879879test "comptime blake2b512" {
880880 comptime {
881 @setEvalBranchQuota(10000);
881 @setEvalBranchQuota(12000);
882882 var block = [_]u8{0} ** Blake2b512.block_length;
883883 var out: [Blake2b512.digest_length]u8 = undefined;
884884
lib/std/enums.zig+1-1
......@@ -6,7 +6,7 @@ const testing = std.testing;
66const EnumField = std.builtin.Type.EnumField;
77
88/// Increment this value when adding APIs that add single backwards branches.
9const eval_branch_quota_cushion = 5;
9const eval_branch_quota_cushion = 10;
1010
1111/// Returns a struct with a field matching each unique named enum element.
1212/// 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" {
890890 }
891891 };
892892 try Test.do();
893 @setEvalBranchQuota(75000);
893 @setEvalBranchQuota(85000);
894894 comptime try Test.do();
895895}
896896
lib/std/math.zig+8-16
......@@ -749,31 +749,23 @@ test rotl {
749749 try testing.expect(rotl(@Vector(1, u32), @Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
750750}
751751
752/// Returns an unsigned int type that can hold the number of bits in T
753/// - 1. Suitable for 0-based bit indices of T.
752/// Returns an unsigned int type that can hold the number of bits in T - 1.
753/// Suitable for 0-based bit indices of T.
754754pub fn Log2Int(comptime T: type) type {
755755 // comptime ceil log2
756756 if (T == comptime_int) return comptime_int;
757 comptime var count = 0;
758 comptime var s = @typeInfo(T).Int.bits - 1;
759 inline while (s != 0) : (s >>= 1) {
760 count += 1;
761 }
762
763 return std.meta.Int(.unsigned, count);
757 const bits: u16 = @typeInfo(T).Int.bits;
758 const log2_bits = 16 - @clz(bits - 1);
759 return std.meta.Int(.unsigned, log2_bits);
764760}
765761
766762/// Returns an unsigned int type that can hold the number of bits in T.
767763pub fn Log2IntCeil(comptime T: type) type {
768764 // comptime ceil log2
769765 if (T == comptime_int) return comptime_int;
770 comptime var count = 0;
771 comptime var s = @typeInfo(T).Int.bits;
772 inline while (s != 0) : (s >>= 1) {
773 count += 1;
774 }
775
776 return std.meta.Int(.unsigned, count);
766 const bits: u16 = @typeInfo(T).Int.bits;
767 const log2_bits = 16 - @clz(bits);
768 return std.meta.Int(.unsigned, log2_bits);
777769}
778770
779771/// 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" {
114114}
115115
116116test "hypot.special" {
117 @setEvalBranchQuota(2000);
117118 inline for (.{ f16, f32, f64, f128 }) |T| {
118119 try expect(math.isNan(hypot(nan(T), 0.0)));
119120 try expect(math.isNan(hypot(0.0, nan(T))));
lib/std/math/nextafter.zig+1-1
......@@ -144,7 +144,7 @@ test "int" {
144144}
145145
146146test "float" {
147 @setEvalBranchQuota(3000);
147 @setEvalBranchQuota(4000);
148148
149149 // normal -> normal
150150 try expect(nextAfter(f16, 0x1.234p0, 2.0) == 0x1.238p0);
lib/std/unicode.zig+1
......@@ -535,6 +535,7 @@ fn testUtf16CountCodepoints() !void {
535535}
536536
537537test "utf16 count codepoints" {
538 @setEvalBranchQuota(2000);
538539 try testUtf16CountCodepoints();
539540 try comptime testUtf16CountCodepoints();
540541}