authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-06-08 19:08:52+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-06-11 19:38:00+02:00
log180baa05465df6440f9953d8ff4d7880322b03f0
tree12ff254c0beb6fc1866a9b6caf09d6404a3d56d0
parentbc499de328f0d0110a8eaf3de7be55e05595f598

wasm:`@byteSwap` for 24 bit integers


1 files changed, 22 insertions(+), 3 deletions(-)

src/arch/wasm/CodeGen.zig+22-3
......@@ -4714,12 +4714,31 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
47144714 switch (int_info.bits) {
47154715 16 => {
47164716 const shl_res = try self.binOp(operand, .{ .imm32 = 8 }, ty, .shl);
4717 const tmp = try self.binOp(operand, .{ .imm32 = 0xFF00 }, ty, .@"and");
4718 const shr_res = try self.binOp(tmp, .{ .imm32 = 8 }, ty, .shr);
4717 const lhs = try self.binOp(shl_res, .{ .imm32 = 0xFF00 }, ty, .@"and");
4718 const shr_res = try self.binOp(operand, .{ .imm32 = 8 }, ty, .shr);
47194719 const res = if (int_info.signedness == .signed) blk: {
47204720 break :blk try self.wrapOperand(shr_res, Type.u8);
47214721 } else shr_res;
4722 return self.binOp(shl_res, res, ty, .@"or");
4722 return self.binOp(lhs, res, ty, .@"or");
4723 },
4724 24 => {
4725 const msb = try self.wrapOperand(operand, Type.u16);
4726 const lsb = try self.wrapBinOp(operand, .{ .imm32 = 16 }, Type.u8, .shr);
4727
4728 const shl_res = try self.binOp(msb, .{ .imm32 = 8 }, Type.u16, .shl);
4729 const lhs = try self.binOp(shl_res, .{ .imm32 = 0xFF0000 }, Type.u16, .@"and");
4730 const shr_res = try self.binOp(msb, .{ .imm32 = 8 }, ty, .shr);
4731
4732 const res = if (int_info.signedness == .signed) blk: {
4733 break :blk try self.wrapOperand(shr_res, Type.u8);
4734 } else shr_res;
4735 const lhs_tmp = try self.binOp(lhs, res, ty, .@"or");
4736 const lhs_result = try self.binOp(lhs_tmp, .{ .imm32 = 8 }, ty, .shr);
4737 const rhs_wrap = try self.wrapOperand(msb, Type.u8);
4738 const rhs_result = try self.binOp(rhs_wrap, .{ .imm32 = 16 }, ty, .shl);
4739
4740 const tmp = try self.binOp(lhs_result, rhs_result, ty, .@"or");
4741 return self.binOp(tmp, lsb, ty, .@"or");
47234742 },
47244743 32 => {
47254744 const shl_tmp = try self.binOp(operand, .{ .imm32 = 8 }, ty, .shl);