]> git.nega.tv - josh/narcissus/commitdiff
narcissus-maths: Remove custom `round_ties_even`
authorJoshua Simmons <josh@nega.tv>
Fri, 3 May 2024 06:37:54 +0000 (08:37 +0200)
committerJoshua Simmons <josh@nega.tv>
Fri, 3 May 2024 06:37:54 +0000 (08:37 +0200)
Stable from Rust 1.77.0

engine/narcissus-maths/src/lib.rs
engine/narcissus-maths/src/sin_cos_pi.rs
engine/narcissus-maths/src/tan_pi.rs

index e840020185ef999a975ab9f51e4177bc7dd60c5c..7fd0ef33cd877270439a41af54b1d332b5098b68 100644 (file)
@@ -174,27 +174,6 @@ pub fn clamp(x: f32, lo: f32, hi: f32) -> f32 {
     max(min(x, hi), lo)
 }
 
-/// Returns the nearest integer to a given `f32`.
-///
-/// Respects IEEE-754 tiesToEven
-#[inline(always)]
-fn round_ties_to_even(x: f32) -> f32 {
-    #[cfg(target_feature = "sse4.1")]
-    unsafe {
-        use std::arch::x86_64::{
-            _mm_load_ss, _mm_round_ss, _MM_FROUND_NO_EXC, _MM_FROUND_TO_NEAREST_INT,
-        };
-        const ROUNDING: i32 = _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC;
-        let x = _mm_load_ss(&x);
-        let x = _mm_round_ss::<ROUNDING>(x, x);
-        std::arch::x86_64::_mm_cvtss_f32(x)
-    }
-
-    // Incorrect if the rounding mode is changed.
-    #[cfg(not(target_feature = "sse4.1"))]
-    x.round()
-}
-
 pub fn quantize_centered(x: f32, n: u32) -> u32 {
     (x * ((n - 1) as f32) + 0.5) as u32
 }
index 420cca31cf7e33984cce2ad847d5ff5066f7ba86..d46e21d2641a978f5c02ae66f64369c3940e33d1 100644 (file)
@@ -2,8 +2,6 @@
 //
 // Sollya code for generating these polynomials is in `doc/sincostan.sollya`
 
-use crate::round_ties_to_even;
-
 // constants for sin(pi x), cos(pi x) for x on [-1/4,1/4]
 const F32_SIN_PI_7_K: [f32; 3] = unsafe {
     std::mem::transmute::<[u32; 3], _>([
@@ -51,7 +49,7 @@ pub fn sin_cos_pi_f32(a: f32) -> (f32, f32) {
     let a = if a.abs() < 16777216.0 { a } else { a * 0.0 };
 
     // Range reduction.
-    let r = round_ties_to_even(a + a);
+    let r = (a + a).round_ties_even();
 
     // SAFETY: The clamp above avoids the possibility of overflow here.
     let i = unsafe { r.to_int_unchecked::<i32>() } as u32;
index 22d68d7268a25d7a9e7a37e8a1ee3ae01b999349..7a6f852cd6bb3b43544e322a3eccc0f97250ec6c 100644 (file)
@@ -4,8 +4,6 @@
 //
 // Sollya code for generating these polynomials is in `doc/sincostan.sollya`
 
-use crate::round_ties_to_even;
-
 const F32_TAN_PI_15_K: [f32; 7] = unsafe {
     std::mem::transmute::<[u32; 7], _>([
         0x41255def, // 0x1.4abbdep3
@@ -34,7 +32,7 @@ pub fn tan_pi_f32(a: f32) -> f32 {
     const T: [f32; 7] = F32_TAN_PI_15_K;
 
     // Range reduction.
-    let r = round_ties_to_even(a + a);
+    let r = (a + a).round_ties_even();
 
     // SAFETY: The clamp above avoids the possibility of overflow here.
     let i = unsafe { r.to_int_unchecked::<i32>() } as u32;