cranelift: Implement float rounding operations (#4397)
Implements the following operations on the interpreter: * `ceil` * `floor` * `nearest` * `trunc`
This commit is contained in:
@@ -800,6 +800,26 @@ impl Ieee32 {
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.as_f32() == 0.0
|
||||
}
|
||||
|
||||
/// Returns the smallest integer greater than or equal to `self`.
|
||||
pub fn ceil(self) -> Self {
|
||||
Self::with_float(self.as_f32().ceil())
|
||||
}
|
||||
|
||||
/// Returns the largest integer less than or equal to `self`.
|
||||
pub fn floor(self) -> Self {
|
||||
Self::with_float(self.as_f32().floor())
|
||||
}
|
||||
|
||||
/// Returns the integer part of `self`. This means that non-integer numbers are always truncated towards zero.
|
||||
pub fn trunc(self) -> Self {
|
||||
Self::with_float(self.as_f32().trunc())
|
||||
}
|
||||
|
||||
/// Returns the nearest integer to `self`. Round half-way cases away from `0.0`.
|
||||
pub fn nearest(self) -> Self {
|
||||
Self::with_float(self.as_f32().round())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Ieee32 {
|
||||
@@ -929,6 +949,26 @@ impl Ieee64 {
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.as_f64() == 0.0
|
||||
}
|
||||
|
||||
/// Returns the smallest integer greater than or equal to `self`.
|
||||
pub fn ceil(self) -> Self {
|
||||
Self::with_float(self.as_f64().ceil())
|
||||
}
|
||||
|
||||
/// Returns the largest integer less than or equal to `self`.
|
||||
pub fn floor(self) -> Self {
|
||||
Self::with_float(self.as_f64().floor())
|
||||
}
|
||||
|
||||
/// Returns the integer part of `self`. This means that non-integer numbers are always truncated towards zero.
|
||||
pub fn trunc(self) -> Self {
|
||||
Self::with_float(self.as_f64().trunc())
|
||||
}
|
||||
|
||||
/// Returns the nearest integer to `self`. Round half-way cases away from `0.0`.
|
||||
pub fn nearest(self) -> Self {
|
||||
Self::with_float(self.as_f64().round())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Ieee64 {
|
||||
|
||||
119
cranelift/filetests/filetests/runtests/ceil.clif
Normal file
119
cranelift/filetests/filetests/runtests/ceil.clif
Normal file
@@ -0,0 +1,119 @@
|
||||
test interpret
|
||||
test run
|
||||
target x86_64
|
||||
target aarch64
|
||||
target s390x
|
||||
|
||||
function %ceil_f32(f32) -> f32 {
|
||||
block0(v0: f32):
|
||||
v1 = ceil v0
|
||||
return v1
|
||||
}
|
||||
; run: %ceil_f32(0x0.5) == 0x1.0
|
||||
; run: %ceil_f32(0x1.0) == 0x1.0
|
||||
; run: %ceil_f32(0x1.5) == 0x1.0p1
|
||||
; run: %ceil_f32(0x2.9) == 0x1.8p1
|
||||
; run: %ceil_f32(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %ceil_f32(-0x0.5) == -0x0.0
|
||||
; run: %ceil_f32(-0x1.0) == -0x1.0
|
||||
; run: %ceil_f32(-0x1.5) == -0x1.0
|
||||
; run: %ceil_f32(-0x2.9) == -0x1.0p1
|
||||
; run: %ceil_f32(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %ceil_f32(0x0.0) == 0x0.0
|
||||
; run: %ceil_f32(-0x0.0) == -0x0.0
|
||||
; run: %ceil_f32(+Inf) == +Inf
|
||||
; run: %ceil_f32(-Inf) == -Inf
|
||||
|
||||
; F32 Epsilon / Max / Min Positive
|
||||
; run: %ceil_f32(0x1.000000p-23) == 0x1.0
|
||||
; run: %ceil_f32(0x1.fffffep127) == 0x1.fffffep127
|
||||
; run: %ceil_f32(0x1.000000p-126) == 0x1.0
|
||||
|
||||
; F32 Subnormals
|
||||
; run: %ceil_f32(0x0.800000p-126) == 0x1.0
|
||||
; run: %ceil_f32(-0x0.800002p-126) == -0x0.0
|
||||
|
||||
; F32 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %ceil_is_nan_f32(f32) -> i32 {
|
||||
block0(v0: f32):
|
||||
v1 = ceil v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %ceil_is_nan_f32(+NaN) == 1
|
||||
; run: %ceil_is_nan_f32(-NaN) == 1
|
||||
; run: %ceil_is_nan_f32(+NaN:0x0) == 1
|
||||
; run: %ceil_is_nan_f32(+NaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f32(+NaN:0x300001) == 1
|
||||
; run: %ceil_is_nan_f32(-NaN:0x0) == 1
|
||||
; run: %ceil_is_nan_f32(-NaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f32(-NaN:0x300001) == 1
|
||||
; run: %ceil_is_nan_f32(+sNaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f32(-sNaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f32(+sNaN:0x200001) == 1
|
||||
; run: %ceil_is_nan_f32(-sNaN:0x200001) == 1
|
||||
|
||||
|
||||
|
||||
function %ceil_f64(f64) -> f64 {
|
||||
block0(v0: f64):
|
||||
v1 = ceil v0
|
||||
return v1
|
||||
}
|
||||
; run: %ceil_f64(0x0.5) == 0x1.0
|
||||
; run: %ceil_f64(0x1.0) == 0x1.0
|
||||
; run: %ceil_f64(0x1.5) == 0x1.0p1
|
||||
; run: %ceil_f64(0x2.9) == 0x1.8p1
|
||||
; run: %ceil_f64(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %ceil_f64(-0x0.5) == -0x0.0
|
||||
; run: %ceil_f64(-0x1.0) == -0x1.0
|
||||
; run: %ceil_f64(-0x1.5) == -0x1.0
|
||||
; run: %ceil_f64(-0x2.9) == -0x1.0p1
|
||||
; run: %ceil_f64(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %ceil_f64(0x0.0) == 0x0.0
|
||||
; run: %ceil_f64(-0x0.0) == -0x0.0
|
||||
; run: %ceil_f64(+Inf) == +Inf
|
||||
; run: %ceil_f64(-Inf) == -Inf
|
||||
|
||||
; F64 Epsilon / Max / Min Positive
|
||||
; run: %ceil_f64(0x1.0000000000000p-52) == 0x1.0
|
||||
; run: %ceil_f64(0x1.fffffffffffffp1023) == 0x1.fffffffffffffp1023
|
||||
; run: %ceil_f64(0x1.0000000000000p-1022) == 0x1.0
|
||||
|
||||
; F64 Subnormals
|
||||
; run: %ceil_f64(0x0.8000000000000p-1022) == 0x1.0
|
||||
; run: %ceil_f64(-0x0.8000000000000p-1022) == -0x0.0
|
||||
|
||||
|
||||
|
||||
; F64 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %ceil_is_nan_f64(f64) -> i32 {
|
||||
block0(v0: f64):
|
||||
v1 = ceil v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %ceil_is_nan_f64(+NaN) == 1
|
||||
; run: %ceil_is_nan_f64(-NaN) == 1
|
||||
; run: %ceil_is_nan_f64(+NaN:0x0) == 1
|
||||
; run: %ceil_is_nan_f64(+NaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f64(+NaN:0x4000000000001) == 1
|
||||
; run: %ceil_is_nan_f64(-NaN:0x0) == 1
|
||||
; run: %ceil_is_nan_f64(-NaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f64(-NaN:0x4000000000001) == 1
|
||||
; run: %ceil_is_nan_f64(+sNaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f64(-sNaN:0x1) == 1
|
||||
; run: %ceil_is_nan_f64(+sNaN:0x4000000000001) == 1
|
||||
; run: %ceil_is_nan_f64(-sNaN:0x4000000000001) == 1
|
||||
119
cranelift/filetests/filetests/runtests/floor.clif
Normal file
119
cranelift/filetests/filetests/runtests/floor.clif
Normal file
@@ -0,0 +1,119 @@
|
||||
test interpret
|
||||
test run
|
||||
target x86_64
|
||||
target aarch64
|
||||
target s390x
|
||||
|
||||
function %floor_f32(f32) -> f32 {
|
||||
block0(v0: f32):
|
||||
v1 = floor v0
|
||||
return v1
|
||||
}
|
||||
; run: %floor_f32(0x0.5) == 0x0.0
|
||||
; run: %floor_f32(0x1.0) == 0x1.0
|
||||
; run: %floor_f32(0x1.5) == 0x1.0
|
||||
; run: %floor_f32(0x2.9) == 0x1.0p1
|
||||
; run: %floor_f32(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %floor_f32(-0x0.5) == -0x1.0
|
||||
; run: %floor_f32(-0x1.0) == -0x1.0
|
||||
; run: %floor_f32(-0x1.5) == -0x1.0p1
|
||||
; run: %floor_f32(-0x2.9) == -0x1.8p1
|
||||
; run: %floor_f32(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %floor_f32(0x0.0) == 0x0.0
|
||||
; run: %floor_f32(-0x0.0) == -0x0.0
|
||||
; run: %floor_f32(+Inf) == +Inf
|
||||
; run: %floor_f32(-Inf) == -Inf
|
||||
|
||||
; F32 Epsilon / Max / Min Positive
|
||||
; run: %floor_f32(0x1.000000p-23) == 0x0.0
|
||||
; run: %floor_f32(0x1.fffffep127) == 0x1.fffffep127
|
||||
; run: %floor_f32(0x1.000000p-126) == 0x0.0
|
||||
|
||||
; F32 Subnormals
|
||||
; run: %floor_f32(0x0.800000p-126) == 0x0.0
|
||||
; run: %floor_f32(-0x0.800002p-126) == -0x1.0
|
||||
|
||||
; F32 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %floor_is_nan_f32(f32) -> i32 {
|
||||
block0(v0: f32):
|
||||
v1 = floor v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %floor_is_nan_f32(+NaN) == 1
|
||||
; run: %floor_is_nan_f32(-NaN) == 1
|
||||
; run: %floor_is_nan_f32(+NaN:0x0) == 1
|
||||
; run: %floor_is_nan_f32(+NaN:0x1) == 1
|
||||
; run: %floor_is_nan_f32(+NaN:0x300001) == 1
|
||||
; run: %floor_is_nan_f32(-NaN:0x0) == 1
|
||||
; run: %floor_is_nan_f32(-NaN:0x1) == 1
|
||||
; run: %floor_is_nan_f32(-NaN:0x300001) == 1
|
||||
; run: %floor_is_nan_f32(+sNaN:0x1) == 1
|
||||
; run: %floor_is_nan_f32(-sNaN:0x1) == 1
|
||||
; run: %floor_is_nan_f32(+sNaN:0x200001) == 1
|
||||
; run: %floor_is_nan_f32(-sNaN:0x200001) == 1
|
||||
|
||||
|
||||
|
||||
function %floor_f64(f64) -> f64 {
|
||||
block0(v0: f64):
|
||||
v1 = floor v0
|
||||
return v1
|
||||
}
|
||||
; run: %floor_f64(0x0.5) == 0x0.0
|
||||
; run: %floor_f64(0x1.0) == 0x1.0
|
||||
; run: %floor_f64(0x1.5) == 0x1.0
|
||||
; run: %floor_f64(0x2.9) == 0x1.0p1
|
||||
; run: %floor_f64(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %floor_f64(-0x0.5) == -0x1.0
|
||||
; run: %floor_f64(-0x1.0) == -0x1.0
|
||||
; run: %floor_f64(-0x1.5) == -0x1.0p1
|
||||
; run: %floor_f64(-0x2.9) == -0x1.8p1
|
||||
; run: %floor_f64(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %floor_f64(0x0.0) == 0x0.0
|
||||
; run: %floor_f64(-0x0.0) == -0x0.0
|
||||
; run: %floor_f64(+Inf) == +Inf
|
||||
; run: %floor_f64(-Inf) == -Inf
|
||||
|
||||
; F64 Epsilon / Max / Min Positive
|
||||
; run: %floor_f64(0x1.0000000000000p-52) == 0x0.0
|
||||
; run: %floor_f64(0x1.fffffffffffffp1023) == 0x1.fffffffffffffp1023
|
||||
; run: %floor_f64(0x1.0000000000000p-1022) == 0x0.0
|
||||
|
||||
; F64 Subnormals
|
||||
; run: %floor_f64(0x0.8000000000000p-1022) == 0x0.0
|
||||
; run: %floor_f64(-0x0.8000000000000p-1022) == -0x1.0
|
||||
|
||||
|
||||
|
||||
; F64 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %floor_is_nan_f64(f64) -> i32 {
|
||||
block0(v0: f64):
|
||||
v1 = floor v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %floor_is_nan_f64(+NaN) == 1
|
||||
; run: %floor_is_nan_f64(-NaN) == 1
|
||||
; run: %floor_is_nan_f64(+NaN:0x0) == 1
|
||||
; run: %floor_is_nan_f64(+NaN:0x1) == 1
|
||||
; run: %floor_is_nan_f64(+NaN:0x4000000000001) == 1
|
||||
; run: %floor_is_nan_f64(-NaN:0x0) == 1
|
||||
; run: %floor_is_nan_f64(-NaN:0x1) == 1
|
||||
; run: %floor_is_nan_f64(-NaN:0x4000000000001) == 1
|
||||
; run: %floor_is_nan_f64(+sNaN:0x1) == 1
|
||||
; run: %floor_is_nan_f64(-sNaN:0x1) == 1
|
||||
; run: %floor_is_nan_f64(+sNaN:0x4000000000001) == 1
|
||||
; run: %floor_is_nan_f64(-sNaN:0x4000000000001) == 1
|
||||
119
cranelift/filetests/filetests/runtests/nearest.clif
Normal file
119
cranelift/filetests/filetests/runtests/nearest.clif
Normal file
@@ -0,0 +1,119 @@
|
||||
test interpret
|
||||
test run
|
||||
target x86_64
|
||||
target aarch64
|
||||
target s390x
|
||||
|
||||
function %nearest_f32(f32) -> f32 {
|
||||
block0(v0: f32):
|
||||
v1 = nearest v0
|
||||
return v1
|
||||
}
|
||||
; run: %nearest_f32(0x0.5) == 0x0.0
|
||||
; run: %nearest_f32(0x1.0) == 0x1.0
|
||||
; run: %nearest_f32(0x1.5) == 0x1.0
|
||||
; run: %nearest_f32(0x2.9) == 0x1.8p1
|
||||
; run: %nearest_f32(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %nearest_f32(-0x0.5) == -0x0.0
|
||||
; run: %nearest_f32(-0x1.0) == -0x1.0
|
||||
; run: %nearest_f32(-0x1.5) == -0x1.0
|
||||
; run: %nearest_f32(-0x2.9) == -0x1.8p1
|
||||
; run: %nearest_f32(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %nearest_f32(0x0.0) == 0x0.0
|
||||
; run: %nearest_f32(-0x0.0) == -0x0.0
|
||||
; run: %nearest_f32(+Inf) == +Inf
|
||||
; run: %nearest_f32(-Inf) == -Inf
|
||||
|
||||
; F32 Epsilon / Max / Min Positive
|
||||
; run: %nearest_f32(0x1.000000p-23) == 0x0.0
|
||||
; run: %nearest_f32(0x1.fffffep127) == 0x1.fffffep127
|
||||
; run: %nearest_f32(0x1.000000p-126) == 0x0.0
|
||||
|
||||
; F32 Subnormals
|
||||
; run: %nearest_f32(0x0.800000p-126) == 0x0.0
|
||||
; run: %nearest_f32(-0x0.800002p-126) == -0x0.0
|
||||
|
||||
; F32 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %near_is_nan_f32(f32) -> i32 {
|
||||
block0(v0: f32):
|
||||
v1 = nearest v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %near_is_nan_f32(+NaN) == 1
|
||||
; run: %near_is_nan_f32(-NaN) == 1
|
||||
; run: %near_is_nan_f32(+NaN:0x0) == 1
|
||||
; run: %near_is_nan_f32(+NaN:0x1) == 1
|
||||
; run: %near_is_nan_f32(+NaN:0x300001) == 1
|
||||
; run: %near_is_nan_f32(-NaN:0x0) == 1
|
||||
; run: %near_is_nan_f32(-NaN:0x1) == 1
|
||||
; run: %near_is_nan_f32(-NaN:0x300001) == 1
|
||||
; run: %near_is_nan_f32(+sNaN:0x1) == 1
|
||||
; run: %near_is_nan_f32(-sNaN:0x1) == 1
|
||||
; run: %near_is_nan_f32(+sNaN:0x200001) == 1
|
||||
; run: %near_is_nan_f32(-sNaN:0x200001) == 1
|
||||
|
||||
|
||||
|
||||
function %nearest_f64(f64) -> f64 {
|
||||
block0(v0: f64):
|
||||
v1 = nearest v0
|
||||
return v1
|
||||
}
|
||||
; run: %nearest_f64(0x0.5) == 0x0.0
|
||||
; run: %nearest_f64(0x1.0) == 0x1.0
|
||||
; run: %nearest_f64(0x1.5) == 0x1.0
|
||||
; run: %nearest_f64(0x2.9) == 0x1.8p1
|
||||
; run: %nearest_f64(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %nearest_f64(-0x0.5) == -0x0.0
|
||||
; run: %nearest_f64(-0x1.0) == -0x1.0
|
||||
; run: %nearest_f64(-0x1.5) == -0x1.0
|
||||
; run: %nearest_f64(-0x2.9) == -0x1.8p1
|
||||
; run: %nearest_f64(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %nearest_f64(0x0.0) == 0x0.0
|
||||
; run: %nearest_f64(-0x0.0) == -0x0.0
|
||||
; run: %nearest_f64(+Inf) == +Inf
|
||||
; run: %nearest_f64(-Inf) == -Inf
|
||||
|
||||
; F64 Epsilon / Max / Min Positive
|
||||
; run: %nearest_f64(0x1.0000000000000p-52) == 0x0.0
|
||||
; run: %nearest_f64(0x1.fffffffffffffp1023) == 0x1.fffffffffffffp1023
|
||||
; run: %nearest_f64(0x1.0000000000000p-1022) == 0x0.0
|
||||
|
||||
; F64 Subnormals
|
||||
; run: %nearest_f64(0x0.8000000000000p-1022) == 0x0.0
|
||||
; run: %nearest_f64(-0x0.8000000000000p-1022) == -0x0.0
|
||||
|
||||
|
||||
|
||||
; F64 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %near_is_nan_f64(f64) -> i32 {
|
||||
block0(v0: f64):
|
||||
v1 = nearest v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %near_is_nan_f64(+NaN) == 1
|
||||
; run: %near_is_nan_f64(-NaN) == 1
|
||||
; run: %near_is_nan_f64(+NaN:0x0) == 1
|
||||
; run: %near_is_nan_f64(+NaN:0x1) == 1
|
||||
; run: %near_is_nan_f64(+NaN:0x4000000000001) == 1
|
||||
; run: %near_is_nan_f64(-NaN:0x0) == 1
|
||||
; run: %near_is_nan_f64(-NaN:0x1) == 1
|
||||
; run: %near_is_nan_f64(-NaN:0x4000000000001) == 1
|
||||
; run: %near_is_nan_f64(+sNaN:0x1) == 1
|
||||
; run: %near_is_nan_f64(-sNaN:0x1) == 1
|
||||
; run: %near_is_nan_f64(+sNaN:0x4000000000001) == 1
|
||||
; run: %near_is_nan_f64(-sNaN:0x4000000000001) == 1
|
||||
119
cranelift/filetests/filetests/runtests/trunc.clif
Normal file
119
cranelift/filetests/filetests/runtests/trunc.clif
Normal file
@@ -0,0 +1,119 @@
|
||||
test interpret
|
||||
test run
|
||||
target x86_64
|
||||
target aarch64
|
||||
target s390x
|
||||
|
||||
function %trunc_f32(f32) -> f32 {
|
||||
block0(v0: f32):
|
||||
v1 = trunc v0
|
||||
return v1
|
||||
}
|
||||
; run: %trunc_f32(0x0.5) == 0x0.0
|
||||
; run: %trunc_f32(0x1.0) == 0x1.0
|
||||
; run: %trunc_f32(0x1.5) == 0x1.0
|
||||
; run: %trunc_f32(0x2.9) == 0x1.0p1
|
||||
; run: %trunc_f32(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %trunc_f32(-0x0.5) == -0x0.0
|
||||
; run: %trunc_f32(-0x1.0) == -0x1.0
|
||||
; run: %trunc_f32(-0x1.5) == -0x1.0
|
||||
; run: %trunc_f32(-0x2.9) == -0x1.0p1
|
||||
; run: %trunc_f32(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %trunc_f32(0x0.0) == 0x0.0
|
||||
; run: %trunc_f32(-0x0.0) == -0x0.0
|
||||
; run: %trunc_f32(+Inf) == +Inf
|
||||
; run: %trunc_f32(-Inf) == -Inf
|
||||
|
||||
; F32 Epsilon / Max / Min Positive
|
||||
; run: %trunc_f32(0x1.000000p-23) == 0x0.0
|
||||
; run: %trunc_f32(0x1.fffffep127) == 0x1.fffffep127
|
||||
; run: %trunc_f32(0x1.000000p-126) == 0x0.0
|
||||
|
||||
; F32 Subnormals
|
||||
; run: %trunc_f32(0x0.800000p-126) == 0x0.0
|
||||
; run: %trunc_f32(-0x0.800002p-126) == -0x0.0
|
||||
|
||||
; F32 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %trunc_is_nan_f32(f32) -> i32 {
|
||||
block0(v0: f32):
|
||||
v1 = trunc v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %trunc_is_nan_f32(+NaN) == 1
|
||||
; run: %trunc_is_nan_f32(-NaN) == 1
|
||||
; run: %trunc_is_nan_f32(+NaN:0x0) == 1
|
||||
; run: %trunc_is_nan_f32(+NaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f32(+NaN:0x300001) == 1
|
||||
; run: %trunc_is_nan_f32(-NaN:0x0) == 1
|
||||
; run: %trunc_is_nan_f32(-NaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f32(-NaN:0x300001) == 1
|
||||
; run: %trunc_is_nan_f32(+sNaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f32(-sNaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f32(+sNaN:0x200001) == 1
|
||||
; run: %trunc_is_nan_f32(-sNaN:0x200001) == 1
|
||||
|
||||
|
||||
|
||||
function %trunc_f64(f64) -> f64 {
|
||||
block0(v0: f64):
|
||||
v1 = trunc v0
|
||||
return v1
|
||||
}
|
||||
; run: %trunc_f64(0x0.5) == 0x0.0
|
||||
; run: %trunc_f64(0x1.0) == 0x1.0
|
||||
; run: %trunc_f64(0x1.5) == 0x1.0
|
||||
; run: %trunc_f64(0x2.9) == 0x1.0p1
|
||||
; run: %trunc_f64(0x1.1p10) == 0x1.1p10
|
||||
|
||||
; Negatives
|
||||
; run: %trunc_f64(-0x0.5) == -0x0.0
|
||||
; run: %trunc_f64(-0x1.0) == -0x1.0
|
||||
; run: %trunc_f64(-0x1.5) == -0x1.0
|
||||
; run: %trunc_f64(-0x2.9) == -0x1.0p1
|
||||
; run: %trunc_f64(-0x1.1p10) == -0x1.1p10
|
||||
|
||||
; Specials
|
||||
; run: %trunc_f64(0x0.0) == 0x0.0
|
||||
; run: %trunc_f64(-0x0.0) == -0x0.0
|
||||
; run: %trunc_f64(+Inf) == +Inf
|
||||
; run: %trunc_f64(-Inf) == -Inf
|
||||
|
||||
; F64 Epsilon / Max / Min Positive
|
||||
; run: %trunc_f64(0x1.0000000000000p-52) == 0x0.0
|
||||
; run: %trunc_f64(0x1.fffffffffffffp1023) == 0x1.fffffffffffffp1023
|
||||
; run: %trunc_f64(0x1.0000000000000p-1022) == 0x0.0
|
||||
|
||||
; F64 Subnormals
|
||||
; run: %trunc_f64(0x0.8000000000000p-1022) == 0x0.0
|
||||
; run: %trunc_f64(-0x0.8000000000000p-1022) == -0x0.0
|
||||
|
||||
|
||||
|
||||
; F64 NaN's
|
||||
; For NaN's this operation is specified as producing a value that is a NaN
|
||||
function %trunc_is_nan_f64(f64) -> i32 {
|
||||
block0(v0: f64):
|
||||
v1 = trunc v0
|
||||
v2 = fcmp ne v1, v1
|
||||
v3 = bint.i32 v2
|
||||
return v3
|
||||
}
|
||||
; run: %trunc_is_nan_f64(+NaN) == 1
|
||||
; run: %trunc_is_nan_f64(-NaN) == 1
|
||||
; run: %trunc_is_nan_f64(+NaN:0x0) == 1
|
||||
; run: %trunc_is_nan_f64(+NaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f64(+NaN:0x4000000000001) == 1
|
||||
; run: %trunc_is_nan_f64(-NaN:0x0) == 1
|
||||
; run: %trunc_is_nan_f64(-NaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f64(-NaN:0x4000000000001) == 1
|
||||
; run: %trunc_is_nan_f64(+sNaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f64(-sNaN:0x1) == 1
|
||||
; run: %trunc_is_nan_f64(+sNaN:0x4000000000001) == 1
|
||||
; run: %trunc_is_nan_f64(-sNaN:0x4000000000001) == 1
|
||||
@@ -728,10 +728,10 @@ where
|
||||
(a, b) if a.is_zero()? && b.is_zero()? => a,
|
||||
(a, b) => a.max(b)?,
|
||||
}),
|
||||
Opcode::Ceil => unimplemented!("Ceil"),
|
||||
Opcode::Floor => unimplemented!("Floor"),
|
||||
Opcode::Trunc => unimplemented!("Trunc"),
|
||||
Opcode::Nearest => unimplemented!("Nearest"),
|
||||
Opcode::Ceil => assign(Value::ceil(arg(0)?)?),
|
||||
Opcode::Floor => assign(Value::floor(arg(0)?)?),
|
||||
Opcode::Trunc => assign(Value::trunc(arg(0)?)?),
|
||||
Opcode::Nearest => assign(Value::nearest(arg(0)?)?),
|
||||
Opcode::IsNull => unimplemented!("IsNull"),
|
||||
Opcode::IsInvalid => unimplemented!("IsInvalid"),
|
||||
Opcode::Trueif => choose(
|
||||
|
||||
@@ -60,6 +60,10 @@ pub trait Value: Clone + From<DataValue> {
|
||||
// Float operations
|
||||
fn neg(self) -> ValueResult<Self>;
|
||||
fn copysign(self, sign: Self) -> ValueResult<Self>;
|
||||
fn ceil(self) -> ValueResult<Self>;
|
||||
fn floor(self) -> ValueResult<Self>;
|
||||
fn trunc(self) -> ValueResult<Self>;
|
||||
fn nearest(self) -> ValueResult<Self>;
|
||||
|
||||
// Saturating arithmetic.
|
||||
fn add_sat(self, other: Self) -> ValueResult<Self>;
|
||||
@@ -517,6 +521,22 @@ impl Value for DataValue {
|
||||
binary_match!(copysign(&self, &sign); [F32, F64])
|
||||
}
|
||||
|
||||
fn ceil(self) -> ValueResult<Self> {
|
||||
unary_match!(ceil(&self); [F32, F64])
|
||||
}
|
||||
|
||||
fn floor(self) -> ValueResult<Self> {
|
||||
unary_match!(floor(&self); [F32, F64])
|
||||
}
|
||||
|
||||
fn trunc(self) -> ValueResult<Self> {
|
||||
unary_match!(trunc(&self); [F32, F64])
|
||||
}
|
||||
|
||||
fn nearest(self) -> ValueResult<Self> {
|
||||
unary_match!(nearest(&self); [F32, F64])
|
||||
}
|
||||
|
||||
fn add_sat(self, other: Self) -> ValueResult<Self> {
|
||||
binary_match!(saturating_add(self, &other); [I8, I16, I32, I64, I128, U8, U16, U32, U64, U128])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user