func_integer.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 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. /// @addtogroup core_funcs
  14. /// @{
  15. //! Adds 32-bit unsigned integer x and y, returning the sum
  16. //! modulo pow(2, 32). The value carry is set to 0 if the sum was
  17. //! less than pow(2, 32), or to 1 otherwise.
  18. //!
  19. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uaddCarry.xml">GLSL uaddCarry man page</a>
  20. //! \li GLSL 4.00.08 specification, section 8.8
  21. template <typename genUType>
  22. genUType uaddCarry(
  23. genUType const & x,
  24. genUType const & y,
  25. genUType & carry);
  26. //! Subtracts the 32-bit unsigned integer y from x, returning
  27. //! the difference if non-negative, or pow(2, 32) plus the difference
  28. //! otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise.
  29. //!
  30. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a>
  31. //! \li GLSL 4.00.08 specification, section 8.8
  32. template <typename genUType>
  33. genUType usubBorrow(
  34. genUType const & x,
  35. genUType const & y,
  36. genUType & borrow);
  37. //! Multiplies 32-bit integers x and y, producing a 64-bit
  38. //! result. The 32 least-significant bits are returned in lsb.
  39. //! The 32 most-significant bits are returned in msb.
  40. //!
  41. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a>
  42. //! \li GLSL 4.00.08 specification, section 8.8
  43. template <typename genUType>
  44. void umulExtended(
  45. genUType const & x,
  46. genUType const & y,
  47. genUType & msb,
  48. genUType & lsb);
  49. //! Multiplies 32-bit integers x and y, producing a 64-bit
  50. //! result. The 32 least-significant bits are returned in lsb.
  51. //! The 32 most-significant bits are returned in msb.
  52. //!
  53. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/imulExtended.xml">GLSL imulExtended man page</a>
  54. //! \li GLSL 4.00.08 specification, section 8.8
  55. template <typename genIType>
  56. void imulExtended(
  57. genIType const & x,
  58. genIType const & y,
  59. genIType & msb,
  60. genIType & lsb);
  61. //! Extracts bits [offset, offset + bits - 1] from value,
  62. //! returning them in the least significant bits of the result.
  63. //! For unsigned data types, the most significant bits of the
  64. //! result will be set to zero. For signed data types, the
  65. //! most significant bits will be set to the value of bit offset + base – 1.
  66. //!
  67. //! If bits is zero, the result will be zero. The result will be
  68. //! undefined if offset or bits is negative, or if the sum of
  69. //! offset and bits is greater than the number of bits used
  70. //! to store the operand.
  71. //!
  72. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
  73. //! \li GLSL 4.00.08 specification, section 8.8
  74. template <typename genIUType>
  75. genIUType bitfieldExtract(
  76. genIUType const & Value,
  77. int const & Offset,
  78. int const & Bits);
  79. //! Returns the insertion the bits least-significant bits of insert into base.
  80. //!
  81. //! The result will have bits [offset, offset + bits - 1] taken
  82. //! from bits [0, bits – 1] of insert, and all other bits taken
  83. //! directly from the corresponding bits of base. If bits is
  84. //! zero, the result will simply be base. The result will be
  85. //! undefined if offset or bits is negative, or if the sum of
  86. //! offset and bits is greater than the number of bits used to
  87. //! store the operand.
  88. //!
  89. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a>
  90. //! \li GLSL 4.00.08 specification, section 8.8
  91. template <typename genIUType>
  92. genIUType bitfieldInsert(
  93. genIUType const & Base,
  94. genIUType const & Insert,
  95. int const & Offset,
  96. int const & Bits);
  97. //! Returns the reversal of the bits of value.
  98. //! The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
  99. //! where bits is the total number of bits used to represent value.
  100. //!
  101. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
  102. //! \li GLSL 4.00.08 specification, section 8.8
  103. template <typename genIUType>
  104. genIUType bitfieldReverse(genIUType const & value);
  105. //! Returns the number of bits set to 1 in the binary representation of value.
  106. //!
  107. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
  108. //! \li GLSL 4.00.08 specification, section 8.8
  109. template <typename T, template <typename> class C>
  110. typename C<T>::signed_type bitCount(C<T> const & Value);
  111. //! Returns the bit number of the least significant bit set to
  112. //! 1 in the binary representation of value.
  113. //! If value is zero, -1 will be returned.
  114. //!
  115. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
  116. //! \li GLSL 4.00.08 specification, section 8.8
  117. template <typename T, template <typename> class C>
  118. typename C<T>::signed_type findLSB(C<T> const & Value);
  119. //! Returns the bit number of the most significant bit in the binary representation of value.
  120. //! For positive integers, the result will be the bit number of the most significant bit set to 1.
  121. //! For negative integers, the result will be the bit number of the most significant
  122. //! bit set to 0. For a value of zero or negative one, -1 will be returned.
  123. //!
  124. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
  125. //! \li GLSL 4.00.08 specification, section 8.8
  126. template <typename T, template <typename> class C>
  127. typename C<T>::signed_type findMSB(C<T> const & Value);
  128. /// @}
  129. }//namespace glm
  130. #include "func_integer.inl"
  131. #endif//glm_core_func_integer