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.

212 lines
10KB

  1. /// @ref core
  2. /// @file glm/integer.hpp
  3. ///
  4. /// @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>
  5. ///
  6. /// @defgroup core_func_integer Integer functions
  7. /// @ingroup core
  8. ///
  9. /// Include <glm/integer.hpp> to use these core features.
  10. ///
  11. /// These all operate component-wise. The description is per component.
  12. /// The notation [a, b] means the set of bits from bit-number a through bit-number
  13. /// b, inclusive. The lowest-order bit is bit 0.
  14. #pragma once
  15. #include "detail/setup.hpp"
  16. #include "detail/qualifier.hpp"
  17. #include "common.hpp"
  18. #include "vector_relational.hpp"
  19. namespace glm
  20. {
  21. /// @addtogroup core_func_integer
  22. /// @{
  23. /// Adds 32-bit unsigned integer x and y, returning the sum
  24. /// modulo pow(2, 32). The value carry is set to 0 if the sum was
  25. /// less than pow(2, 32), or to 1 otherwise.
  26. ///
  27. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  28. ///
  29. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uaddCarry.xml">GLSL uaddCarry man page</a>
  30. /// @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>
  31. template<length_t L, qualifier Q>
  32. GLM_FUNC_DECL vec<L, uint, Q> uaddCarry(
  33. vec<L, uint, Q> const& x,
  34. vec<L, uint, Q> const& y,
  35. vec<L, uint, Q> & carry);
  36. /// Subtracts the 32-bit unsigned integer y from x, returning
  37. /// the difference if non-negative, or pow(2, 32) plus the difference
  38. /// otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise.
  39. ///
  40. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  41. ///
  42. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a>
  43. /// @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>
  44. template<length_t L, qualifier Q>
  45. GLM_FUNC_DECL vec<L, uint, Q> usubBorrow(
  46. vec<L, uint, Q> const& x,
  47. vec<L, uint, Q> const& y,
  48. vec<L, uint, Q> & borrow);
  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. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  54. ///
  55. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a>
  56. /// @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>
  57. template<length_t L, qualifier Q>
  58. GLM_FUNC_DECL void umulExtended(
  59. vec<L, uint, Q> const& x,
  60. vec<L, uint, Q> const& y,
  61. vec<L, uint, Q> & msb,
  62. vec<L, uint, Q> & lsb);
  63. /// Multiplies 32-bit integers x and y, producing a 64-bit
  64. /// result. The 32 least-significant bits are returned in lsb.
  65. /// The 32 most-significant bits are returned in msb.
  66. ///
  67. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  68. ///
  69. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/imulExtended.xml">GLSL imulExtended man page</a>
  70. /// @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>
  71. template<length_t L, qualifier Q>
  72. GLM_FUNC_DECL void imulExtended(
  73. vec<L, int, Q> const& x,
  74. vec<L, int, Q> const& y,
  75. vec<L, int, Q> & msb,
  76. vec<L, int, Q> & lsb);
  77. /// Extracts bits [offset, offset + bits - 1] from value,
  78. /// returning them in the least significant bits of the result.
  79. /// For unsigned data types, the most significant bits of the
  80. /// result will be set to zero. For signed data types, the
  81. /// most significant bits will be set to the value of bit offset + base - 1.
  82. ///
  83. /// If bits is zero, the result will be zero. The result will be
  84. /// undefined if offset or bits is negative, or if the sum of
  85. /// offset and bits is greater than the number of bits used
  86. /// to store the operand.
  87. ///
  88. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  89. /// @tparam T Signed or unsigned integer scalar types.
  90. ///
  91. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
  92. /// @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>
  93. template<length_t L, typename T, qualifier Q>
  94. GLM_FUNC_DECL vec<L, T, Q> bitfieldExtract(
  95. vec<L, T, Q> const& Value,
  96. int Offset,
  97. int Bits);
  98. /// Returns the insertion the bits least-significant bits of insert into base.
  99. ///
  100. /// The result will have bits [offset, offset + bits - 1] taken
  101. /// from bits [0, bits - 1] of insert, and all other bits taken
  102. /// directly from the corresponding bits of base. If bits is
  103. /// zero, the result will simply be base. 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 to
  106. /// store the operand.
  107. ///
  108. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  109. /// @tparam T Signed or unsigned integer scalar or vector types.
  110. ///
  111. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert 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<length_t L, typename T, qualifier Q>
  114. GLM_FUNC_DECL vec<L, T, Q> bitfieldInsert(
  115. vec<L, T, Q> const& Base,
  116. vec<L, T, Q> const& Insert,
  117. int Offset,
  118. int Bits);
  119. /// Returns the reversal of the bits of value.
  120. /// The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
  121. /// where bits is the total number of bits used to represent value.
  122. ///
  123. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  124. /// @tparam T Signed or unsigned integer scalar or vector types.
  125. ///
  126. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
  127. /// @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>
  128. template<length_t L, typename T, qualifier Q>
  129. GLM_FUNC_DECL vec<L, T, Q> bitfieldReverse(vec<L, T, Q> const& v);
  130. /// Returns the number of bits set to 1 in the binary representation of value.
  131. ///
  132. /// @tparam genType Signed or unsigned integer scalar or vector types.
  133. ///
  134. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
  135. /// @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>
  136. template<typename genType>
  137. GLM_FUNC_DECL int bitCount(genType v);
  138. /// Returns the number of bits set to 1 in the binary representation of value.
  139. ///
  140. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  141. /// @tparam T Signed or unsigned integer scalar or vector types.
  142. ///
  143. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount 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<length_t L, typename T, qualifier Q>
  146. GLM_FUNC_DECL vec<L, int, Q> bitCount(vec<L, T, Q> const& v);
  147. /// Returns the bit number of the least significant bit set to
  148. /// 1 in the binary representation of value.
  149. /// If value is zero, -1 will be returned.
  150. ///
  151. /// @tparam genIUType Signed or unsigned integer scalar types.
  152. ///
  153. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
  154. /// @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>
  155. template<typename genIUType>
  156. GLM_FUNC_DECL int findLSB(genIUType x);
  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 L An integer between 1 and 4 included that qualify the dimension of the vector.
  162. /// @tparam T Signed or unsigned integer scalar 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. template<length_t L, typename T, qualifier Q>
  167. GLM_FUNC_DECL vec<L, int, Q> findLSB(vec<L, T, Q> const& v);
  168. /// Returns the bit number of the most significant bit in the binary representation of value.
  169. /// For positive integers, the result will be the bit number of the most significant bit set to 1.
  170. /// For negative integers, the result will be the bit number of the most significant
  171. /// bit set to 0. For a value of zero or negative one, -1 will be returned.
  172. ///
  173. /// @tparam genIUType Signed or unsigned integer scalar types.
  174. ///
  175. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
  176. /// @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>
  177. template<typename genIUType>
  178. GLM_FUNC_DECL int findMSB(genIUType x);
  179. /// Returns the bit number of the most significant bit in the binary representation of value.
  180. /// For positive integers, the result will be the bit number of the most significant bit set to 1.
  181. /// For negative integers, the result will be the bit number of the most significant
  182. /// bit set to 0. For a value of zero or negative one, -1 will be returned.
  183. ///
  184. /// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
  185. /// @tparam T Signed or unsigned integer scalar types.
  186. ///
  187. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
  188. /// @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>
  189. template<length_t L, typename T, qualifier Q>
  190. GLM_FUNC_DECL vec<L, int, Q> findMSB(vec<L, T, Q> const& v);
  191. /// @}
  192. }//namespace glm
  193. #include "detail/func_integer.inl"