Skip to content

Commit 5b1c81b

Browse files
committed
aarch64: implement optional comparisons
1 parent a583e21 commit 5b1c81b

File tree

8 files changed

+384
-291
lines changed

8 files changed

+384
-291
lines changed

src/codegen/aarch64/Disassemble.zig

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
7474
dis.operands_separator,
7575
imm12,
7676
});
77-
return if (!elide_shift) writer.print("{s}{f} #{s}", .{
77+
return if (!elide_shift) writer.print("{s}{f} #{t}", .{
7878
dis.operands_separator,
7979
fmtCase(.lsl, dis.case),
80-
@tagName(sh),
80+
sh,
8181
});
8282
},
8383
.add_subtract_immediate_with_tags => |add_subtract_immediate_with_tags| {
@@ -176,10 +176,10 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
176176
dis.operands_separator,
177177
imm16,
178178
});
179-
return if (!elide_shift) writer.print("{s}{f} #{s}", .{
179+
return if (!elide_shift) writer.print("{s}{f} #{t}", .{
180180
dis.operands_separator,
181181
fmtCase(.lsl, dis.case),
182-
@tagName(hw),
182+
hw,
183183
});
184184
},
185185
.bitfield => |bitfield| {
@@ -833,8 +833,36 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
833833
},
834834
.rotate_right_into_flags => {},
835835
.evaluate_into_flags => {},
836-
.conditional_compare_register => {},
837-
.conditional_compare_immediate => {},
836+
.conditional_compare_register => |conditional_compare_register| {
837+
const group = conditional_compare_register.group;
838+
const sf = group.sf;
839+
return writer.print("{f}{s}{f}{s}{f}{s}#0x{x}{s}{f}", .{
840+
fmtCase(group.op, dis.case),
841+
dis.mnemonic_operands_separator,
842+
group.Rn.decode(.{}).general(sf).fmtCase(dis.case),
843+
dis.operands_separator,
844+
group.Rm.decode(.{}).general(sf).fmtCase(dis.case),
845+
dis.operands_separator,
846+
@as(u4, @bitCast(group.nzcv)),
847+
dis.operands_separator,
848+
fmtCase(group.cond, dis.case),
849+
});
850+
},
851+
.conditional_compare_immediate => |conditional_compare_immediate| {
852+
const group = conditional_compare_immediate.group;
853+
const sf = group.sf;
854+
return writer.print("{f}{s}{f}{s}#0x{x}{s}#0x{x}{s}{f}", .{
855+
fmtCase(group.op, dis.case),
856+
dis.mnemonic_operands_separator,
857+
group.Rn.decode(.{}).general(sf).fmtCase(dis.case),
858+
dis.operands_separator,
859+
group.imm5,
860+
dis.operands_separator,
861+
@as(u4, @bitCast(group.nzcv)),
862+
dis.operands_separator,
863+
fmtCase(group.cond, dis.case),
864+
});
865+
},
838866
.conditional_select => |conditional_select| {
839867
const decoded = conditional_select.decode();
840868
if (decoded == .unallocated) break :unallocated;

src/codegen/aarch64/Mir.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn emit(
136136
mf.getZigObject().?.getOrCreateMetadataForLazySymbol(mf, pt, lazy_reloc.symbol) catch |err|
137137
return zcu.codegenFail(func.owner_nav, "{s} creating lazy symbol", .{@errorName(err)})
138138
else
139-
return zcu.codegenFail(func.owner_nav, "external symbols unimplemented for {s}", .{@tagName(lf.tag)}),
139+
return zcu.codegenFail(func.owner_nav, "external symbols unimplemented for {t}", .{lf.tag}),
140140
mir.body[lazy_reloc.reloc.label],
141141
body_end - Instruction.size * (1 + lazy_reloc.reloc.label),
142142
lazy_reloc.reloc.addend,
@@ -150,7 +150,7 @@ pub fn emit(
150150
else if (lf.cast(.macho)) |mf|
151151
try mf.getGlobalSymbol(std.mem.span(global_reloc.name), null)
152152
else
153-
return zcu.codegenFail(func.owner_nav, "external symbols unimplemented for {s}", .{@tagName(lf.tag)}),
153+
return zcu.codegenFail(func.owner_nav, "external symbols unimplemented for {t}", .{lf.tag}),
154154
mir.body[global_reloc.reloc.label],
155155
body_end - Instruction.size * (1 + global_reloc.reloc.label),
156156
global_reloc.reloc.addend,

src/codegen/aarch64/Select.zig

Lines changed: 348 additions & 270 deletions
Large diffs are not rendered by default.

test/behavior/enum.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,6 @@ test "enum value allocation" {
899899
}
900900

901901
test "enum literal casting to tagged union" {
902-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
903902
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
904903
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
905904

@@ -935,7 +934,6 @@ test "enum literal casting to error union with payload enum" {
935934
}
936935

937936
test "constant enum initialization with differing sizes" {
938-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
939937
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
940938
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
941939
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;

test/behavior/optional.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ test "nested optional field in struct" {
149149
}
150150

151151
test "equality compare optionals and non-optionals" {
152-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
153152
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
154153
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
155154
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
@@ -209,7 +208,6 @@ test "equality compare optionals and non-optionals" {
209208
}
210209

211210
test "compare optionals with modified payloads" {
212-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
213211
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
214212

215213
var lhs: ?bool = false;

test/behavior/switch.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ test "switch with null and T peer types and inferred result location type" {
576576
}
577577

578578
test "switch prongs with cases with identical payload types" {
579-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
580579
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
581580
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
582581

@@ -824,7 +823,6 @@ test "comptime inline switch" {
824823
}
825824

826825
test "switch capture peer type resolution" {
827-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
828826
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
829827

830828
const U = union(enum) {

test/behavior/tuple.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ test "anon tuple field referencing comptime var isn't comptime" {
496496
}
497497

498498
test "tuple with runtime value coerced into a slice with a sentinel" {
499-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
500499
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
501500
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
502501
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;

test/behavior/union.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ const Payload = union(Letter) {
208208
};
209209

210210
test "union with specified enum tag" {
211-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
212211
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
213212
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
214213
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
@@ -219,7 +218,6 @@ test "union with specified enum tag" {
219218
}
220219

221220
test "packed union generates correctly aligned type" {
222-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
223221
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
224222
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
225223
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
@@ -605,7 +603,6 @@ fn returnAnInt(x: i32) TaggedFoo {
605603
}
606604

607605
test "tagged union with all void fields but a meaningful tag" {
608-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
609606
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
610607
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
611608

@@ -1032,7 +1029,6 @@ test "containers with single-field enums" {
10321029
}
10331030

10341031
test "@unionInit on union with tag but no fields" {
1035-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10361032
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
10371033
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10381034

@@ -1446,8 +1442,6 @@ test "access the tag of a global tagged union" {
14461442
}
14471443

14481444
test "coerce enum literal to union in result loc" {
1449-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1450-
14511445
const U = union(enum) {
14521446
a,
14531447
b: u8,

0 commit comments

Comments
 (0)