Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. // magic number is 2^n
  2. const double FMOD_MAGIC_NUMBER = 4294967296.0;
  3. const double FRAC_MAGIC_NUMBER = 268435456.0;   // 2^28
  4.  
  5. // these fmods won't work with negative numbers.
  6. // if the input is negative, the magic number needs to be negated,
  7. // but this support was omitted for speed.
  8. double fmod64(double f_)
  9. {
  10.     M3Assert(0.0f <= f_ && f_ < FMOD_MAGIC_NUMBER);
  11.     __m128d f = _mm_set_sd(f_);
  12.     __m128d magic = _mm_set_sd(FMOD_MAGIC_NUMBER);
  13.     f = _mm_add_sd(f, magic);
  14.     // Hang on to the exponent, and to everything below 64.
  15.     const M3uint64 mask_ = 0xFFF0000003FFFFFF;
  16.     __m128d mask = _mm_set_sd(reinterpret_cast<const double&>(mask_));
  17.     f = _mm_and_pd(f, mask);
  18.     f = _mm_sub_sd(f, magic);
  19.     _mm_store_sd(&f_, f);
  20.     M3Assert(f.m128d_f64[0] < 64.0f);
  21.     return f_;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement