func_integer.hpp 10 KB

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