Stream: general

Topic: ✔ overflow implmentation.


view this post on Zulip yang yu (Jul 07 2022 at 01:32):

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.

A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Afonso Bordado (Jul 07 2022 at 15:08):

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!

view this post on Zulip Afonso Bordado (Jul 07 2022 at 15:15):

Also, our implementation is very different from what LLVM outputs

A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.
pub fn of_check(a: i128, b: i128) -> bool { a.checked_sub(b).is_none() }

view this post on Zulip Afonso Bordado (Jul 07 2022 at 16:24):

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!

@yuyang-ok reported via zulip that i128 overflow tests were wrong. It turns out that both the tests and the aarch64 codegen are wrong. I've altered the implementation to match what LLVM produces, a...

view this post on Zulip yang yu (Jul 08 2022 at 05:19):

@Afonso Bordado ok, thanks.

view this post on Zulip Notification Bot (Aug 10 2022 at 00:44):

yang yu has marked this topic as resolved.


Last updated: Dec 23 2024 at 12:05 UTC