Skip to content

Commit 8bacf3e

Browse files
committed
x86_64: implement integer @reduce(.Max)
1 parent 3fd3358 commit 8bacf3e

File tree

14 files changed

+8246
-118
lines changed

14 files changed

+8246
-118
lines changed

lib/std/simd.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ pub fn countElementsWithValue(vec: anytype, value: std.meta.Child(@TypeOf(vec)))
368368
}
369369

370370
test "vector searching" {
371-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
371+
if (builtin.zig_backend == .stage2_x86_64 and
372+
!comptime std.Target.x86.featureSetHas(builtin.cpu.features, .ssse3)) return error.SkipZigTest;
372373

373374
const base = @Vector(8, u32){ 6, 4, 7, 4, 4, 2, 3, 7 };
374375

lib/std/zig/Zir.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ pub const Inst = struct {
21422142
ref_start_index = static_len,
21432143
_,
21442144

2145-
pub const static_len = 117;
2145+
pub const static_len = 118;
21462146

21472147
pub fn toRef(i: Index) Inst.Ref {
21482148
return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
@@ -2246,6 +2246,7 @@ pub const Inst = struct {
22462246
vector_8_u16_type,
22472247
vector_16_u16_type,
22482248
vector_32_u16_type,
2249+
vector_2_i32_type,
22492250
vector_4_i32_type,
22502251
vector_8_i32_type,
22512252
vector_16_i32_type,

src/Air.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ pub const Inst = struct {
10291029
vector_8_u16_type = @intFromEnum(InternPool.Index.vector_8_u16_type),
10301030
vector_16_u16_type = @intFromEnum(InternPool.Index.vector_16_u16_type),
10311031
vector_32_u16_type = @intFromEnum(InternPool.Index.vector_32_u16_type),
1032+
vector_2_i32_type = @intFromEnum(InternPool.Index.vector_2_i32_type),
10321033
vector_4_i32_type = @intFromEnum(InternPool.Index.vector_4_i32_type),
10331034
vector_8_i32_type = @intFromEnum(InternPool.Index.vector_8_i32_type),
10341035
vector_16_i32_type = @intFromEnum(InternPool.Index.vector_16_i32_type),

src/InternPool.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4606,6 +4606,7 @@ pub const Index = enum(u32) {
46064606
vector_8_u16_type,
46074607
vector_16_u16_type,
46084608
vector_32_u16_type,
4609+
vector_2_i32_type,
46094610
vector_4_i32_type,
46104611
vector_8_i32_type,
46114612
vector_16_i32_type,
@@ -5168,6 +5169,8 @@ pub const static_keys: [static_len]Key = .{
51685169
.{ .vector_type = .{ .len = 16, .child = .u16_type } },
51695170
// @Vector(32, u16)
51705171
.{ .vector_type = .{ .len = 32, .child = .u16_type } },
5172+
// @Vector(2, i32)
5173+
.{ .vector_type = .{ .len = 2, .child = .i32_type } },
51715174
// @Vector(4, i32)
51725175
.{ .vector_type = .{ .len = 4, .child = .i32_type } },
51735176
// @Vector(8, i32)
@@ -11870,6 +11873,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1187011873
.vector_8_u16_type,
1187111874
.vector_16_u16_type,
1187211875
.vector_32_u16_type,
11876+
.vector_2_i32_type,
1187311877
.vector_4_i32_type,
1187411878
.vector_8_i32_type,
1187511879
.vector_16_i32_type,
@@ -12210,6 +12214,7 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
1221012214
.vector_8_u16_type,
1221112215
.vector_16_u16_type,
1221212216
.vector_32_u16_type,
12217+
.vector_2_i32_type,
1221312218
.vector_4_i32_type,
1221412219
.vector_8_i32_type,
1221512220
.vector_16_i32_type,

src/Sema.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36562,6 +36562,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3656236562
.vector_8_u16_type,
3656336563
.vector_16_u16_type,
3656436564
.vector_32_u16_type,
36565+
.vector_2_i32_type,
3656536566
.vector_4_i32_type,
3656636567
.vector_8_i32_type,
3656736568
.vector_16_i32_type,

src/Type.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,7 @@ pub const vector_4_u16: Type = .{ .ip_index = .vector_4_u16_type };
41274127
pub const vector_8_u16: Type = .{ .ip_index = .vector_8_u16_type };
41284128
pub const vector_16_u16: Type = .{ .ip_index = .vector_16_u16_type };
41294129
pub const vector_32_u16: Type = .{ .ip_index = .vector_32_u16_type };
4130+
pub const vector_2_i32: Type = .{ .ip_index = .vector_2_i32_type };
41304131
pub const vector_4_i32: Type = .{ .ip_index = .vector_4_i32_type };
41314132
pub const vector_8_i32: Type = .{ .ip_index = .vector_8_i32_type };
41324133
pub const vector_16_i32: Type = .{ .ip_index = .vector_16_i32_type };

src/arch/x86_64/CodeGen.zig

Lines changed: 8203 additions & 108 deletions
Large diffs are not rendered by default.

src/codegen/c/Type.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,21 @@ pub const Pool = struct {
17471747
};
17481748
return pool.fromFields(allocator, .@"struct", &fields, kind);
17491749
},
1750+
.vector_2_i32_type => {
1751+
const vector_ctype = try pool.getVector(allocator, .{
1752+
.elem_ctype = .i32,
1753+
.len = 2,
1754+
});
1755+
if (!kind.isParameter()) return vector_ctype;
1756+
var fields = [_]Info.Field{
1757+
.{
1758+
.name = .{ .index = .array },
1759+
.ctype = vector_ctype,
1760+
.alignas = AlignAs.fromAbiAlignment(Type.i32.abiAlignment(zcu)),
1761+
},
1762+
};
1763+
return pool.fromFields(allocator, .@"struct", &fields, kind);
1764+
},
17501765
.vector_4_i32_type => {
17511766
const vector_ctype = try pool.getVector(allocator, .{
17521767
.elem_ctype = .i32,

test/behavior/x86_64/unary.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5102,6 +5102,14 @@ test reduceMin {
51025102
try test_reduce_min.testIntVectors();
51035103
}
51045104

5105+
inline fn reduceMax(comptime Type: type, rhs: Type) @typeInfo(Type).vector.child {
5106+
return @reduce(.Max, rhs);
5107+
}
5108+
test reduceMax {
5109+
const test_reduce_max = unary(reduceMax, .{});
5110+
try test_reduce_max.testIntVectors();
5111+
}
5112+
51055113
inline fn reduceAdd(comptime Type: type, rhs: Type) @typeInfo(Type).vector.child {
51065114
return @reduce(.Add, rhs);
51075115
}

test/cases/compile_errors/@import_zon_bad_type.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ export fn testMutablePointer() void {
117117
// tmp.zig:37:38: note: imported here
118118
// neg_inf.zon:1:1: error: expected type '?u8'
119119
// tmp.zig:57:28: note: imported here
120-
// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_517'
120+
// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_518'
121121
// tmp.zig:62:39: note: imported here
122-
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_519'
122+
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_520'
123123
// tmp.zig:67:44: note: imported here
124-
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_522'
124+
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_523'
125125
// tmp.zig:72:50: note: imported here

test/cases/compile_errors/anytype_param_requires_comptime.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ pub export fn entry() void {
1515
// error
1616
//
1717
// :7:25: error: unable to resolve comptime value
18-
// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_491.C' must be comptime-known
18+
// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_492.C' must be comptime-known
1919
// :4:16: note: struct requires comptime because of this field
2020
// :4:16: note: types are not available at runtime

test/cases/compile_errors/bogus_method_call_on_slice.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ pub export fn entry2() void {
1616
//
1717
// :3:6: error: no field or member function named 'copy' in '[]const u8'
1818
// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
19-
// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_495'
19+
// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_496'
2020
// :12:6: note: struct declared here

test/cases/compile_errors/coerce_anon_struct.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export fn foo() void {
66

77
// error
88
//
9-
// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_484'
9+
// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_485'
1010
// :3:16: note: struct declared here
1111
// :1:11: note: struct declared here

test/cases/compile_errors/redundant_try.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ comptime {
4444
//
4545
// :5:23: error: expected error union type, found 'comptime_int'
4646
// :10:23: error: expected error union type, found '@TypeOf(.{})'
47-
// :15:23: error: expected error union type, found 'tmp.test2__struct_521'
47+
// :15:23: error: expected error union type, found 'tmp.test2__struct_522'
4848
// :15:23: note: struct declared here
49-
// :20:27: error: expected error union type, found 'tmp.test3__struct_523'
49+
// :20:27: error: expected error union type, found 'tmp.test3__struct_524'
5050
// :20:27: note: struct declared here
5151
// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
5252
// :31:13: error: expected error union type, found 'u32'

0 commit comments

Comments
 (0)