浏览代码

Implement tests for floatuntidf and floatuntisf

est31 8 年之前
父节点
当前提交
b91c39da73
共有 3 个文件被更改,包括 150 次插入0 次删除
  1. 134 0
      build.rs
  2. 8 0
      tests/floatuntidf.rs
  3. 8 0
      tests/floatuntisf.rs

+ 134 - 0
build.rs

@@ -90,6 +90,8 @@ mod tests {
             Floatundidf,
             Floatunsidf,
             Floatunsisf,
+            Floatuntisf,
+            Floatuntidf,
 
             // float/pow.rs
             Powidf2,
@@ -2116,6 +2118,138 @@ fn floatunsisf() {
         }
     }
 
+    #[derive(Eq, Hash, PartialEq)]
+    pub struct Floatuntisf {
+        a: u128,
+        b: u32, // f32
+    }
+
+    impl TestCase for Floatuntisf {
+        fn name() -> &'static str {
+            "floatuntisf"
+        }
+
+        fn generate<R>(rng: &mut R) -> Option<Self>
+        where
+            R: Rng,
+            Self: Sized,
+        {
+            let a = gen_u128(rng);
+            Some(
+                Floatuntisf {
+                    a,
+                    b: to_u32(f32(a)),
+                },
+            )
+        }
+
+        fn to_string(&self, buffer: &mut String) {
+            writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
+        }
+
+        fn prologue() -> &'static str {
+            r#"
+#[cfg(all(target_arch = "arm",
+          not(any(target_env = "gnu", target_env = "musl")),
+          target_os = "linux",
+          test))]
+use core::mem;
+#[cfg(not(all(target_arch = "arm",
+              not(any(target_env = "gnu", target_env = "musl")),
+              target_os = "linux",
+              test)))]
+use std::mem;
+use compiler_builtins::float::conv::__floatuntisf;
+
+fn to_u32(x: f32) -> u32 {
+    unsafe { mem::transmute(x) }
+}
+
+static TEST_CASES: &[((u128,), u32)] = &[
+"#
+        }
+
+        fn epilogue() -> &'static str {
+            "
+];
+
+#[test]
+fn floatuntisf() {
+    for &((a,), b) in TEST_CASES {
+        let b_ = __floatuntisf(a);
+        assert_eq!(((a,), b), ((a,), to_u32(b_)));
+    }
+}
+"
+        }
+    }
+
+    #[derive(Eq, Hash, PartialEq)]
+    pub struct Floatuntidf {
+        a: u128,
+        b: u64, // f64
+    }
+
+    impl TestCase for Floatuntidf {
+        fn name() -> &'static str {
+            "floatuntidf"
+        }
+
+        fn generate<R>(rng: &mut R) -> Option<Self>
+        where
+            R: Rng,
+            Self: Sized,
+        {
+            let a = gen_u128(rng);
+            Some(
+                Floatuntidf {
+                    a,
+                    b: to_u64(f64(a)),
+                },
+            )
+        }
+
+        fn to_string(&self, buffer: &mut String) {
+            writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
+        }
+
+        fn prologue() -> &'static str {
+            r#"
+#[cfg(all(target_arch = "arm",
+          not(any(target_env = "gnu", target_env = "musl")),
+          target_os = "linux",
+          test))]
+use core::mem;
+#[cfg(not(all(target_arch = "arm",
+              not(any(target_env = "gnu", target_env = "musl")),
+              target_os = "linux",
+              test)))]
+use std::mem;
+use compiler_builtins::float::conv::__floatuntidf;
+
+fn to_u64(x: f64) -> u64 {
+    unsafe { mem::transmute(x) }
+}
+
+static TEST_CASES: &[((u128,), u64)] = &[
+"#
+        }
+
+        fn epilogue() -> &'static str {
+            "
+];
+
+#[test]
+fn floatuntidf() {
+    for &((a,), b) in TEST_CASES {
+        let b_ = __floatuntidf(a);
+        assert_eq!(((a,), b), ((a,), to_u64(b_)));
+    }
+}
+"
+        }
+    }
+
     #[derive(Eq, Hash, PartialEq)]
     pub struct Moddi3 {
         a: i64,

+ 8 - 0
tests/floatuntidf.rs

@@ -0,0 +1,8 @@
+#![feature(compiler_builtins_lib)]
+#![feature(i128_type)]
+#![cfg_attr(all(target_arch = "arm",
+                not(any(target_env = "gnu", target_env = "musl")),
+                target_os = "linux",
+                test), no_std)]
+
+include!(concat!(env!("OUT_DIR"), "/floatuntidf.rs"));

+ 8 - 0
tests/floatuntisf.rs

@@ -0,0 +1,8 @@
+#![feature(compiler_builtins_lib)]
+#![feature(i128_type)]
+#![cfg_attr(all(target_arch = "arm",
+                not(any(target_env = "gnu", target_env = "musl")),
+                target_os = "linux",
+                test), no_std)]
+
+include!(concat!(env!("OUT_DIR"), "/floatuntisf.rs"));