-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
iadd_cin
and isub_bin
, split isub_borrow
and iadd_carry
(
#9199) * Remove `iadd_cin` and `isub_bin`, split `isub_borrow` and `iadd_carry` This commit refactors the opcodes the Cranelift supports for add-with-carry and subtract-with-borrow. None of these opcodes are currently in use by the wasm frontend nor supported by any backend. In that sense it's unlikely they have many users and the hope is that refactoring won't cause much impact. The `iadd_cin` and `isub_bin` opcodes are the equivalent of `*_borrow` and `*_carry` except that they don't return the carry flag, they only return the result of the operation. While theoretically useful I've elected to remove them here in favor of only the borrow-returning operations. They can be added back in in the future though if necessary. I've split the preexisting operations `isub_borrow` and `iadd_carry` additionally into signed/unsigned portions: * `isub_borrow` => `usub_borrow` and `ssub_borrow` * `iadd_carry` => `uadd_carry` and `sadd_carry` This reflects how the condition needs to differ on the carry flag computation for signed/unsigned inputs. I've additionally fixed the interpreter's implementation of `IsubBorrow` when switching to the signed/unsigned opcodes. Finally the documentation for these instructions now explicitly say that the incoming carry/borrow is zero-or-nonzero even though it's typed as `i8`. Additionally the tests have been refactored to make use of multi-return which may not have existed when they were first written. * Rename instructions * Fix more renames * Update instruction descriptions
- Loading branch information
1 parent
75ed0b6
commit ff98760
Showing
8 changed files
with
263 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,115 @@ | ||
test interpret | ||
|
||
function %iaddcarry_i8_v(i8, i8, i8) -> i8 { | ||
function %sadd_overflow_cin_i8(i8, i8, i8) -> i8, i8 { | ||
block0(v0: i8, v1: i8, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v3 | ||
v3, v4 = sadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i8_v(0, 1, 1) == 2 | ||
; run: %iaddcarry_i8_v(0, 1, 0) == 1 | ||
; run: %iaddcarry_i8_v(100, 27, 1) == -128 | ||
; run: %iaddcarry_i8_v(100, 27, 0) == 127 | ||
; run: %iaddcarry_i8_v(127, 127, 1) == -1 | ||
; run: %iaddcarry_i8_v(127, 127, 0) == -2 | ||
; run: %iaddcarry_i8_v(-128, -128, 0) == 0 | ||
; run: %sadd_overflow_cin_i8(0, 1, 1) == [2, 0] | ||
; run: %sadd_overflow_cin_i8(0, 1, 10) == [2, 0] | ||
; run: %sadd_overflow_cin_i8(0, 1, 0) == [1, 0] | ||
; run: %sadd_overflow_cin_i8(100, 27, 1) == [-128, 1] | ||
; run: %sadd_overflow_cin_i8(100, 27, 0) == [127, 0] | ||
; run: %sadd_overflow_cin_i8(127, 127, 1) == [-1, 1] | ||
; run: %sadd_overflow_cin_i8(127, 127, 0) == [-2, 1] | ||
; run: %sadd_overflow_cin_i8(-128, -128, 0) == [0, 1] | ||
|
||
function %iaddcarry_i8_c(i8, i8, i8) -> i8 { | ||
block0(v0: i8, v1: i8, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v4 | ||
function %sadd_overflow_cin_i16(i16, i16, i8) -> i16, i8 { | ||
block0(v0: i16, v1: i16, v2: i8): | ||
v3, v4 = sadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i8_c(0, 1, 1) == 0 | ||
; run: %iaddcarry_i8_c(0, 1, 0) == 0 | ||
; run: %iaddcarry_i8_c(100, 27, 1) == 1 | ||
; run: %iaddcarry_i8_c(100, 27, 0) == 0 | ||
; run: %iaddcarry_i8_c(127, 127, 1) == 1 | ||
; run: %iaddcarry_i8_c(127, 127, 0) == 1 | ||
; run: %iaddcarry_i8_c(-128, -128, 0) == 1 | ||
; run: %sadd_overflow_cin_i16(0, 1, 1) == [2, 0] | ||
; run: %sadd_overflow_cin_i16(0, 1, 10) == [2, 0] | ||
; run: %sadd_overflow_cin_i16(0, 1, 0) == [1, 0] | ||
; run: %sadd_overflow_cin_i16(100, 27, 1) == [128, 0] | ||
; run: %sadd_overflow_cin_i16(100, 27, 0) == [127, 0] | ||
; run: %sadd_overflow_cin_i16(32000, 767, 1) == [-32768, 1] | ||
; run: %sadd_overflow_cin_i16(32000, 767, 0) == [32767, 0] | ||
|
||
function %iaddcarry_i16_v(i16, i16, i8) -> i16 { | ||
block0(v0: i16, v1: i16, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v3 | ||
function %sadd_overflow_cin_i32(i32, i32, i8) -> i32, i8 { | ||
block0(v0: i32, v1: i32, v2: i8): | ||
v3, v4 = sadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i16_v(0, 1, 1) == 2 | ||
; run: %iaddcarry_i16_v(0, 1, 0) == 1 | ||
; run: %iaddcarry_i16_v(100, 27, 1) == 128 | ||
; run: %iaddcarry_i16_v(100, 27, 0) == 127 | ||
; run: %iaddcarry_i16_v(32000, 767, 1) == -32768 | ||
; run: %iaddcarry_i16_v(32000, 767, 0) == 32767 | ||
; run: %sadd_overflow_cin_i32(0, 1, 1) == [2, 0] | ||
; run: %sadd_overflow_cin_i32(0, 1, 10) == [2, 0] | ||
; run: %sadd_overflow_cin_i32(0, 1, 0) == [1, 0] | ||
; run: %sadd_overflow_cin_i32(100, 27, 1) == [128, 0] | ||
; run: %sadd_overflow_cin_i32(100, 27, 0) == [127, 0] | ||
; run: %sadd_overflow_cin_i32(2000000000, 147483647, 1) == [-2147483648, 1] | ||
; run: %sadd_overflow_cin_i32(2000000000, 147483647, 0) == [2147483647, 0] | ||
|
||
function %iaddcarry_i16_c(i16, i16, i8) -> i8 { | ||
block0(v0: i16, v1: i16, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v4 | ||
function %sadd_overflow_cin_i64(i64, i64, i8) -> i64, i8 { | ||
block0(v0: i64, v1: i64, v2: i8): | ||
v3, v4 = sadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i16_c(0, 1, 1) == 0 | ||
; run: %iaddcarry_i16_c(0, 1, 0) == 0 | ||
; run: %iaddcarry_i16_c(100, 27, 1) == 0 | ||
; run: %iaddcarry_i16_c(100, 27, 0) == 0 | ||
; run: %iaddcarry_i16_c(32000, 767, 1) == 1 | ||
; run: %iaddcarry_i16_c(32000, 767, 0) == 0 | ||
; run: %sadd_overflow_cin_i64(0, 1, 1) == [2, 0] | ||
; run: %sadd_overflow_cin_i64(0, 1, 10) == [2, 0] | ||
; run: %sadd_overflow_cin_i64(0, 1, 0) == [1, 0] | ||
; run: %sadd_overflow_cin_i64(100, 27, 1) == [128, 0] | ||
; run: %sadd_overflow_cin_i64(100, 27, 0) == [127, 0] | ||
; run: %sadd_overflow_cin_i64(9000000000000000000, 223372036854775807, 1) == [-9223372036854775808, 1] | ||
; run: %sadd_overflow_cin_i64(9000000000000000000, 223372036854775807, 0) == [9223372036854775807, 0] | ||
|
||
function %iaddcarry_i32_v(i32, i32, i8) -> i32 { | ||
block0(v0: i32, v1: i32, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v3 | ||
function %uadd_overflow_cin_i8(i8, i8, i8) -> i8, i8 { | ||
block0(v0: i8, v1: i8, v2: i8): | ||
v3, v4 = uadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i32_v(0, 1, 1) == 2 | ||
; run: %iaddcarry_i32_v(0, 1, 0) == 1 | ||
; run: %iaddcarry_i32_v(100, 27, 1) == 128 | ||
; run: %iaddcarry_i32_v(100, 27, 0) == 127 | ||
; run: %iaddcarry_i32_v(2000000000, 147483647, 1) == -2147483648 | ||
; run: %iaddcarry_i32_v(2000000000, 147483647, 0) == 2147483647 | ||
; run: %uadd_overflow_cin_i8(0, 1, 1) == [2, 0] | ||
; run: %uadd_overflow_cin_i8(0, 1, 10) == [2, 0] | ||
; run: %uadd_overflow_cin_i8(0, 1, 0) == [1, 0] | ||
; run: %uadd_overflow_cin_i8(100, 27, 1) == [-128, 0] | ||
; run: %uadd_overflow_cin_i8(100, 27, 0) == [127, 0] | ||
; run: %uadd_overflow_cin_i8(127, 127, 1) == [-1, 0] | ||
; run: %uadd_overflow_cin_i8(127, 127, 0) == [-2, 0] | ||
; run: %uadd_overflow_cin_i8(-128, -128, 0) == [0, 1] | ||
; run: %uadd_overflow_cin_i8(-1, -1, 0) == [-2, 1] | ||
; run: %uadd_overflow_cin_i8(-1, -1, 1) == [-1, 1] | ||
|
||
function %iaddcarry_i32_c(i32, i32, i8) -> i8 { | ||
block0(v0: i32, v1: i32, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v4 | ||
function %uadd_overflow_cin_i16(i16, i16, i8) -> i16, i8 { | ||
block0(v0: i16, v1: i16, v2: i8): | ||
v3, v4 = uadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i32_c(0, 1, 1) == 0 | ||
; run: %iaddcarry_i32_c(0, 1, 0) == 0 | ||
; run: %iaddcarry_i32_c(100, 27, 1) == 0 | ||
; run: %iaddcarry_i32_c(100, 27, 0) == 0 | ||
; run: %iaddcarry_i32_c(2000000000, 147483647, 1) == 1 | ||
; run: %iaddcarry_i32_c(2000000000, 147483647, 0) == 0 | ||
; run: %uadd_overflow_cin_i16(0, 1, 1) == [2, 0] | ||
; run: %uadd_overflow_cin_i16(0, 1, 10) == [2, 0] | ||
; run: %uadd_overflow_cin_i16(0, 1, 0) == [1, 0] | ||
; run: %uadd_overflow_cin_i16(100, 27, 1) == [128, 0] | ||
; run: %uadd_overflow_cin_i16(100, 27, 0) == [127, 0] | ||
; run: %uadd_overflow_cin_i16(32000, 767, 1) == [-32768, 0] | ||
; run: %uadd_overflow_cin_i16(32000, 767, 0) == [32767, 0] | ||
; run: %uadd_overflow_cin_i16(-1, -1, 0) == [-2, 1] | ||
; run: %uadd_overflow_cin_i16(-1, -1, 1) == [-1, 1] | ||
|
||
function %iaddcarry_i64_v(i64, i64, i8) -> i64 { | ||
block0(v0: i64, v1: i64, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v3 | ||
function %uadd_overflow_cin_i32(i32, i32, i8) -> i32, i8 { | ||
block0(v0: i32, v1: i32, v2: i8): | ||
v3, v4 = uadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i64_v(0, 1, 1) == 2 | ||
; run: %iaddcarry_i64_v(0, 1, 0) == 1 | ||
; run: %iaddcarry_i64_v(100, 27, 1) == 128 | ||
; run: %iaddcarry_i64_v(100, 27, 0) == 127 | ||
; run: %iaddcarry_i64_v(9000000000000000000, 223372036854775807, 1) == -9223372036854775808 | ||
; run: %iaddcarry_i64_v(9000000000000000000, 223372036854775807, 0) == 9223372036854775807 | ||
; run: %uadd_overflow_cin_i32(0, 1, 1) == [2, 0] | ||
; run: %uadd_overflow_cin_i32(0, 1, 10) == [2, 0] | ||
; run: %uadd_overflow_cin_i32(0, 1, 0) == [1, 0] | ||
; run: %uadd_overflow_cin_i32(100, 27, 1) == [128, 0] | ||
; run: %uadd_overflow_cin_i32(100, 27, 0) == [127, 0] | ||
; run: %uadd_overflow_cin_i32(2000000000, 147483647, 1) == [-2147483648, 0] | ||
; run: %uadd_overflow_cin_i32(2000000000, 147483647, 0) == [2147483647, 0] | ||
; run: %uadd_overflow_cin_i32(-1, -1, 0) == [-2, 1] | ||
; run: %uadd_overflow_cin_i32(-1, -1, 1) == [-1, 1] | ||
|
||
function %iaddcarry_i64_c(i64, i64, i8) -> i8 { | ||
function %uadd_overflow_cin_i64(i64, i64, i8) -> i64, i8 { | ||
block0(v0: i64, v1: i64, v2: i8): | ||
v3, v4 = iadd_carry v0, v1, v2 | ||
return v4 | ||
v3, v4 = uadd_overflow_cin v0, v1, v2 | ||
return v3, v4 | ||
} | ||
; run: %iaddcarry_i64_c(0, 1, 1) == 0 | ||
; run: %iaddcarry_i64_c(0, 1, 0) == 0 | ||
; run: %iaddcarry_i64_c(100, 27, 1) == 0 | ||
; run: %iaddcarry_i64_c(100, 27, 0) == 0 | ||
; run: %iaddcarry_i64_c(9000000000000000000, 223372036854775807, 1) == 1 | ||
; run: %iaddcarry_i64_c(9000000000000000000, 223372036854775807, 0) == 0 | ||
; run: %uadd_overflow_cin_i64(0, 1, 1) == [2, 0] | ||
; run: %uadd_overflow_cin_i64(0, 1, 10) == [2, 0] | ||
; run: %uadd_overflow_cin_i64(0, 1, 0) == [1, 0] | ||
; run: %uadd_overflow_cin_i64(100, 27, 1) == [128, 0] | ||
; run: %uadd_overflow_cin_i64(100, 27, 0) == [127, 0] | ||
; run: %uadd_overflow_cin_i64(9000000000000000000, 223372036854775807, 1) == [-9223372036854775808, 0] | ||
; run: %uadd_overflow_cin_i64(9000000000000000000, 223372036854775807, 0) == [9223372036854775807, 0] | ||
; run: %uadd_overflow_cin_i64(-1, -1, 0) == [-2, 1] | ||
; run: %uadd_overflow_cin_i64(-1, -1, 1) == [-1, 1] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.