1///////////////////////////////////////////////////////////////////////////////////
2/// OpenGL Mathematics (glm.g-truc.net)
3///
4/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
5/// Permission is hereby granted, free of charge, to any person obtaining a copy
6/// of this software and associated documentation files (the "Software"), to deal
7/// in the Software without restriction, including without limitation the rights
8/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9/// copies of the Software, and to permit persons to whom the Software is
10/// furnished to do so, subject to the following conditions:
11///
12/// The above copyright notice and this permission notice shall be included in
13/// all copies or substantial portions of the Software.
14///
15/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21/// THE SOFTWARE.
22///
23/// @ref gtx_bit
24/// @file glm/gtx/bit.hpp
25/// @date 2007-03-14 / 2011-06-07
26/// @author Christophe Riccio
27///
28/// @see core (dependence)
29/// @see gtc_half_float (dependence)
30///
31/// @defgroup gtx_bit GLM_GTX_bit
32/// @ingroup gtx
33///
34/// @brief Allow to perform bit operations on integer values
35///
36/// <glm/gtx/bit.hpp> need to be included to use these functionalities.
37///////////////////////////////////////////////////////////////////////////////////
38
39#ifndef GLM_GTX_bit
40#define GLM_GTX_bit
41
42// Dependencies
43#include "../detail/type_int.hpp"
44#include "../detail/setup.hpp"
45#include <cstddef>
46
47#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
48#	pragma message("GLM: GLM_GTX_bit extension included")
49#endif
50
51namespace glm
52{
53	/// @addtogroup gtx_bit
54	/// @{
55
56	/// Build a mask of 'count' bits
57	/// @see gtx_bit
58	template <typename genIType>
59	GLM_FUNC_DECL genIType mask(genIType const & count);
60
61	//! Find the highest bit set to 1 in a integer variable and return its value.
62	/// @see gtx_bit
63	template <typename genType>
64	GLM_FUNC_DECL genType highestBitValue(genType const & value);
65
66	//! Return true if the value is a power of two number.
67	/// @see gtx_bit
68	template <typename genType>
69	GLM_FUNC_DECL bool isPowerOfTwo(genType const & value);
70
71	//! Return the power of two number which value is just higher the input value.
72	/// @see gtx_bit
73	template <typename genType>
74	GLM_FUNC_DECL genType powerOfTwoAbove(genType const & value);
75
76	//! Return the power of two number which value is just lower the input value.
77	/// @see gtx_bit
78	template <typename genType>
79	GLM_FUNC_DECL genType powerOfTwoBelow(genType const & value);
80
81	//! Return the power of two number which value is the closet to the input value.
82	/// @see gtx_bit
83	template <typename genType>
84	GLM_FUNC_DECL genType powerOfTwoNearest(genType const & value);
85
86	//! Revert all bits of any integer based type.
87	/// @see gtx_bit
88	template <typename genType>
89	GLM_DEPRECATED GLM_FUNC_DECL genType bitRevert(genType const & value);
90
91	//! Rotate all bits to the right.
92	/// @see gtx_bit
93	template <typename genType>
94	GLM_FUNC_DECL genType bitRotateRight(genType const & In, std::size_t Shift);
95
96	//! Rotate all bits to the left.
97	/// @see gtx_bit
98	template <typename genType>
99	GLM_FUNC_DECL genType bitRotateLeft(genType const & In, std::size_t Shift);
100
101	//! Set to 1 a range of bits.
102	/// @see gtx_bit
103	template <typename genIUType>
104	GLM_FUNC_DECL genIUType fillBitfieldWithOne(
105		genIUType const & Value,
106		int const & FromBit,
107		int const & ToBit);
108
109	//! Set to 0 a range of bits.
110	/// @see gtx_bit
111	template <typename genIUType>
112	GLM_FUNC_DECL genIUType fillBitfieldWithZero(
113		genIUType const & Value,
114		int const & FromBit,
115		int const & ToBit);
116
117	/// Interleaves the bits of x and y.
118	/// The first bit is the first bit of x followed by the first bit of y.
119	/// The other bits are interleaved following the previous sequence.
120	///
121	/// @see gtx_bit
122	GLM_FUNC_DECL int16 bitfieldInterleave(int8 x, int8 y);
123
124	/// Interleaves the bits of x and y.
125	/// The first bit is the first bit of x followed by the first bit of y.
126	/// The other bits are interleaved following the previous sequence.
127	///
128	/// @see gtx_bit
129	GLM_FUNC_DECL uint16 bitfieldInterleave(uint8 x, uint8 y);
130
131	/// Interleaves the bits of x and y.
132	/// The first bit is the first bit of x followed by the first bit of y.
133	/// The other bits are interleaved following the previous sequence.
134	///
135	/// @see gtx_bit
136	GLM_FUNC_DECL int32 bitfieldInterleave(int16 x, int16 y);
137
138	/// Interleaves the bits of x and y.
139	/// The first bit is the first bit of x followed by the first bit of y.
140	/// The other bits are interleaved following the previous sequence.
141	///
142	/// @see gtx_bit
143	GLM_FUNC_DECL uint32 bitfieldInterleave(uint16 x, uint16 y);
144
145	/// Interleaves the bits of x and y.
146	/// The first bit is the first bit of x followed by the first bit of y.
147	/// The other bits are interleaved following the previous sequence.
148	///
149	/// @see gtx_bit
150	GLM_FUNC_DECL int64 bitfieldInterleave(int32 x, int32 y);
151
152	/// Interleaves the bits of x and y.
153	/// The first bit is the first bit of x followed by the first bit of y.
154	/// The other bits are interleaved following the previous sequence.
155	///
156	/// @see gtx_bit
157	GLM_FUNC_DECL uint64 bitfieldInterleave(uint32 x, uint32 y);
158
159	/// Interleaves the bits of x, y and z.
160	/// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
161	/// The other bits are interleaved following the previous sequence.
162	///
163	/// @see gtx_bit
164	GLM_FUNC_DECL int32 bitfieldInterleave(int8 x, int8 y, int8 z);
165
166	/// Interleaves the bits of x, y and z.
167	/// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
168	/// The other bits are interleaved following the previous sequence.
169	///
170	/// @see gtx_bit
171	GLM_FUNC_DECL uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z);
172
173	/// Interleaves the bits of x, y and z.
174	/// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
175	/// The other bits are interleaved following the previous sequence.
176	///
177	/// @see gtx_bit
178	GLM_FUNC_DECL int64 bitfieldInterleave(int16 x, int16 y, int16 z);
179
180	/// Interleaves the bits of x, y and z.
181	/// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
182	/// The other bits are interleaved following the previous sequence.
183	///
184	/// @see gtx_bit
185	GLM_FUNC_DECL uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z);
186
187	/// Interleaves the bits of x, y and z.
188	/// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
189	/// The other bits are interleaved following the previous sequence.
190	///
191	/// @see gtx_bit
192	GLM_FUNC_DECL int64 bitfieldInterleave(int32 x, int32 y, int32 z);
193
194	/// Interleaves the bits of x, y and z.
195	/// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
196	/// The other bits are interleaved following the previous sequence.
197	///
198	/// @see gtx_bit
199	GLM_FUNC_DECL uint64 bitfieldInterleave(uint32 x, uint32 y, uint32 z);
200
201	/// Interleaves the bits of x, y, z and w.
202	/// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
203	/// The other bits are interleaved following the previous sequence.
204	///
205	/// @see gtx_bit
206	GLM_FUNC_DECL int32 bitfieldInterleave(int8 x, int8 y, int8 z, int8 w);
207
208	/// Interleaves the bits of x, y, z and w.
209	/// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
210	/// The other bits are interleaved following the previous sequence.
211	///
212	/// @see gtx_bit
213	GLM_FUNC_DECL uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z, uint8 w);
214
215	/// Interleaves the bits of x, y, z and w.
216	/// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
217	/// The other bits are interleaved following the previous sequence.
218	///
219	/// @see gtx_bit
220	GLM_FUNC_DECL int64 bitfieldInterleave(int16 x, int16 y, int16 z, int16 w);
221
222	/// Interleaves the bits of x, y, z and w.
223	/// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
224	/// The other bits are interleaved following the previous sequence.
225	///
226	/// @see gtx_bit
227	GLM_FUNC_DECL uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z, uint16 w);
228
229	/// @}
230} //namespace glm
231
232#include "bit.inl"
233
234#endif//GLM_GTX_bit
235