func_integer.hpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/func_integer.hpp
  25. /// @date 2010-03-17 / 2011-06-18
  26. /// @author Christophe Riccio
  27. ///
  28. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  29. ///
  30. /// @defgroup core_func_integer Integer functions
  31. /// @ingroup core
  32. ///
  33. /// These all operate component-wise. The description is per component.
  34. /// The notation [a, b] means the set of bits from bit-number a through bit-number
  35. /// b, inclusive. The lowest-order bit is bit 0.
  36. ///////////////////////////////////////////////////////////////////////////////////
  37. #ifndef glm_core_func_integer
  38. #define glm_core_func_integer GLM_VERSION
  39. #include "setup.hpp"
  40. namespace glm
  41. {
  42. /// @addtogroup core_func_integer
  43. /// @{
  44. /// Adds 32-bit unsigned integer x and y, returning the sum
  45. /// modulo pow(2, 32). The value carry is set to 0 if the sum was
  46. /// less than pow(2, 32), or to 1 otherwise.
  47. ///
  48. /// @tparam genUType Unsigned integer scalar or vector types.
  49. ///
  50. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uaddCarry.xml">GLSL uaddCarry man page</a>
  51. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  52. template <typename genUType>
  53. GLM_FUNC_DECL genUType uaddCarry(
  54. genUType const & x,
  55. genUType const & y,
  56. genUType & carry);
  57. /// Subtracts the 32-bit unsigned integer y from x, returning
  58. /// the difference if non-negative, or pow(2, 32) plus the difference
  59. /// otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise.
  60. ///
  61. /// @tparam genUType Unsigned integer scalar or vector types.
  62. ///
  63. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a>
  64. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  65. template <typename genUType>
  66. GLM_FUNC_DECL genUType usubBorrow(
  67. genUType const & x,
  68. genUType const & y,
  69. genUType & borrow);
  70. /// Multiplies 32-bit integers x and y, producing a 64-bit
  71. /// result. The 32 least-significant bits are returned in lsb.
  72. /// The 32 most-significant bits are returned in msb.
  73. ///
  74. /// @tparam genUType Unsigned integer scalar or vector types.
  75. ///
  76. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a>
  77. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  78. template <typename genUType>
  79. GLM_FUNC_DECL void umulExtended(
  80. genUType const & x,
  81. genUType const & y,
  82. genUType & msb,
  83. genUType & lsb);
  84. /// Multiplies 32-bit integers x and y, producing a 64-bit
  85. /// result. The 32 least-significant bits are returned in lsb.
  86. /// The 32 most-significant bits are returned in msb.
  87. ///
  88. /// @tparam genIType Signed integer scalar or vector types.
  89. ///
  90. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/imulExtended.xml">GLSL imulExtended man page</a>
  91. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  92. template <typename genIType>
  93. GLM_FUNC_DECL void imulExtended(
  94. genIType const & x,
  95. genIType const & y,
  96. genIType & msb,
  97. genIType & lsb);
  98. /// Extracts bits [offset, offset + bits - 1] from value,
  99. /// returning them in the least significant bits of the result.
  100. /// For unsigned data types, the most significant bits of the
  101. /// result will be set to zero. For signed data types, the
  102. /// most significant bits will be set to the value of bit offset + base - 1.
  103. ///
  104. /// If bits is zero, the result will be zero. The result will be
  105. /// undefined if offset or bits is negative, or if the sum of
  106. /// offset and bits is greater than the number of bits used
  107. /// to store the operand.
  108. ///
  109. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  110. ///
  111. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
  112. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  113. template <typename genIUType>
  114. GLM_FUNC_DECL genIUType bitfieldExtract(
  115. genIUType const & Value,
  116. int const & Offset,
  117. int const & Bits);
  118. /// Returns the insertion the bits least-significant bits of insert into base.
  119. ///
  120. /// The result will have bits [offset, offset + bits - 1] taken
  121. /// from bits [0, bits - 1] of insert, and all other bits taken
  122. /// directly from the corresponding bits of base. If bits is
  123. /// zero, the result will simply be base. The result will be
  124. /// undefined if offset or bits is negative, or if the sum of
  125. /// offset and bits is greater than the number of bits used to
  126. /// store the operand.
  127. ///
  128. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  129. ///
  130. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a>
  131. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  132. template <typename genIUType>
  133. GLM_FUNC_DECL genIUType bitfieldInsert(
  134. genIUType const & Base,
  135. genIUType const & Insert,
  136. int const & Offset,
  137. int const & Bits);
  138. /// Returns the reversal of the bits of value.
  139. /// The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
  140. /// where bits is the total number of bits used to represent value.
  141. ///
  142. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  143. ///
  144. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
  145. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  146. template <typename genIUType>
  147. GLM_FUNC_DECL genIUType bitfieldReverse(genIUType const & Value);
  148. /// Returns the number of bits set to 1 in the binary representation of value.
  149. ///
  150. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  151. ///
  152. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
  153. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  154. ///
  155. /// @todo Clarify the declaration to specify that scalars are suported.
  156. template <typename T, template <typename> class genIUType>
  157. GLM_FUNC_DECL typename genIUType<T>::signed_type bitCount(genIUType<T> const & Value);
  158. /// Returns the bit number of the least significant bit set to
  159. /// 1 in the binary representation of value.
  160. /// If value is zero, -1 will be returned.
  161. ///
  162. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  163. ///
  164. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
  165. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  166. ///
  167. /// @todo Clarify the declaration to specify that scalars are suported.
  168. template <typename T, template <typename> class genIUType>
  169. GLM_FUNC_DECL typename genIUType<T>::signed_type findLSB(genIUType<T> const & Value);
  170. /// Returns the bit number of the most significant bit in the binary representation of value.
  171. /// For positive integers, the result will be the bit number of the most significant bit set to 1.
  172. /// For negative integers, the result will be the bit number of the most significant
  173. /// bit set to 0. For a value of zero or negative one, -1 will be returned.
  174. ///
  175. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  176. ///
  177. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
  178. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
  179. ///
  180. /// @todo Clarify the declaration to specify that scalars are suported.
  181. template <typename T, template <typename> class genIUType>
  182. GLM_FUNC_DECL typename genIUType<T>::signed_type findMSB(genIUType<T> const & Value);
  183. /// @}
  184. }//namespace glm
  185. #include "func_integer.inl"
  186. #endif//glm_core_func_integer