Files
wasmtime/cranelift/filetests/filetests/runtests/fma.clif
Afonso Bordado 2003ae99a0 Implement fma/fabs/fneg/fcopysign on the interpreter (#4367)
* cranelift: Implement `fma` on interpreter

* cranelift: Implement `fabs` on interpreter

* cranelift: Fix `fneg` implementation on interpreter

`fneg` was implemented as `0 - x` which is not correct according to the
standard since that operation makes no guarantees on what the output
is when the input is `NaN`. However for `fneg` the output for `NaN`
inputs is fully defined.

* cranelift: Implement `fcopysign` on interpreter
2022-07-05 09:03:04 -07:00

120 lines
4.8 KiB
Plaintext

test interpret
test run
target aarch64
target s390x
function %fma_f32(f32, f32, f32) -> f32 {
block0(v0: f32, v1: f32, v2: f32):
v3 = fma v0, v1, v2
return v3
}
; run: %fma_f32(0x9.0, 0x9.0, 0x9.0) == 0x1.680000p6
; run: %fma_f32(0x83.0, 0x2.68091p6, 0x9.88721p1) == 0x1.3b88e6p14
; run: %fma_f32(0x0.0, 0x0.0, 0x0.0) == 0x0.0
; run: %fma_f32(0x0.0, 0x0.0, -0x0.0) == 0x0.0
; run: %fma_f32(0x0.0, -0x0.0, 0x0.0) == 0x0.0
; run: %fma_f32(-0x0.0, 0x0.0, 0x0.0) == 0x0.0
; run: %fma_f32(-Inf, -Inf, 0x0.0) == +Inf
; run: %fma_f32(Inf, -Inf, 0x0.0) == -Inf
; run: %fma_f32(-Inf, Inf, 0x0.0) == -Inf
; run: %fma_f32(Inf, -Inf, -Inf) == -Inf
; run: %fma_f32(-Inf, Inf, -Inf) == -Inf
; F32 Epsilon / Max / Min Positive
; run: %fma_f32(0x1.000000p-23, 0x1.000000p-23, 0x1.000000p-23) == 0x1.000002p-23
; run: %fma_f32(0x0.0, 0x0.0, 0x1.000000p-23) == 0x1.000000p-23
; run: %fma_f32(0x1.fffffep127, 0x1.fffffep127, 0x1.fffffep127) == +Inf
; run: %fma_f32(0x0.0, 0x0.0, 0x1.fffffep127) == 0x1.fffffep127
; run: %fma_f32(0x1.000000p-126, 0x1.000000p-126, 0x1.000000p-126) == 0x1.000000p-126
; run: %fma_f32(0x0.0, 0x0.0, 0x1.000000p-126) == 0x1.000000p-126
; F32 Subnormals
; run: %fma_f32(0x0.800000p-126, 0x0.800000p-126, 0x0.800000p-126) == 0x0.800000p-126
; run: %fma_f32(0x0.800000p-126, 0x0.800000p-126, 0x0.0) == 0x0.0
; run: %fma_f32(0x0.0, 0x0.0, 0x0.800000p-126) == 0x0.800000p-126
; run: %fma_f32(0x0.000002p-126, 0x0.000002p-126, 0x0.000002p-126) == 0x0.000002p-126
; run: %fma_f32(0x0.000002p-126, 0x0.000002p-126, 0x0.0) == 0x0.0
; run: %fma_f32(0x0.0, 0x0.0, 0x0.000002p-126) == 0x0.000002p-126
;; The IEEE754 Standard does not make a lot of guarantees about what
;; comes out of NaN producing operations, we just check if its a NaN
function %fma_is_nan_f32(f32, f32, f32) -> i32 {
block0(v0: f32, v1: f32, v2: f32):
v3 = fma v0, v1, v2
v4 = fcmp ne v3, v3
v5 = bint.i32 v4
return v5
}
; run: %fma_is_nan_f32(Inf, -Inf, Inf) == 1
; run: %fma_is_nan_f32(-Inf, Inf, Inf) == 1
; run: %fma_is_nan_f32(-Inf, -Inf, -Inf) == 1
; run: %fma_is_nan_f32(+NaN, 0x0.0, 0x0.0) == 1
; run: %fma_is_nan_f32(0x0.0, +NaN, 0x0.0) == 1
; run: %fma_is_nan_f32(0x0.0, 0x0.0, +NaN) == 1
; run: %fma_is_nan_f32(-NaN, 0x0.0, 0x0.0) == 1
; run: %fma_is_nan_f32(0x0.0, -NaN, 0x0.0) == 1
; run: %fma_is_nan_f32(0x0.0, 0x0.0, -NaN) == 1
function %fma_f64(f64, f64, f64) -> f64 {
block0(v0: f64, v1: f64, v2: f64):
v3 = fma v0, v1, v2
return v3
}
; run: %fma_f64(0x9.0, 0x9.0, 0x9.0) == 0x1.680000p6
; run: %fma_f64(0x1.3b88ea148dd4ap14, 0x2.680916809121p6, 0x9.887218721837p1) == 0x1.7ba6ebee17417p21
; run: %fma_f64(0x0.0, 0x0.0, 0x0.0) == 0x0.0
; run: %fma_f64(0x0.0, 0x0.0, -0x0.0) == 0x0.0
; run: %fma_f64(0x0.0, -0x0.0, 0x0.0) == 0x0.0
; run: %fma_f64(-0x0.0, 0x0.0, 0x0.0) == 0x0.0
; run: %fma_f64(-Inf, -Inf, 0x0.0) == +Inf
; run: %fma_f64(Inf, -Inf, 0x0.0) == -Inf
; run: %fma_f64(-Inf, Inf, 0x0.0) == -Inf
; run: %fma_f64(Inf, -Inf, -Inf) == -Inf
; run: %fma_f64(-Inf, Inf, -Inf) == -Inf
; F64 Epsilon / Max / Min Positive
; run: %fma_f64(0x1.0000000000000p-52, 0x1.0000000000000p-52, 0x1.0000000000000p-52) == 0x1.0000000000001p-52
; run: %fma_f64(0x0.0, 0x0.0, 0x1.0000000000000p-52) == 0x1.0000000000000p-52
; run: %fma_f64(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023) == +Inf
; run: %fma_f64(0x0.0, 0x0.0, 0x1.fffffffffffffp1023) == 0x1.fffffffffffffp1023
; run: %fma_f64(0x1.0000000000000p-1022, 0x1.0000000000000p-1022, 0x1.0000000000000p-1022) == 0x1.0000000000000p-1022
; run: %fma_f64(0x0.0, 0x0.0, 0x1.0000000000000p-1022) == 0x1.0000000000000p-1022
; F64 Subnormals
; run: %fma_f64(0x0.8000000000000p-1022, 0x0.8000000000000p-1022, 0x0.8000000000000p-1022) == 0x0.8000000000000p-1022
; run: %fma_f64(0x0.8000000000000p-1022, 0x0.8000000000000p-1022, 0x0.0) == 0x0.0
; run: %fma_f64(0x0.0, 0x0.0, 0x0.8000000000000p-1022) == 0x0.8000000000000p-1022
; run: %fma_f64(0x0.0000000000001p-1022, 0x0.0000000000001p-1022, 0x0.0000000000001p-1022) == 0x0.0000000000001p-1022
; run: %fma_f64(0x0.0000000000001p-1022, 0x0.0000000000001p-1022, 0x0.0) == 0x0.0
; run: %fma_f64(0x0.0, 0x0.0, 0x0.0000000000001p-1022) == 0x0.0000000000001p-1022
;; The IEEE754 Standard does not make a lot of guarantees about what
;; comes out of NaN producing operations, we just check if its a NaN
function %fma_is_nan_f64(f64, f64, f64) -> i32 {
block0(v0: f64, v1: f64, v2: f64):
v3 = fma v0, v1, v2
v4 = fcmp ne v3, v3
v5 = bint.i32 v4
return v5
}
; run: %fma_is_nan_f64(Inf, -Inf, Inf) == 1
; run: %fma_is_nan_f64(-Inf, Inf, Inf) == 1
; run: %fma_is_nan_f64(-Inf, -Inf, -Inf) == 1
; run: %fma_is_nan_f64(+NaN, 0x0.0, 0x0.0) == 1
; run: %fma_is_nan_f64(0x0.0, +NaN, 0x0.0) == 1
; run: %fma_is_nan_f64(0x0.0, 0x0.0, +NaN) == 1
; run: %fma_is_nan_f64(-NaN, 0x0.0, 0x0.0) == 1
; run: %fma_is_nan_f64(0x0.0, -NaN, 0x0.0) == 1
; run: %fma_is_nan_f64(0x0.0, 0x0.0, -NaN) == 1