integer.inl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /// @ref gtc_integer
  2. namespace glm{
  3. namespace detail
  4. {
  5. template<length_t L, typename T, qualifier Q, bool Aligned>
  6. struct compute_log2<L, T, Q, false, Aligned>
  7. {
  8. GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& v)
  9. {
  10. //Equivalent to return findMSB(vec); but save one function call in ASM with VC
  11. //return findMSB(vec);
  12. return vec<L, T, Q>(detail::compute_findMSB_vec<L, T, Q, sizeof(T) * 8>::call(v));
  13. }
  14. };
  15. # if GLM_HAS_BITSCAN_WINDOWS
  16. template<qualifier Q, bool Aligned>
  17. struct compute_log2<4, int, Q, false, Aligned>
  18. {
  19. GLM_FUNC_QUALIFIER static vec<4, int, Q> call(vec<4, int, Q> const& v)
  20. {
  21. vec<4, int, Q> Result;
  22. _BitScanReverse(reinterpret_cast<unsigned long*>(&Result.x), v.x);
  23. _BitScanReverse(reinterpret_cast<unsigned long*>(&Result.y), v.y);
  24. _BitScanReverse(reinterpret_cast<unsigned long*>(&Result.z), v.z);
  25. _BitScanReverse(reinterpret_cast<unsigned long*>(&Result.w), v.w);
  26. return Result;
  27. }
  28. };
  29. # endif//GLM_HAS_BITSCAN_WINDOWS
  30. }//namespace detail
  31. template<typename genType>
  32. GLM_FUNC_QUALIFIER int iround(genType x)
  33. {
  34. GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'iround' only accept floating-point inputs");
  35. assert(static_cast<genType>(0.0) <= x);
  36. return static_cast<int>(x + static_cast<genType>(0.5));
  37. }
  38. template<length_t L, typename T, qualifier Q>
  39. GLM_FUNC_QUALIFIER vec<L, int, Q> iround(vec<L, T, Q> const& x)
  40. {
  41. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'iround' only accept floating-point inputs");
  42. assert(all(lessThanEqual(vec<L, T, Q>(0), x)));
  43. return vec<L, int, Q>(x + static_cast<T>(0.5));
  44. }
  45. template<typename genType>
  46. GLM_FUNC_QUALIFIER uint uround(genType x)
  47. {
  48. GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'uround' only accept floating-point inputs");
  49. assert(static_cast<genType>(0.0) <= x);
  50. return static_cast<uint>(x + static_cast<genType>(0.5));
  51. }
  52. template<length_t L, typename T, qualifier Q>
  53. GLM_FUNC_QUALIFIER vec<L, uint, Q> uround(vec<L, T, Q> const& x)
  54. {
  55. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'uround' only accept floating-point inputs");
  56. assert(all(lessThanEqual(vec<L, T, Q>(0), x)));
  57. return vec<L, uint, Q>(x + static_cast<T>(0.5));
  58. }
  59. }//namespace glm