| ... | @@ -953,10 +953,18 @@ test "len" { | ... | @@ -953,10 +953,18 @@ test "len" { |
| 953 | try testing.expect(len(c_ptr) == 2); | 953 | try testing.expect(len(c_ptr) == 2); |
| 954 | } | 954 | } |
| 955 | | 955 | |
| | 956 | const backend_supports_vectors = switch (builtin.zig_backend) { |
| | 957 | .stage2_llvm, .stage2_c => true, |
| | 958 | else => false, |
| | 959 | }; |
| | 960 | |
| 956 | pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]const T) usize { | 961 | pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]const T) usize { |
| 957 | var i: usize = 0; | 962 | var i: usize = 0; |
| 958 | | 963 | |
| 959 | if (!@inComptime() and (@typeInfo(T) == .Int or @typeInfo(T) == .Float) and std.math.isPowerOfTwo(@bitSizeOf(T))) { | 964 | if (backend_supports_vectors and |
| | 965 | !@inComptime() and |
| | 966 | (@typeInfo(T) == .Int or @typeInfo(T) == .Float) and std.math.isPowerOfTwo(@bitSizeOf(T))) |
| | 967 | { |
| 960 | switch (@import("builtin").cpu.arch) { | 968 | switch (@import("builtin").cpu.arch) { |
| 961 | // The below branch assumes that reading past the end of the buffer is valid, as long | 969 | // The below branch assumes that reading past the end of the buffer is valid, as long |
| 962 | // as we don't read into a new page. This should be the case for most architectures | 970 | // as we don't read into a new page. This should be the case for most architectures |
| ... | @@ -1066,7 +1074,10 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, | ... | @@ -1066,7 +1074,10 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, |
| 1066 | if (start_index >= slice.len) return null; | 1074 | if (start_index >= slice.len) return null; |
| 1067 | | 1075 | |
| 1068 | var i: usize = start_index; | 1076 | var i: usize = start_index; |
| 1069 | if (!@inComptime() and (@typeInfo(T) == .Int or @typeInfo(T) == .Float) and std.math.isPowerOfTwo(@bitSizeOf(T))) { | 1077 | if (backend_supports_vectors and |
| | 1078 | !@inComptime() and |
| | 1079 | (@typeInfo(T) == .Int or @typeInfo(T) == .Float) and std.math.isPowerOfTwo(@bitSizeOf(T))) |
| | 1080 | { |
| 1070 | if (comptime std.simd.suggestVectorSize(T)) |block_len| { | 1081 | if (comptime std.simd.suggestVectorSize(T)) |block_len| { |
| 1071 | // For Intel Nehalem (2009) and AMD Bulldozer (2012) or later, unaligned loads on aligned data result | 1082 | // For Intel Nehalem (2009) and AMD Bulldozer (2012) or later, unaligned loads on aligned data result |
| 1072 | // in the same execution as aligned loads. We ignore older arch's here and don't bother pre-aligning. | 1083 | // in the same execution as aligned loads. We ignore older arch's here and don't bother pre-aligning. |