Преглед изворни кода

Implement tests for floattidf and floattisf

est31 пре 8 година
родитељ
комит
f9b5297ccc
3 измењених фајлова са 151 додато и 1 уклоњено
  1. 135 1
      build.rs
  2. 8 0
      tests/floattidf.rs
  3. 8 0
      tests/floattisf.rs

+ 135 - 1
build.rs

@@ -49,7 +49,7 @@ mod tests {
     use std::path::PathBuf;
     use std::{env, mem};
 
-    use self::cast::{f32, f64, u32, u64, i32, i64};
+    use self::cast::{f32, f64, u32, u64, u128, i32, i64, i128};
     use self::rand::Rng;
 
     const NTESTS: usize = 10_000;
@@ -81,6 +81,8 @@ mod tests {
             Floatdidf,
             Floatsidf,
             Floatsisf,
+            Floattisf,
+            Floattidf,
             Floatundidf,
             Floatunsidf,
             Floatunsisf,
@@ -1536,6 +1538,138 @@ fn floatsisf() {
         }
     }
 
+    #[derive(Eq, Hash, PartialEq)]
+    pub struct Floattisf {
+        a: i128,
+        b: u32, // f32
+    }
+
+    impl TestCase for Floattisf {
+        fn name() -> &'static str {
+            "floattisf"
+        }
+
+        fn generate<R>(rng: &mut R) -> Option<Self>
+        where
+            R: Rng,
+            Self: Sized,
+        {
+            let a = gen_i128(rng);
+            Some(
+                Floattisf {
+                    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::__floattisf;
+
+fn to_u32(x: f32) -> u32 {
+    unsafe { mem::transmute(x) }
+}
+
+static TEST_CASES: &[((i128,), u32)] = &[
+"#
+        }
+
+        fn epilogue() -> &'static str {
+            "
+];
+
+#[test]
+fn floattisf() {
+    for &((a,), b) in TEST_CASES {
+        let b_ = __floattisf(a);
+        assert_eq!(((a,), b), ((a,), to_u32(b_)));
+    }
+}
+"
+        }
+    }
+
+    #[derive(Eq, Hash, PartialEq)]
+    pub struct Floattidf {
+        a: i128,
+        b: u64, // f64
+    }
+
+    impl TestCase for Floattidf {
+        fn name() -> &'static str {
+            "floattidf"
+        }
+
+        fn generate<R>(rng: &mut R) -> Option<Self>
+        where
+            R: Rng,
+            Self: Sized,
+        {
+            let a = gen_i128(rng);
+            Some(
+                Floattidf {
+                    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::__floattidf;
+
+fn to_u64(x: f64) -> u64 {
+    unsafe { mem::transmute(x) }
+}
+
+static TEST_CASES: &[((i128,), u64)] = &[
+"#
+        }
+
+        fn epilogue() -> &'static str {
+            "
+];
+
+#[test]
+fn floattidf() {
+    for &((a,), b) in TEST_CASES {
+        let b_ = __floattidf(a);
+        assert_eq!(((a,), b), ((a,), to_u64(b_)));
+    }
+}
+"
+        }
+    }
+
     #[derive(Eq, Hash, PartialEq)]
     pub struct Floatundidf {
         a: u64,

+ 8 - 0
tests/floattidf.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"), "/floattidf.rs"));

+ 8 - 0
tests/floattisf.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"), "/floattisf.rs"));