Stream: git-wasmtime

Topic: wasmtime / issue #5992 Cranelift: RISC-V wrong result for...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 11 2023 at 17:23):

afonso360 edited issue #5992:

:wave: Hey,

.clif Test Case

test interpret
test run
target riscv64gc

function %a_f32(f32) -> i16 {
block0(v0: f32):
    v1 = fcvt_to_uint_sat.i16 v0
    return v1
}
; run: %a_f32(0x1.949400p21) == -1


function %b_f32(f32) -> i8 {
block0(v0: f32):
    v1 = fcvt_to_uint_sat.i8 v0
    return v1
}
; run: %b_f32(0x1.949400p21) == -1


function %a_f64(f64) -> i16 {
block0(v0: f64):
    v1 = fcvt_to_uint_sat.i16 v0
    return v1
}
; run: %a_f64(0x1.949400p21) == -1


function %b_f64(f64) -> i8 {
block0(v0: f64):
    v1 = fcvt_to_uint_sat.i8 v0
    return v1
}
; run: %b_f64(0x1.949400p21) == -1

Steps to Reproduce

Expected Results

The test to pass

Actual Results

    Failed test: run: %a_f32(0x1.949400p21) == -1, actual: -28032
    Failed test: run: %b_f32(0x1.949400p21) == -1, actual: -128
    Failed test: run: %a_f64(0x1.9494000000000p21) == -1, actual: -28032
    Failed test: run: %b_f64(0x1.9494000000000p21) == -1, actual: -128

Versions and Environment

Cranelift version or commit: main

Operating system: Linux

Architecture: riscv64

Extra Info

cc: @yuyang-ok

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

yuyang-ok commented on issue #5992:

Should works fine.
generate code quit simple.

test interpret
test run
target riscv64

function %b_f32(f32) -> i8 {
block0(v0: f32):
v1 = fcvt_to_uint_sat.i8 v0
return v1
}
; run: %b_f32(0x1.949400p21) == -1


Disassembly of 24 bytes:
0: 53 25 a5 a0 feq.s a0, fa0, fa0
4: 63 06 05 00 beqz a0, 0xc
8: 53 05 15 c0 fcvt.wu.s a0, fa0, rne
c: 6f 00 80 00 j 8
10: 13 05 00 00 mv a0, zero
14: 67 80 00 00 ret


view this post on Zulip Wasmtime GitHub notifications bot (Mar 13 2023 at 05:03):

yuyang-ok edited a comment on issue #5992:

Should works fine.
generated code quit simple.

test interpret
test run
target riscv64

function %b_f32(f32) -> i8 {
block0(v0: f32):
v1 = fcvt_to_uint_sat.i8 v0
return v1
}
; run: %b_f32(0x1.949400p21) == -1


Disassembly of 24 bytes:
0: 53 25 a5 a0 feq.s a0, fa0, fa0
4: 63 06 05 00 beqz a0, 0xc
8: 53 05 15 c0 fcvt.wu.s a0, fa0, rne
c: 6f 00 80 00 j 8
10: 13 05 00 00 mv a0, zero
14: 67 80 00 00 ret


view this post on Zulip Wasmtime GitHub notifications bot (Mar 13 2023 at 05:08):

yuyang-ok commented on issue #5992:

@afonso360 Any Idea about this issue.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 13 2023 at 05:08):

yuyang-ok edited a comment on issue #5992:

@afonso360 Any Idea about this issue??

view this post on Zulip Wasmtime GitHub notifications bot (Mar 13 2023 at 05:10):

yuyang-ok edited a comment on issue #5992:

@afonso360 Any idea about this issue??

view this post on Zulip Wasmtime GitHub notifications bot (Mar 13 2023 at 10:52):

afonso360 commented on issue #5992:

Right, fcvt.wu.s operates on the full 32bit values. Which means that when performing this conversion it does not saturate up to the max of i8 (or i16).

When looking at what LLVM does for this operation it looks like they manually clamp the value using fmin/fmax before doing the operation.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 14 2023 at 02:15):

yuyang-ok commented on issue #5992:

@afonso360 Thanks.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2023 at 21:12):

afonso360 commented on issue #5992:

Fixed in #7327

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2023 at 21:12):

afonso360 closed issue #5992:

:wave: Hey,

.clif Test Case

test interpret
test run
target riscv64gc

function %a_f32(f32) -> i16 {
block0(v0: f32):
    v1 = fcvt_to_uint_sat.i16 v0
    return v1
}
; run: %a_f32(0x1.949400p21) == -1


function %b_f32(f32) -> i8 {
block0(v0: f32):
    v1 = fcvt_to_uint_sat.i8 v0
    return v1
}
; run: %b_f32(0x1.949400p21) == -1


function %a_f64(f64) -> i16 {
block0(v0: f64):
    v1 = fcvt_to_uint_sat.i16 v0
    return v1
}
; run: %a_f64(0x1.949400p21) == -1


function %b_f64(f64) -> i8 {
block0(v0: f64):
    v1 = fcvt_to_uint_sat.i8 v0
    return v1
}
; run: %b_f64(0x1.949400p21) == -1

Steps to Reproduce

Expected Results

The test to pass

Actual Results

    Failed test: run: %a_f32(0x1.949400p21) == -1, actual: -28032
    Failed test: run: %b_f32(0x1.949400p21) == -1, actual: -128
    Failed test: run: %a_f64(0x1.9494000000000p21) == -1, actual: -28032
    Failed test: run: %b_f64(0x1.9494000000000p21) == -1, actual: -128

Versions and Environment

Cranelift version or commit: main

Operating system: Linux

Architecture: riscv64

Extra Info

cc: @yuyang-ok


Last updated: Dec 23 2024 at 12:05 UTC