Last active
February 23, 2020 21:57
-
-
Save mooman219/8ecab1e3f6e6b1ceea325614723ea9d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fraction(1.1) | |
f32x4::splat(1.1).fract_first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[inline(always)] | |
pub fn fraction(value: f32) -> f32 { | |
unsafe { | |
let packed = _mm_set1_ps(value); | |
_mm_cvtss_f32(_mm_sub_ps(packed, _mm_cvtepi32_ps(_mm_cvttps_epi32(packed)))) | |
} | |
} | |
#[derive(Copy, Clone)] | |
#[repr(transparent)] | |
pub struct f32x4(__m128); | |
impl f32x4 { | |
#[inline(always)] | |
pub fn splat(value: f32) -> Self { | |
f32x4(unsafe { _mm_set1_ps(value) }) | |
} | |
#[inline(always)] | |
pub fn fract_first(self) -> f32 { | |
unsafe { _mm_cvtss_f32(_mm_sub_ps(self.0, _mm_cvtepi32_ps(_mm_cvttps_epi32(self.0)))) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment