func_integer.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2010-03-17
  5. // Updated : 2010-03-31
  6. // Licence : This source is under MIT License
  7. // File : glm/core/func_integer.hpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef glm_core_func_integer
  10. #define glm_core_func_integer
  11. namespace glm
  12. {
  13. namespace test{
  14. void main_core_func_integer();
  15. }//namespace test
  16. namespace core{
  17. namespace function{
  18. //! Define integer functions from Section 8.8 of GLSL 4.00.8 specification.
  19. namespace integer{
  20. //! Adds 32-bit unsigned integer x and y, returning the sum
  21. //! modulo pow(2, 32). The value carry is set to 0 if the sum was
  22. //! less than pow(2, 32), or to 1 otherwise.
  23. //!
  24. //! (From GLSL 4.00.08 specification, section 8.8)
  25. template <typename genUType>
  26. genUType uaddCarry(
  27. genUType const & x,
  28. genUType const & y,
  29. genUType & carry);
  30. //! Subtracts the 32-bit unsigned integer y from x, returning
  31. //! the difference if non-negative, or pow(2, 32) plus the difference
  32. //! otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise.
  33. //!
  34. //! (From GLSL 4.00.08 specification, section 8.8)
  35. template <typename genUType>
  36. genUType usubBorrow(
  37. genUType const & x,
  38. genUType const & y,
  39. genUType & borrow);
  40. //! Multiplies 32-bit integers x and y, producing a 64-bit
  41. //! result. The 32 least-significant bits are returned in lsb.
  42. //! The 32 most-significant bits are returned in msb.
  43. //! (From GLSL 4.00.08 specification, section 8.8)
  44. template <typename genUType>
  45. void umulExtended(
  46. genUType const & x,
  47. genUType const & y,
  48. genUType & msb,
  49. genUType & lsb);
  50. //! Multiplies 32-bit integers x and y, producing a 64-bit
  51. //! result. The 32 least-significant bits are returned in lsb.
  52. //! The 32 most-significant bits are returned in msb.
  53. //! (From GLSL 4.00.08 specification, section 8.8)
  54. template <typename genIType>
  55. void imulExtended(
  56. genIType const & x,
  57. genIType const & y,
  58. genIType & msb,
  59. genIType & lsb);
  60. //! Extracts bits [offset, offset + bits - 1] from value,
  61. //! returning them in the least significant bits of the result.
  62. //! For unsigned data types, the most significant bits of the
  63. //! result will be set to zero. For signed data types, the
  64. //! most significant bits will be set to the value of bit offset + base – 1.
  65. //!
  66. //! If bits is zero, the result will be zero. The result will be
  67. //! undefined if offset or bits is negative, or if the sum of
  68. //! offset and bits is greater than the number of bits used
  69. //! to store the operand.
  70. //!
  71. //! (From GLSL 4.00.08 specification, section 8.8)
  72. template <typename genIUType>
  73. genIUType bitfieldExtract(
  74. genIUType const & Value,
  75. int const & Offset,
  76. int const & Bits);
  77. //! Returns the insertion the bits least-significant bits of insert into base.
  78. //!
  79. //! The result will have bits [offset, offset + bits - 1] taken
  80. //! from bits [0, bits – 1] of insert, and all other bits taken
  81. //! directly from the corresponding bits of base. If bits is
  82. //! zero, the result will simply be base. The result will be
  83. //! undefined if offset or bits is negative, or if the sum of
  84. //! offset and bits is greater than the number of bits used to
  85. //! store the operand.
  86. //!
  87. //! (From GLSL 4.00.08 specification, section 8.8)
  88. template <typename genIUType>
  89. genIUType bitfieldInsert(
  90. genIUType const & Base,
  91. genIUType const & Insert,
  92. int const & Offset,
  93. int const & Bits);
  94. //! Returns the reversal of the bits of value.
  95. //! The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
  96. //! where bits is the total number of bits used to represent value.
  97. //! (From GLSL 4.00.08 specification, section 8.8)
  98. template <typename genIUType>
  99. genIUType bitfieldReverse(genIUType const & value);
  100. //! Returns the number of bits set to 1 in the binary representation of value.
  101. //! (From GLSL 4.00.08 specification, section 8.8)
  102. template <typename T, template <typename> class C>
  103. typename C<T>::signed_type bitCount(C<T> const & Value);
  104. //! Returns the bit number of the least significant bit set to
  105. //! 1 in the binary representation of value.
  106. //! If value is zero, -1 will be returned.
  107. //! (From GLSL 4.00.08 specification, section 8.8)
  108. template <typename T, template <typename> class C>
  109. typename C<T>::signed_type findLSB(C<T> const & Value);
  110. //! Returns the bit number of the most significant bit in the binary representation of value.
  111. //! For positive integers, the result will be the bit number of the most significant bit set to 1.
  112. //! For negative integers, the result will be the bit number of the most significant
  113. //! bit set to 0. For a value of zero or negative one, -1 will be returned.
  114. //! (From GLSL 4.00.08 specification, section 8.8)
  115. template <typename T, template <typename> class C>
  116. typename C<T>::signed_type findMSB(C<T> const & Value);
  117. }//namespace integer
  118. }//namespace function
  119. }//namespace core
  120. using namespace core::function::integer;
  121. }//namespace glm
  122. #include "func_integer.inl"
  123. #endif//glm_core_func_integer