stage2 x86_64: enable bitwise and + or and add tests

This commit is contained in:
Jacob G-W 2021-08-18 21:29:32 -04:00 committed by Veikka Tuominen
parent 62fe4a0ba8
commit df10e998ee
2 changed files with 44 additions and 0 deletions

View File

@ -1247,6 +1247,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
const bin_op = self.air.instructions.items(.data)[inst].bin_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) {
.arm, .armeb => try self.genArmBinOp(inst, bin_op.lhs, bin_op.rhs, .bit_and),
.x86_64 => try self.genX8664BinMath(inst, bin_op.lhs, bin_op.rhs),
else => return self.fail("TODO implement bitwise and for {}", .{self.target.cpu.arch}),
};
return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
@ -1256,6 +1257,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
const bin_op = self.air.instructions.items(.data)[inst].bin_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) {
.arm, .armeb => try self.genArmBinOp(inst, bin_op.lhs, bin_op.rhs, .bit_or),
.x86_64 => try self.genX8664BinMath(inst, bin_op.lhs, bin_op.rhs),
else => return self.fail("TODO implement bitwise or for {}", .{self.target.cpu.arch}),
};
return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });

View File

@ -1535,6 +1535,48 @@ pub fn addCases(ctx: *TestContext) !void {
\\}
, "");
}
{
var case = ctx.exe("runtime bitwise and", linux_x64);
case.addCompareOutput(
\\pub fn main() void {
\\ var i: u32 = 10;
\\ var j: u32 = 11;
\\ assert(i & 1 == 0);
\\ assert(j & 1 == 1);
\\ var m1: u32 = 0b1111;
\\ var m2: u32 = 0b0000;
\\ assert(m1 & 0b1010 == 0b1010);
\\ assert(m2 & 0b1010 == 0b0000);
\\}
\\fn assert(b: bool) void {
\\ if (!b) unreachable;
\\}
,
"",
);
}
{
var case = ctx.exe("runtime bitwise or", linux_x64);
case.addCompareOutput(
\\pub fn main() void {
\\ var i: u32 = 10;
\\ var j: u32 = 11;
\\ assert(i | 1 == 11);
\\ assert(j | 1 == 11);
\\ var m1: u32 = 0b1111;
\\ var m2: u32 = 0b0000;
\\ assert(m1 | 0b1010 == 0b1111);
\\ assert(m2 | 0b1010 == 0b1010);
\\}
\\fn assert(b: bool) void {
\\ if (!b) unreachable;
\\}
,
"",
);
}
{
var case = ctx.exe("merge error sets", linux_x64);