Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.2KB

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