I am trying to implement overflow in risc-v.
I look at the interpreter.
https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/interpreter/src/value.rs#L448
overflow should implemented as "checked_sub".
but in test file.
function %icmp_of_i128(i128, i128) -> b1 {
block0(v0: i128, v1: i128):
v2 = icmp.i128 of v0, v1
return v2
}
; run: %icmp_of_i128(0, 0) == false
; run: %icmp_of_i128(0, 1) == false
; run: %icmp_of_i128(0, -1) == false
; run: %icmp_of_i128(-1, -1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == false
; run: %icmp_of_i128(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == true
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == false
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == true
; run: %icmp_of_i128(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
should not overflow.
Hey,
This is interesting... I think it may be a codegen bug in the aarch64 backend and a wrong test suite. I'm going to check this a bit further, but my initial guess would be that the interpreter has the correct implementation.
It is also weird that this testsuite does not have test interpret
when the interpreter has this implemented.
Thanks for finding this!
Also, our implementation is very different from what LLVM outputs
Just to let you know, I've added a PR to fix this issue: https://github.com/bytecodealliance/wasmtime/pull/4403
Thanks for the report!
@Afonso Bordado ok, thanks.
yang yu has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC