9
3

integer.hpp 10 KB

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