afonso360 edited issue #5992:
:wave: Hey,
.clif
Test Casetest 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
clif-util test ./the-above.clif
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
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
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
yuyang-ok commented on issue #5992:
@afonso360 Any Idea about this issue.
yuyang-ok edited a comment on issue #5992:
@afonso360 Any Idea about this issue??
yuyang-ok edited a comment on issue #5992:
@afonso360 Any idea about this issue??
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 ofi8
(ori16
).When looking at what LLVM does for this operation it looks like they manually clamp the value using
fmin
/fmax
before doing the operation.
yuyang-ok commented on issue #5992:
@afonso360 Thanks.
afonso360 commented on issue #5992:
Fixed in #7327
afonso360 closed issue #5992:
:wave: Hey,
.clif
Test Casetest 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
clif-util test ./the-above.clif
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