Skip to content

Commit c5c1c85

Browse files
committed
x86_64: rewrite wrapping multiplication
1 parent ed284c1 commit c5c1c85

File tree

14 files changed

+3197
-374
lines changed

14 files changed

+3197
-374
lines changed

lib/std/zig/Zir.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ pub const Inst = struct {
21362136
ref_start_index = static_len,
21372137
_,
21382138

2139-
pub const static_len = 93;
2139+
pub const static_len = 97;
21402140

21412141
pub fn toRef(i: Index) Inst.Ref {
21422142
return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
@@ -2221,6 +2221,10 @@ pub const Inst = struct {
22212221
slice_const_u8_sentinel_0_type,
22222222
vector_16_i8_type,
22232223
vector_32_i8_type,
2224+
vector_1_u8_type,
2225+
vector_2_u8_type,
2226+
vector_4_u8_type,
2227+
vector_8_u8_type,
22242228
vector_16_u8_type,
22252229
vector_32_u8_type,
22262230
vector_8_i16_type,

src/Air.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,10 @@ pub const Inst = struct {
985985
slice_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.slice_const_u8_sentinel_0_type),
986986
vector_16_i8_type = @intFromEnum(InternPool.Index.vector_16_i8_type),
987987
vector_32_i8_type = @intFromEnum(InternPool.Index.vector_32_i8_type),
988+
vector_1_u8_type = @intFromEnum(InternPool.Index.vector_1_u8_type),
989+
vector_2_u8_type = @intFromEnum(InternPool.Index.vector_2_u8_type),
990+
vector_4_u8_type = @intFromEnum(InternPool.Index.vector_4_u8_type),
991+
vector_8_u8_type = @intFromEnum(InternPool.Index.vector_8_u8_type),
988992
vector_16_u8_type = @intFromEnum(InternPool.Index.vector_16_u8_type),
989993
vector_32_u8_type = @intFromEnum(InternPool.Index.vector_32_u8_type),
990994
vector_8_i16_type = @intFromEnum(InternPool.Index.vector_8_i16_type),

src/InternPool.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4573,6 +4573,10 @@ pub const Index = enum(u32) {
45734573

45744574
vector_16_i8_type,
45754575
vector_32_i8_type,
4576+
vector_1_u8_type,
4577+
vector_2_u8_type,
4578+
vector_4_u8_type,
4579+
vector_8_u8_type,
45764580
vector_16_u8_type,
45774581
vector_32_u8_type,
45784582
vector_8_i16_type,
@@ -5089,6 +5093,14 @@ pub const static_keys = [_]Key{
50895093
.{ .vector_type = .{ .len = 16, .child = .i8_type } },
50905094
// @Vector(32, i8)
50915095
.{ .vector_type = .{ .len = 32, .child = .i8_type } },
5096+
// @Vector(1, u8)
5097+
.{ .vector_type = .{ .len = 1, .child = .u8_type } },
5098+
// @Vector(2, u8)
5099+
.{ .vector_type = .{ .len = 2, .child = .u8_type } },
5100+
// @Vector(4, u8)
5101+
.{ .vector_type = .{ .len = 4, .child = .u8_type } },
5102+
// @Vector(8, u8)
5103+
.{ .vector_type = .{ .len = 8, .child = .u8_type } },
50925104
// @Vector(16, u8)
50935105
.{ .vector_type = .{ .len = 16, .child = .u8_type } },
50945106
// @Vector(32, u8)
@@ -11766,6 +11778,10 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1176611778
.slice_const_u8_sentinel_0_type,
1176711779
.vector_16_i8_type,
1176811780
.vector_32_i8_type,
11781+
.vector_1_u8_type,
11782+
.vector_2_u8_type,
11783+
.vector_4_u8_type,
11784+
.vector_8_u8_type,
1176911785
.vector_16_u8_type,
1177011786
.vector_32_u8_type,
1177111787
.vector_8_i16_type,
@@ -12106,6 +12122,10 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
1210612122

1210712123
.vector_16_i8_type,
1210812124
.vector_32_i8_type,
12125+
.vector_1_u8_type,
12126+
.vector_2_u8_type,
12127+
.vector_4_u8_type,
12128+
.vector_8_u8_type,
1210912129
.vector_16_u8_type,
1211012130
.vector_32_u8_type,
1211112131
.vector_8_i16_type,

src/Sema.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36377,6 +36377,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3637736377
.slice_const_u8_sentinel_0_type,
3637836378
.vector_16_i8_type,
3637936379
.vector_32_i8_type,
36380+
.vector_1_u8_type,
36381+
.vector_2_u8_type,
36382+
.vector_4_u8_type,
36383+
.vector_8_u8_type,
3638036384
.vector_16_u8_type,
3638136385
.vector_32_u8_type,
3638236386
.vector_8_i16_type,

src/Type.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,6 +4201,10 @@ pub const slice_const_u8_sentinel_0: Type = .{ .ip_index = .slice_const_u8_senti
42014201

42024202
pub const vector_16_i8: Type = .{ .ip_index = .vector_16_i8_type };
42034203
pub const vector_32_i8: Type = .{ .ip_index = .vector_32_i8_type };
4204+
pub const vector_1_u8: Type = .{ .ip_index = .vector_1_u8_type };
4205+
pub const vector_2_u8: Type = .{ .ip_index = .vector_2_u8_type };
4206+
pub const vector_4_u8: Type = .{ .ip_index = .vector_4_u8_type };
4207+
pub const vector_8_u8: Type = .{ .ip_index = .vector_8_u8_type };
42044208
pub const vector_16_u8: Type = .{ .ip_index = .vector_16_u8_type };
42054209
pub const vector_32_u8: Type = .{ .ip_index = .vector_32_u8_type };
42064210
pub const vector_8_i16: Type = .{ .ip_index = .vector_8_i16_type };

src/arch/x86_64/CodeGen.zig

Lines changed: 3082 additions & 364 deletions
Large diffs are not rendered by default.

src/arch/x86_64/Lower.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ fn generic(lower: *Lower, inst: Mir.Inst) Error!void {
579579
.rrri => inst.data.rrri.fixes,
580580
.rri_s, .rri_u => inst.data.rri.fixes,
581581
.ri_s, .ri_u, .ri_64, .ir => inst.data.ri.fixes,
582-
.rm, .rmi_s, .mr => inst.data.rx.fixes,
582+
.rm, .rmi_s, .rmi_u, .mr => inst.data.rx.fixes,
583583
.mrr, .rrm, .rmr => inst.data.rrx.fixes,
584584
.rmi, .mri => inst.data.rix.fixes,
585585
.rrmr => inst.data.rrrx.fixes,

src/codegen/c/Type.zig

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,66 @@ pub const Pool = struct {
14741474
};
14751475
return pool.fromFields(allocator, .@"struct", &fields, kind);
14761476
},
1477+
.vector_1_u8_type => {
1478+
const vector_ctype = try pool.getVector(allocator, .{
1479+
.elem_ctype = .u8,
1480+
.len = 1,
1481+
});
1482+
if (!kind.isParameter()) return vector_ctype;
1483+
var fields = [_]Info.Field{
1484+
.{
1485+
.name = .{ .index = .array },
1486+
.ctype = vector_ctype,
1487+
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
1488+
},
1489+
};
1490+
return pool.fromFields(allocator, .@"struct", &fields, kind);
1491+
},
1492+
.vector_2_u8_type => {
1493+
const vector_ctype = try pool.getVector(allocator, .{
1494+
.elem_ctype = .u8,
1495+
.len = 2,
1496+
});
1497+
if (!kind.isParameter()) return vector_ctype;
1498+
var fields = [_]Info.Field{
1499+
.{
1500+
.name = .{ .index = .array },
1501+
.ctype = vector_ctype,
1502+
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
1503+
},
1504+
};
1505+
return pool.fromFields(allocator, .@"struct", &fields, kind);
1506+
},
1507+
.vector_4_u8_type => {
1508+
const vector_ctype = try pool.getVector(allocator, .{
1509+
.elem_ctype = .u8,
1510+
.len = 4,
1511+
});
1512+
if (!kind.isParameter()) return vector_ctype;
1513+
var fields = [_]Info.Field{
1514+
.{
1515+
.name = .{ .index = .array },
1516+
.ctype = vector_ctype,
1517+
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
1518+
},
1519+
};
1520+
return pool.fromFields(allocator, .@"struct", &fields, kind);
1521+
},
1522+
.vector_8_u8_type => {
1523+
const vector_ctype = try pool.getVector(allocator, .{
1524+
.elem_ctype = .u8,
1525+
.len = 8,
1526+
});
1527+
if (!kind.isParameter()) return vector_ctype;
1528+
var fields = [_]Info.Field{
1529+
.{
1530+
.name = .{ .index = .array },
1531+
.ctype = vector_ctype,
1532+
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
1533+
},
1534+
};
1535+
return pool.fromFields(allocator, .@"struct", &fields, kind);
1536+
},
14771537
.vector_16_u8_type => {
14781538
const vector_ctype = try pool.getVector(allocator, .{
14791539
.elem_ctype = .u8,

test/behavior/x86_64/math.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21684,6 +21684,15 @@ test mulUnsafe {
2168421684
try test_mul_unsafe.testIntVectors();
2168521685
}
2168621686

21687+
inline fn mulWrap(comptime Type: type, lhs: Type, rhs: Type) Type {
21688+
return lhs *% rhs;
21689+
}
21690+
test mulWrap {
21691+
const test_mul_wrap = binary(mulWrap, .{});
21692+
try test_mul_wrap.testInts();
21693+
try test_mul_wrap.testIntVectors();
21694+
}
21695+
2168721696
inline fn multiply(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs * rhs) {
2168821697
return lhs * rhs;
2168921698
}

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_487'
120+
// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_491'
121121
// tmp.zig:62:39: note: imported here
122-
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_489'
122+
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_493'
123123
// tmp.zig:67:44: note: imported here
124-
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_492'
124+
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_496'
125125
// tmp.zig:72:50: note: imported here

0 commit comments

Comments
 (0)