authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-01-13 18:43:50+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-02-04 19:08:57+01:00
log3ef5b80d2c359c94ec2fa14bde492a6c9774d536
tree8782d990d7cea79e86346fa83400f34405bffac6
parenta1b607acb5c1e9dd03760efd7078185e7628b29d
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

std: use simple eqlBytes for spirv

The SPIR-V backend doesn't support the advanced eqlBytes yet, and when it does, it likely that it will be detrimental.

1 files changed, 11 insertions(+), 1 deletions(-)

lib/std/mem.zig+11-1
...@@ -632,10 +632,16 @@ test "lessThan" {...@@ -632,10 +632,16 @@ test "lessThan" {
632 try testing.expect(lessThan(u8, "", "a"));632 try testing.expect(lessThan(u8, "", "a"));
633}633}
634634
635const backend_can_use_eql_bytes = switch (builtin.zig_backend) {
636 // The SPIR-V backend does not support the optimized path yet.
637 .stage2_spirv64 => false,
638 else => true,
639};
640
635/// Compares two slices and returns whether they are equal.641/// Compares two slices and returns whether they are equal.
636pub fn eql(comptime T: type, a: []const T, b: []const T) bool {642pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
637 if (@sizeOf(T) == 0) return true;643 if (@sizeOf(T) == 0) return true;
638 if (!@inComptime() and std.meta.hasUniqueRepresentation(T)) return eqlBytes(sliceAsBytes(a), sliceAsBytes(b));644 if (!@inComptime() and std.meta.hasUniqueRepresentation(T) and backend_can_use_eql_bytes) return eqlBytes(sliceAsBytes(a), sliceAsBytes(b));
639645
640 if (a.len != b.len) return false;646 if (a.len != b.len) return false;
641 if (a.len == 0 or a.ptr == b.ptr) return true;647 if (a.len == 0 or a.ptr == b.ptr) return true;
...@@ -648,6 +654,10 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {...@@ -648,6 +654,10 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
648654
649/// std.mem.eql heavily optimized for slices of bytes.655/// std.mem.eql heavily optimized for slices of bytes.
650fn eqlBytes(a: []const u8, b: []const u8) bool {656fn eqlBytes(a: []const u8, b: []const u8) bool {
657 if (!backend_can_use_eql_bytes) {
658 return eql(u8, a, b);
659 }
660
651 if (a.len != b.len) return false;661 if (a.len != b.len) return false;
652 if (a.len == 0 or a.ptr == b.ptr) return true;662 if (a.len == 0 or a.ptr == b.ptr) return true;
653663