Stream: git-wasmtime

Topic: wasmtime / issue #6787 s390x: ixx.trunc_sat_fxx_u with Na...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 31 2023 at 05:00):

candymate opened issue #6787:

Test Case

Cases with i64.trunc_sat_f32_u, i64.trunc_sat_f64_u, i32.trunc_sat_f32_u, i32.trunc_sat_f64_u work

One example

(module
  (type (;0;) (func (param f32) (result i64)))
  (func (;0;) (type 0) (param f32) (result i64)
    local.get 0
    i64.trunc_sat_f32_u
  )
  (export "main" (func 0))
)
use wasmtime::*;

fn main() -> Result<()> {
    let engine = Engine::default();
    let module = Module::from_file(&engine, "test.wat")?;
    let mut store = Store::new(&engine, ());

    let instance = Instance::new(&mut store, &module, &[])?;
    let main = instance.get_typed_func::<f32, i64>(&mut store, "main")?;
    println!("main(NaN) = {}", main.call(&mut store, f32::NAN)?);
    Ok(())
}

Steps to Reproduce

Run the following code with s390x

cargo run --release --target=s390x-unknown-linux-gnu

Expected Results

ixx.trunc_sat_fxx_u with NaN should result in 0. (https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-sat-u)

main(NaN) = 0

Actual Results

main(NaN) = -1

Versions and Environment

Wasmtime version or commit: v11.0.1 Release

Operating system: Ubuntu 20.04.6

Architecture: s390x

view this post on Zulip Wasmtime GitHub notifications bot (Jul 31 2023 at 05:00):

candymate added the bug label to Issue #6787.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 31 2023 at 05:01):

cfallin commented on issue #6787:

cc @uweigand, can you take a look?

view this post on Zulip Wasmtime GitHub notifications bot (Jul 31 2023 at 14:59):

uweigand commented on issue #6787:

Unfortunately I'm unable to reproduce the problem, the provided test case gives the correct output for me:

main(NaN) = 0

Not sure what exactly is different in your situation, it must be some environment issue. Which Rust version are you using? Which s390x processor version?

Note that there is a spec conformance test in the wasmtime testsuite that verifies these specific corner cases:
https://github.com/WebAssembly/testsuite/blob/7ef86ddeed81458f9031a49a40b3a3f99c1c6a8a/conversions.wast#L399
This test is continually passing in CI on s390x, so the core implementation should be correct.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 01 2023 at 02:25):

candymate commented on issue #6787:

Thanks for the response.

I was using an old QEMU, and it seemed to be the cause of the problem. After updating QEMU, it now gives me the correct output.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 01 2023 at 02:25):

candymate closed issue #6787:

Test Case

Cases with i64.trunc_sat_f32_u, i64.trunc_sat_f64_u, i32.trunc_sat_f32_u, i32.trunc_sat_f64_u work

One example

(module
  (type (;0;) (func (param f32) (result i64)))
  (func (;0;) (type 0) (param f32) (result i64)
    local.get 0
    i64.trunc_sat_f32_u
  )
  (export "main" (func 0))
)
use wasmtime::*;

fn main() -> Result<()> {
    let engine = Engine::default();
    let module = Module::from_file(&engine, "test.wat")?;
    let mut store = Store::new(&engine, ());

    let instance = Instance::new(&mut store, &module, &[])?;
    let main = instance.get_typed_func::<f32, i64>(&mut store, "main")?;
    println!("main(NaN) = {}", main.call(&mut store, f32::NAN)?);
    Ok(())
}

Steps to Reproduce

Run the following code with s390x

cargo run --release --target=s390x-unknown-linux-gnu

Expected Results

ixx.trunc_sat_fxx_u with NaN should result in 0. (https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-sat-u)

main(NaN) = 0

Actual Results

main(NaN) = -1

Versions and Environment

Wasmtime version or commit: v11.0.1 Release

Operating system: Ubuntu 20.04.6

Architecture: s390x

view this post on Zulip Wasmtime GitHub notifications bot (Aug 01 2023 at 07:39):

uweigand commented on issue #6787:

I was using an old QEMU, and it seemed to be the cause of the problem.

Ah yes, some older QEMU versions had a bug in the emulation of the float-to-int conversion instructions - that would explain it.


Last updated: Nov 22 2024 at 16:03 UTC