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