authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-05-22 15:36:45+02:00
committergravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-05-22 21:02:32+02:00
logb56b4428a3a2fd8cf244580f997ec0ed2010fce2
tree0556328e5d095bcb9ab9d9c5d5f171827828cb90
parent9747303d16dfca61316a292d1e05ac901191e3a3

stage2 ARM: fix recursive fibonacci

Some handling of register_c_flag/register_v_flag was incorrect.

4 files changed, 24 insertions(+), 28 deletions(-)

src/arch/arm/CodeGen.zig+22-25
......@@ -2447,6 +2447,9 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
24472447 .register_c_flag,
24482448 .register_v_flag,
24492449 => |reg| {
2450 const reg_lock = self.register_manager.lockRegAssumeUnused(reg);
2451 defer self.register_manager.unlockReg(reg_lock);
2452
24502453 switch (index) {
24512454 0 => {
24522455 // get wrapped value: return register
......@@ -5062,6 +5065,7 @@ fn lowerUnnamedConst(self: *Self, tv: TypedValue) InnerError!MCValue {
50625065}
50635066
50645067fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
5068 log.debug("genTypedValue: ty = {}, val = {}", .{ typed_value.ty.fmtDebug(), typed_value.val.fmtDebug() });
50655069 if (typed_value.val.isUndef())
50665070 return MCValue{ .undef = {} };
50675071 const ptr_bits = self.target.cpu.arch.ptrBitWidth();
......@@ -5075,24 +5079,14 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
50755079 const target = self.target.*;
50765080
50775081 switch (typed_value.ty.zigTypeTag()) {
5078 .Array => {
5079 return self.lowerUnnamedConst(typed_value);
5080 },
50815082 .Pointer => switch (typed_value.ty.ptrSize()) {
5082 .Slice => {
5083 return self.lowerUnnamedConst(typed_value);
5084 },
5083 .Slice => {},
50855084 else => {
50865085 switch (typed_value.val.tag()) {
50875086 .int_u64 => {
50885087 return MCValue{ .immediate = @intCast(u32, typed_value.val.toUnsignedInt(target)) };
50895088 },
5090 .slice => {
5091 return self.lowerUnnamedConst(typed_value);
5092 },
5093 else => {
5094 return self.fail("TODO codegen more kinds of const pointers", .{});
5095 },
5089 else => {},
50965090 }
50975091 },
50985092 },
......@@ -5115,8 +5109,6 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
51155109 .Bool => {
51165110 return MCValue{ .immediate = @boolToInt(typed_value.val.toBool()) };
51175111 },
5118 .ComptimeInt => unreachable, // semantic analysis prevents this
5119 .ComptimeFloat => unreachable, // semantic analysis prevents this
51205112 .Optional => {
51215113 if (typed_value.ty.isPtrLikeOptional()) {
51225114 if (typed_value.val.isNull())
......@@ -5130,7 +5122,6 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
51305122 } else if (typed_value.ty.abiSize(self.target.*) == 1) {
51315123 return MCValue{ .immediate = @boolToInt(typed_value.val.isNull()) };
51325124 }
5133 return self.fail("TODO non pointer optionals", .{});
51345125 },
51355126 .Enum => {
51365127 if (typed_value.val.castTag(.enum_field_index)) |field_index| {
......@@ -5166,28 +5157,34 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
51665157 const error_type = typed_value.ty.errorUnionSet();
51675158 const payload_type = typed_value.ty.errorUnionPayload();
51685159
5169 if (typed_value.val.castTag(.eu_payload)) |pl| {
5160 if (typed_value.val.castTag(.eu_payload)) |_| {
51705161 if (!payload_type.hasRuntimeBits()) {
51715162 // We use the error type directly as the type.
51725163 return MCValue{ .immediate = 0 };
51735164 }
5174
5175 _ = pl;
5176 return self.fail("TODO implement error union const of type '{}' (non-error)", .{typed_value.ty.fmtDebug()});
51775165 } else {
51785166 if (!payload_type.hasRuntimeBits()) {
51795167 // We use the error type directly as the type.
51805168 return self.genTypedValue(.{ .ty = error_type, .val = typed_value.val });
51815169 }
5182
5183 return self.fail("TODO implement error union const of type '{}' (error)", .{typed_value.ty.fmtDebug()});
51845170 }
51855171 },
5186 .Struct => {
5187 return self.lowerUnnamedConst(typed_value);
5188 },
5189 else => return self.fail("TODO implement const of type '{}'", .{typed_value.ty.fmtDebug()}),
5172
5173 .ComptimeInt => unreachable, // semantic analysis prevents this
5174 .ComptimeFloat => unreachable, // semantic analysis prevents this
5175 .Type => unreachable,
5176 .EnumLiteral => unreachable,
5177 .Void => unreachable,
5178 .NoReturn => unreachable,
5179 .Undefined => unreachable,
5180 .Null => unreachable,
5181 .BoundFn => unreachable,
5182 .Opaque => unreachable,
5183
5184 else => {},
51905185 }
5186
5187 return self.lowerUnnamedConst(typed_value);
51915188}
51925189
51935190const CallMCValues = struct {
src/arch/arm/Emit.zig+1-1
......@@ -394,7 +394,7 @@ fn mirDataProcessing(emit: *Emit, inst: Mir.Inst.Index) !void {
394394 .orr => try emit.writeInstruction(Instruction.orr(cond, rr_op.rd, rr_op.rn, rr_op.op)),
395395 .rsb => try emit.writeInstruction(Instruction.rsb(cond, rr_op.rd, rr_op.rn, rr_op.op)),
396396 .sub => try emit.writeInstruction(Instruction.sub(cond, rr_op.rd, rr_op.rn, rr_op.op)),
397 .subs => try emit.writeInstruction(Instruction.sub(cond, rr_op.rd, rr_op.rn, rr_op.op)),
397 .subs => try emit.writeInstruction(Instruction.subs(cond, rr_op.rd, rr_op.rn, rr_op.op)),
398398 else => unreachable,
399399 }
400400}
test/behavior/underscore.zig-1
......@@ -7,7 +7,6 @@ test "ignore lval with underscore" {
77}
88
99test "ignore lval with underscore (while loop)" {
10 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1110 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1211
1312 while (optionalReturnError()) |_| {
test/cases/recursive_fibonacci.zig+1-1
......@@ -20,5 +20,5 @@ fn assert(ok: bool) void {
2020}
2121
2222// run
23// target=x86_64-linux,x86_64-macos,wasm32-wasi
23// target=x86_64-linux,x86_64-macos,arm-linux,wasm32-wasi
2424//