[codegen] reintroduce support for carry and borrow instructions in RI… (#1005)
Reintroduce support for iadd carry variants and isub borrow variants for RISC ISAs which had been removed in https://github.com/CraneStation/cranelift/pull/961 and https://github.com/CraneStation/cranelift/pull/962 because of the lack of a proper flags register in RISC architectures.
This commit is contained in:
committed by
Benjamin Bouvier
parent
cadd0ac655
commit
3418fb6e18
@@ -1,6 +1,3 @@
|
||||
; TODO(ryzokuken): figure out a better legalization strategy for platforms that
|
||||
; platforms that don't have flags.
|
||||
|
||||
; Test the legalization of i32 instructions that don't have RISC-V versions.
|
||||
test legalizer
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
; TODO(ryzokuken): figure out a better legalization strategy for platforms that
|
||||
; platforms that don't have flags.
|
||||
|
||||
; Test the legalization of i64 arithmetic instructions.
|
||||
test legalizer
|
||||
target riscv32 supports_m=1
|
||||
@@ -471,19 +471,19 @@ ebb0:
|
||||
|
||||
; Carry Addition
|
||||
; asm: addl %esi, %ecx
|
||||
[-,%rcx,%rflags] v701, v702 = iadd_cout v1, v2 ; bin: 01 f1
|
||||
[-,%rcx,%rflags] v701, v702 = iadd_ifcout v1, v2 ; bin: 01 f1
|
||||
; asm: adcl %esi, %ecx
|
||||
[-,%rcx] v703 = iadd_cin v1, v2, v702 ; bin: 11 f1
|
||||
[-,%rcx] v703 = iadd_ifcin v1, v2, v702 ; bin: 11 f1
|
||||
; asm: adcl %esi, %ecx
|
||||
[-,%rcx,%rflags] v704, v705 = iadd_carry v1, v2, v702 ; bin: 11 f1
|
||||
[-,%rcx,%rflags] v704, v705 = iadd_ifcarry v1, v2, v702 ; bin: 11 f1
|
||||
|
||||
; Borrow Subtraction
|
||||
; asm: subl %esi, %ecx
|
||||
[-,%rcx,%rflags] v706, v707 = isub_bout v1, v2 ; bin: 29 f1
|
||||
[-,%rcx,%rflags] v706, v707 = isub_ifbout v1, v2 ; bin: 29 f1
|
||||
; asm: sbbl %esi, %ecx
|
||||
[-,%rcx] v708 = isub_bin v1, v2, v707 ; bin: 19 f1
|
||||
[-,%rcx] v708 = isub_ifbin v1, v2, v707 ; bin: 19 f1
|
||||
; asm: sbbl %esi, %ecx
|
||||
[-,%rcx,%rflags] v709, v710 = isub_borrow v1, v2, v707 ; bin: 19 f1
|
||||
[-,%rcx,%rflags] v709, v710 = isub_ifborrow v1, v2, v707 ; bin: 19 f1
|
||||
|
||||
; asm: testl %ecx, %ecx
|
||||
; asm: je ebb1
|
||||
|
||||
@@ -9,8 +9,8 @@ ebb0(v1: i64, v2: i64):
|
||||
v10 = iadd v1, v2
|
||||
; check: v1 = iconcat $(v1_lsb=$V), $(v1_msb=$V)
|
||||
; nextln: v2 = iconcat $(v2_lsb=$V), $(v2_msb=$V)
|
||||
; nextln: $(v10_lsb=$V), $(carry=$V) = iadd_cout $v1_lsb, $v2_lsb
|
||||
; nextln: $(v10_msb=$V) = iadd_cin $v1_msb, $v2_msb, $carry
|
||||
; nextln: $(v10_lsb=$V), $(carry=$V) = iadd_ifcout $v1_lsb, $v2_lsb
|
||||
; nextln: $(v10_msb=$V) = iadd_ifcin $v1_msb, $v2_msb, $carry
|
||||
; nextln: v10 = iconcat $v10_lsb, $v10_msb
|
||||
return v10
|
||||
}
|
||||
@@ -20,8 +20,8 @@ ebb0(v1: i64, v2: i64):
|
||||
v10 = isub v1, v2
|
||||
; check: v1 = iconcat $(v1_lsb=$V), $(v1_msb=$V)
|
||||
; nextln: v2 = iconcat $(v2_lsb=$V), $(v2_msb=$V)
|
||||
; nextln: $(v10_lsb=$V), $(borrow=$V) = isub_bout $v1_lsb, $v2_lsb
|
||||
; nextln: $(v10_msb=$V) = isub_bin $v1_msb, $v2_msb, $borrow
|
||||
; nextln: $(v10_lsb=$V), $(borrow=$V) = isub_ifbout $v1_lsb, $v2_lsb
|
||||
; nextln: $(v10_msb=$V) = isub_ifbin $v1_msb, $v2_msb, $borrow
|
||||
; nextln: v10 = iconcat $v10_lsb, $v10_msb
|
||||
return v10
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ target i686 haswell
|
||||
function %iadd(i64, i64) -> i64 {
|
||||
ebb0(v1: i64, v2: i64):
|
||||
v10 = iadd v1, v2
|
||||
; check: iadd_cout
|
||||
; check: iadd_ifcout
|
||||
return v10
|
||||
}
|
||||
|
||||
function %isub(i64, i64) -> i64 {
|
||||
ebb0(v1: i64, v2: i64):
|
||||
v10 = isub v1, v2
|
||||
; check: isub_bout
|
||||
; check: isub_ifbout
|
||||
return v10
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ function %foo(i32, i32) {
|
||||
ebb1(v0: i32 [%x8], v1: i32):
|
||||
[-,-] v2 = iadd v0, v1
|
||||
[-] trap heap_oob
|
||||
[R#1234, %x5, %x11] v6, v7 = iadd_cout v2, v0
|
||||
[R#1234, %x5, %x11] v6, v7 = iadd_ifcout v2, v0
|
||||
[Rshamt#beef, %x25] v8 = ishl_imm v6, 2
|
||||
@55 v9 = iadd v8, v7
|
||||
@a5 [Iret#5] return v0, v8
|
||||
@@ -17,7 +17,7 @@ ebb1(v0: i32 [%x8], v1: i32):
|
||||
; nextln: ebb1(v0: i32 [%x8], v1: i32):
|
||||
; nextln: [-,-]$WS v2 = iadd v0, v1
|
||||
; nextln: [-]$WS trap heap_oob
|
||||
; nextln: [R#1234,%x5,%x11]$WS v6, v7 = iadd_cout v2, v0
|
||||
; nextln: [R#1234,%x5,%x11]$WS v6, v7 = iadd_ifcout v2, v0
|
||||
; nextln: [Rshamt#beef,%x25]$WS v8 = ishl_imm v6, 2
|
||||
; nextln: @0055 [-,-]$WS v9 = iadd v8, v7
|
||||
; nextln: @00a5 [Iret#05]$WS return v0, v8
|
||||
|
||||
@@ -3,22 +3,22 @@ test verifier
|
||||
|
||||
function %add_i96(i32, i32, i32, i32, i32, i32) -> i32, i32, i32 {
|
||||
ebb1(v1: i32, v2: i32, v3: i32, v4: i32, v5: i32, v6: i32):
|
||||
v10, v11 = iadd_cout v1, v4
|
||||
;check: v10, v11 = iadd_cout v1, v4
|
||||
v20, v21 = iadd_carry v2, v5, v11
|
||||
; check: v20, v21 = iadd_carry v2, v5, v11
|
||||
v30 = iadd_cin v3, v6, v21
|
||||
; check: v30 = iadd_cin v3, v6, v21
|
||||
v10, v11 = iadd_ifcout v1, v4
|
||||
;check: v10, v11 = iadd_ifcout v1, v4
|
||||
v20, v21 = iadd_ifcarry v2, v5, v11
|
||||
; check: v20, v21 = iadd_ifcarry v2, v5, v11
|
||||
v30 = iadd_ifcin v3, v6, v21
|
||||
; check: v30 = iadd_ifcin v3, v6, v21
|
||||
return v10, v20, v30
|
||||
}
|
||||
|
||||
function %sub_i96(i32, i32, i32, i32, i32, i32) -> i32, i32, i32 {
|
||||
ebb1(v1: i32, v2: i32, v3: i32, v4: i32, v5: i32, v6: i32):
|
||||
v10, v11 = isub_bout v1, v4
|
||||
;check: v10, v11 = isub_bout v1, v4
|
||||
v20, v21 = isub_borrow v2, v5, v11
|
||||
; check: v20, v21 = isub_borrow v2, v5, v11
|
||||
v30 = isub_bin v3, v6, v21
|
||||
; check: v30 = isub_bin v3, v6, v21
|
||||
v10, v11 = isub_ifbout v1, v4
|
||||
;check: v10, v11 = isub_ifbout v1, v4
|
||||
v20, v21 = isub_ifborrow v2, v5, v11
|
||||
; check: v20, v21 = isub_ifborrow v2, v5, v11
|
||||
v30 = isub_ifbin v3, v6, v21
|
||||
; check: v30 = isub_ifbin v3, v6, v21
|
||||
return v10, v20, v30
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user