Skip to content

Commit

Permalink
Merge pull request #3008 from afonso360/aarch64-i128-ireduce
Browse files Browse the repository at this point in the history
aarch64: Implement ireduce for i128 values
  • Loading branch information
cfallin committed Jun 21, 2021
2 parents 4246e69 + 151ad2f commit 444d9f9
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/aarch64/lower_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ pub(crate) fn lower_insn_to_regs<C: LowerCtx<I = Inst>>(
Opcode::Breduce | Opcode::Ireduce => {
// Smaller integers/booleans are stored with high-order bits
// undefined, so we can simply do a copy.
let rn = put_input_in_reg(ctx, inputs[0], NarrowValueMode::None);
let rn = put_input_in_regs(ctx, inputs[0]).regs()[0];
let rd = get_output_reg(ctx, outputs[0]).only_reg().unwrap();
let ty = ctx.input_ty(insn, 0);
ctx.emit(Inst::gen_move(rd, rn, ty));
Expand Down
43 changes: 43 additions & 0 deletions cranelift/filetests/filetests/isa/aarch64/reduce.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
test compile
set unwind_info=false
target aarch64

function %ireduce_128_64(i128) -> i64 {
block0(v0: i128):
v1 = ireduce.i64 v0
return v1
}
; check: stp fp, lr, [sp, #-16]!
; nextln: mov fp, sp
; nextln: ldp fp, lr, [sp], #16
; nextln: ret

function %ireduce_128_32(i128) -> i32 {
block0(v0: i128):
v1 = ireduce.i32 v0
return v1
}
; check: stp fp, lr, [sp, #-16]!
; nextln: mov fp, sp
; nextln: ldp fp, lr, [sp], #16
; nextln: ret

function %ireduce_128_16(i128) -> i16 {
block0(v0: i128):
v1 = ireduce.i16 v0
return v1
}
; check: stp fp, lr, [sp, #-16]!
; nextln: mov fp, sp
; nextln: ldp fp, lr, [sp], #16
; nextln: ret

function %ireduce_128_8(i128) -> i8 {
block0(v0: i128):
v1 = ireduce.i8 v0
return v1
}
; check: stp fp, lr, [sp, #-16]!
; nextln: mov fp, sp
; nextln: ldp fp, lr, [sp], #16
; nextln: ret
43 changes: 43 additions & 0 deletions cranelift/filetests/filetests/runtests/i128-reduce.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
test run
target aarch64
target x86_64 machinst

function %ireduce_128_64(i64, i64) -> i64 {
block0(v0: i64, v1: i64):
v2 = iconcat v0, v1
v3 = ireduce.i64 v2
return v3
}
; run: %ireduce_128_64(0, 0) == 0
; run: %ireduce_128_64(-1, -1) == -1
; run: %ireduce_128_64(0xC0FFEEEE_DECAFFFF, 0xDECAFFFF_C0FFEEEE) == 0xC0FFEEEE_DECAFFFF

function %ireduce_128_32(i64, i64) -> i32 {
block0(v0: i64, v1: i64):
v2 = iconcat v0, v1
v3 = ireduce.i32 v2
return v3
}
; run: %ireduce_128_32(0, 0) == 0
; run: %ireduce_128_32(-1, -1) == -1
; run: %ireduce_128_32(0xC0FFEEEE_DECAFFFF, 0xDECAFFFF_C0FFEEEE) == 0xDECAFFFF

function %ireduce_128_16(i64, i64) -> i16 {
block0(v0: i64, v1: i64):
v2 = iconcat v0, v1
v3 = ireduce.i16 v2
return v3
}
; run: %ireduce_128_16(0, 0) == 0
; run: %ireduce_128_16(-1, -1) == -1
; run: %ireduce_128_16(0xC0FFEEEE_DECAFFFF, 0xDECAFFFF_C0FFEEEE) == 0xFFFF

function %ireduce_128_8(i64, i64) -> i8 {
block0(v0: i64, v1: i64):
v2 = iconcat v0, v1
v3 = ireduce.i8 v2
return v3
}
; run: %ireduce_128_8(0, 0) == 0
; run: %ireduce_128_8(-1, -1) == -1
; run: %ireduce_128_8(0xC0FFEEEE_DECAFFFF, 0xDECAFFFF_C0FFEEEE) == 0xFF

0 comments on commit 444d9f9

Please sign in to comment.