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.

201 lines
9.4 KiB

  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. namespace glm
  40. {
  41. /// @addtogroup core_func_integer
  42. /// @{
  43. /// Adds 32-bit unsigned integer x and y, returning the sum
  44. /// modulo pow(2, 32). The value carry is set to 0 if the sum was
  45. /// less than pow(2, 32), or to 1 otherwise.
  46. ///
  47. /// @tparam genUType Unsigned integer scalar or vector types.
  48. ///
  49. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uaddCarry.xml">GLSL uaddCarry man page</a>
  50. /// @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>
  51. template <typename genUType>
  52. GLM_FUNC_DECL genUType uaddCarry(
  53. genUType const & x,
  54. genUType const & y,
  55. genUType & carry);
  56. /// Subtracts the 32-bit unsigned integer y from x, returning
  57. /// the difference if non-negative, or pow(2, 32) plus the difference
  58. /// otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise.
  59. ///
  60. /// @tparam genUType Unsigned integer scalar or vector types.
  61. ///
  62. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a>
  63. /// @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>
  64. template <typename genUType>
  65. GLM_FUNC_DECL genUType usubBorrow(
  66. genUType const & x,
  67. genUType const & y,
  68. genUType & borrow);
  69. /// Multiplies 32-bit integers x and y, producing a 64-bit
  70. /// result. The 32 least-significant bits are returned in lsb.
  71. /// The 32 most-significant bits are returned in msb.
  72. ///
  73. /// @tparam genUType Unsigned integer scalar or vector types.
  74. ///
  75. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a>
  76. /// @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>
  77. template <typename genUType>
  78. GLM_FUNC_DECL void umulExtended(
  79. genUType const & x,
  80. genUType const & y,
  81. genUType & msb,
  82. genUType & lsb);
  83. /// Multiplies 32-bit integers x and y, producing a 64-bit
  84. /// result. The 32 least-significant bits are returned in lsb.
  85. /// The 32 most-significant bits are returned in msb.
  86. ///
  87. /// @tparam genIType Signed integer scalar or vector types.
  88. ///
  89. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/imulExtended.xml">GLSL imulExtended man page</a>
  90. /// @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>
  91. template <typename genIType>
  92. GLM_FUNC_DECL void imulExtended(
  93. genIType const & x,
  94. genIType const & y,
  95. genIType & msb,
  96. genIType & lsb);
  97. /// Extracts bits [offset, offset + bits - 1] from value,
  98. /// returning them in the least significant bits of the result.
  99. /// For unsigned data types, the most significant bits of the
  100. /// result will be set to zero. For signed data types, the
  101. /// most significant bits will be set to the value of bit offset + base - 1.
  102. ///
  103. /// If bits is zero, the result will be zero. The result will be
  104. /// undefined if offset or bits is negative, or if the sum of
  105. /// offset and bits is greater than the number of bits used
  106. /// to store the operand.
  107. ///
  108. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  109. ///
  110. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
  111. /// @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>
  112. template <typename genIUType>
  113. GLM_FUNC_DECL genIUType bitfieldExtract(
  114. genIUType const & Value,
  115. int const & Offset,
  116. int const & Bits);
  117. /// Returns the insertion the bits least-significant bits of insert into base.
  118. ///
  119. /// The result will have bits [offset, offset + bits - 1] taken
  120. /// from bits [0, bits - 1] of insert, and all other bits taken
  121. /// directly from the corresponding bits of base. If bits is
  122. /// zero, the result will simply be base. The result will be
  123. /// undefined if offset or bits is negative, or if the sum of
  124. /// offset and bits is greater than the number of bits used to
  125. /// store the operand.
  126. ///
  127. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  128. ///
  129. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a>
  130. /// @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>
  131. template <typename genIUType>
  132. GLM_FUNC_DECL genIUType bitfieldInsert(
  133. genIUType const & Base,
  134. genIUType const & Insert,
  135. int const & Offset,
  136. int const & Bits);
  137. /// Returns the reversal of the bits of value.
  138. /// The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
  139. /// where bits is the total number of bits used to represent value.
  140. ///
  141. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  142. ///
  143. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
  144. /// @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>
  145. template <typename genIUType>
  146. GLM_FUNC_DECL genIUType bitfieldReverse(genIUType const & Value);
  147. /// Returns the number of bits set to 1 in the binary representation of value.
  148. ///
  149. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  150. ///
  151. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
  152. /// @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>
  153. ///
  154. /// @todo Clarify the declaration to specify that scalars are suported.
  155. template <typename T, template <typename> class genIUType>
  156. GLM_FUNC_DECL typename genIUType<T>::signed_type bitCount(genIUType<T> const & Value);
  157. /// Returns the bit number of the least significant bit set to
  158. /// 1 in the binary representation of value.
  159. /// If value is zero, -1 will be returned.
  160. ///
  161. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  162. ///
  163. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
  164. /// @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>
  165. ///
  166. /// @todo Clarify the declaration to specify that scalars are suported.
  167. template <typename T, template <typename> class genIUType>
  168. GLM_FUNC_DECL typename genIUType<T>::signed_type findLSB(genIUType<T> const & Value);
  169. /// Returns the bit number of the most significant bit in the binary representation of value.
  170. /// For positive integers, the result will be the bit number of the most significant bit set to 1.
  171. /// For negative integers, the result will be the bit number of the most significant
  172. /// bit set to 0. For a value of zero or negative one, -1 will be returned.
  173. ///
  174. /// @tparam genIUType Signed or unsigned integer scalar or vector types.
  175. ///
  176. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
  177. /// @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>
  178. ///
  179. /// @todo Clarify the declaration to specify that scalars are suported.
  180. template <typename T, template <typename> class genIUType>
  181. GLM_FUNC_DECL typename genIUType<T>::signed_type findMSB(genIUType<T> const & Value);
  182. /// @}
  183. }//namespace glm
  184. #include "func_integer.inl"
  185. #endif//glm_core_func_integer