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