Skip to content

Instantly share code, notes, and snippets.

@mooman219
Last active February 23, 2020 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooman219/8ecab1e3f6e6b1ceea325614723ea9d7 to your computer and use it in GitHub Desktop.
Save mooman219/8ecab1e3f6e6b1ceea325614723ea9d7 to your computer and use it in GitHub Desktop.
fraction(1.1)
f32x4::splat(1.1).fract_first()
#[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