cranelift: Fix fdemote on the interpreter (#5158)

* cranelift: Cleanup `fdemote`/`fpromote` tests

* cranelift: Fix `fdemote`/`fpromote` instruction docs

The verifier fails if the input and output types are the same
for these instructions

* cranelift: Fix `fdemote`/`fpromote` in the interpreter

* fuzzgen: Add `fdemote`/`fpromote`
This commit is contained in:
Afonso Bordado
2022-11-15 22:22:00 +00:00
committed by GitHub
parent a007e02bd2
commit a793648eb2
8 changed files with 249 additions and 100 deletions

View File

@@ -0,0 +1,91 @@
test interpret
test run
target x86_64
target s390x
target aarch64
target riscv64
function %fdemote(f64) -> f32 {
block0(v0: f64):
v1 = fdemote.f32 v0
return v1
}
; run: %fdemote(0x0.0) == 0x0.0
; run: %fdemote(-0x0.0) == -0x0.0
; run: %fdemote(0x0.1) == 0x0.1
; run: %fdemote(0x0.2) == 0x0.2
; run: %fdemote(0x0.5) == 0x0.5
; run: %fdemote(-0x0.5) == -0x0.5
; run: %fdemote(0x3.2) == 0x3.2
; run: %fdemote(0x9.0) == 0x9.0
; run: %fdemote(-0x9.0) == -0x9.0
; run: %fdemote(0x1.1p10) == 0x1.100000p10
; run: %fdemote(-0x1.1p10) == -0x1.100000p10
; run: %fdemote(0x1.c555555555556p10) == 0x1.c55556p10
; run: %fdemote(-0x1.999999999999ap-2) == -0x1.99999ap-2
; run: %fdemote(0x1.c3c3c3c3c3c3cp-1) == 0x1.c3c3c4p-1
; run: %fdemote(0x1.c924924924925p-1) == 0x1.c92492p-1
; run: %fdemote(0x1.4cccccccccccdp0) == 0x1.4cccccp0
;; Inf
; run: %fdemote(Inf) == Inf
; run: %fdemote(-Inf) == -Inf
;; Epsilon / Max / Min Positive
; run: %fdemote(0x1.0000000000000p-52) == 0x1.0000000000000p-52
; run: %fdemote(-0x1.0000000000000p-52) == -0x1.0000000000000p-52
; run: %fdemote(0x1.fffffffffffffp1023) == +Inf
; run: %fdemote(-0x1.fffffffffffffp1023) == -Inf
; run: %fdemote(0x1.0000000000000p-1022) == 0x0.0
; run: %fdemote(-0x1.0000000000000p-1022) == -0x0.0
;; Subnormals
; run: %fdemote(0x0.8000000000000p-1022) == 0x0.0
; run: %fdemote(-0x0.8000000000000p-1022) == -0x0.0
; run: %fdemote(0x0.0000000000001p-1022) == 0x0.0
; run: %fdemote(-0x0.0000000000001p-1022) == -0x0.0
;; NaN's
; For NaN's this operation is specified as producing a value that is a NaN
function %fdemote_is_nan(f64) -> i8 {
block0(v0: f64):
v1 = fdemote.f32 v0
v2 = fcmp ne v1, v1
return v2
}
; run: %fdemote_is_nan(+NaN) == 1
; run: %fdemote_is_nan(-NaN) == 1
; run: %fdemote_is_nan(+NaN:0x0) == 1
; run: %fdemote_is_nan(+NaN:0x1) == 1
; run: %fdemote_is_nan(+NaN:0x4000000000001) == 1
; run: %fdemote_is_nan(-NaN:0x0) == 1
; run: %fdemote_is_nan(-NaN:0x1) == 1
; run: %fdemote_is_nan(-NaN:0x4000000000001) == 1
; run: %fdemote_is_nan(+sNaN:0x1) == 1
; run: %fdemote_is_nan(-sNaN:0x1) == 1
; run: %fdemote_is_nan(+sNaN:0x4000000000001) == 1
; run: %fdemote_is_nan(-sNaN:0x4000000000001) == 1
;; Tests a fdemote+load combo which some backends may optimize
function %fdemote_load(i64 vmctx, i64, f64) -> f32 {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0+0
heap0 = static gv1, min 0x10, bound 0x10, offset_guard 0x0, index_type i64
block0(v0: i64, v1: i64, v2: f64):
v3 = heap_addr.i64 heap0, v1, 0, 8
store.f64 v2, v3
v4 = load.f64 v3
v5 = fdemote.f32 v4
return v5
}
; heap: static, size=0x10, ptr=vmctx+0, bound=vmctx+8
; run: %fdemote_load(0, 0x0.0) == 0x0.0
; run: %fdemote_load(1, 0x0.1) == 0x0.1
; run: %fdemote_load(2, 0x0.2) == 0x0.2
; run: %fdemote_load(3, 0x3.2) == 0x3.2
; run: %fdemote_load(0x8, 0x3.2) == 0x3.2