3#include "_vectorize.hpp"
4#if(GLM_ARCH & GLM_ARCH_X86 && GLM_COMPILER & GLM_COMPILER_VC)
6# pragma intrinsic(_BitScanReverse)
10#if !GLM_HAS_EXTENDED_INTEGER_TYPE
11# if GLM_COMPILER & GLM_COMPILER_GCC
12# pragma GCC diagnostic ignored "-Wlong-long"
14# if (GLM_COMPILER & GLM_COMPILER_CLANG)
15# pragma clang diagnostic ignored "-Wc++11-long-long"
23 GLM_FUNC_QUALIFIER T mask(T Bits)
25 return Bits >=
static_cast<T
>(
sizeof(T) * 8) ? ~
static_cast<T
>(0) : (
static_cast<T
>(1) << Bits) -
static_cast<T
>(1);
28 template<length_t L,
typename T, qualifier Q,
bool Aligned,
bool EXEC>
37 template<length_t L,
typename T, qualifier Q,
bool Aligned>
42 return (v & Mask) << Shift | (v & (~Mask)) >> Shift;
46 template<length_t L,
typename T, qualifier Q,
bool Aligned,
bool EXEC>
55 template<length_t L,
typename T, qualifier Q,
bool Aligned>
60 return (v & Mask) + ((v >> Shift) & Mask);
64 template<
typename genIUType,
size_t Bits>
67 GLM_FUNC_QUALIFIER
static int call(genIUType Value)
72 return glm::bitCount(~Value & (Value -
static_cast<genIUType
>(1)));
76# if GLM_HAS_BITSCAN_WINDOWS
77 template<
typename genIUType>
80 GLM_FUNC_QUALIFIER
static int call(genIUType Value)
82 unsigned long Result(0);
83 unsigned char IsNotNull = _BitScanForward(&Result, *
reinterpret_cast<unsigned long*
>(&Value));
84 return IsNotNull ? int(Result) : -1;
88# if !((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_MODEL == GLM_MODEL_32))
89 template<
typename genIUType>
90 struct compute_findLSB<genIUType, 64>
92 GLM_FUNC_QUALIFIER
static int call(genIUType Value)
94 unsigned long Result(0);
95 unsigned char IsNotNull = _BitScanForward64(&Result, *
reinterpret_cast<unsigned __int64*
>(&Value));
96 return IsNotNull ? int(Result) : -1;
102 template<length_t L,
typename T, qualifier Q,
bool EXEC = true>
107 return x | (x >> Shift);
111 template<length_t L,
typename T, qualifier Q>
120 template<length_t L,
typename T, qualifier Q,
int>
136# if GLM_HAS_BITSCAN_WINDOWS
137 template<
typename genIUType>
138 GLM_FUNC_QUALIFIER
int compute_findMSB_32(genIUType Value)
140 unsigned long Result(0);
141 unsigned char IsNotNull = _BitScanReverse(&Result, *
reinterpret_cast<unsigned long*
>(&Value));
142 return IsNotNull ? int(Result) : -1;
145 template<length_t L,
typename T, qualifier Q>
146 struct compute_findMSB_vec<L, T, Q, 32>
154# if !((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_MODEL == GLM_MODEL_32))
155 template<
typename genIUType>
156 GLM_FUNC_QUALIFIER
int compute_findMSB_64(genIUType Value)
158 unsigned long Result(0);
159 unsigned char IsNotNull = _BitScanReverse64(&Result, *
reinterpret_cast<unsigned __int64*
>(&Value));
160 return IsNotNull ? int(Result) : -1;
163 template<length_t L,
typename T, qualifier Q>
164 struct compute_findMSB_vec<L, T, Q, 64>
166 GLM_FUNC_QUALIFIER
static vec<L, int, Q> call(vec<L, T, Q>
const& x)
168 return detail::functor1<vec, L, int, T, Q>::call(compute_findMSB_64, x);
176 GLM_FUNC_QUALIFIER uint uaddCarry(uint
const& x, uint
const& y, uint & Carry)
178 detail::uint64
const Value64(
static_cast<detail::uint64
>(x) +
static_cast<detail::uint64
>(y));
179 detail::uint64
const Max32((
static_cast<detail::uint64
>(1) <<
static_cast<detail::uint64
>(32)) -
static_cast<detail::uint64
>(1));
180 Carry = Value64 > Max32 ? 1u : 0u;
181 return static_cast<uint
>(Value64 % (Max32 +
static_cast<detail::uint64
>(1)));
184 template<length_t L, qualifier Q>
185 GLM_FUNC_QUALIFIER
vec<L, uint, Q> uaddCarry(
vec<L, uint, Q> const& x,
vec<L, uint, Q> const& y,
vec<L, uint, Q>& Carry)
188 vec<L, detail::uint64, Q> Max32((
static_cast<detail::uint64
>(1) <<
static_cast<detail::uint64
>(32)) -
static_cast<detail::uint64
>(1));
190 return vec<L, uint, Q>(Value64 % (Max32 +
static_cast<detail::uint64
>(1)));
194 GLM_FUNC_QUALIFIER uint usubBorrow(uint
const& x, uint
const& y, uint & Borrow)
196 Borrow = x >= y ?
static_cast<uint
>(0) : static_cast<uint>(1);
200 return static_cast<uint
>((
static_cast<detail::int64
>(1) <<
static_cast<detail::int64
>(32)) + (
static_cast<detail::int64
>(y) -
static_cast<detail::int64
>(x)));
203 template<length_t L, qualifier Q>
204 GLM_FUNC_QUALIFIER
vec<L, uint, Q> usubBorrow(
vec<L, uint, Q> const& x,
vec<L, uint, Q> const& y,
vec<L, uint, Q>& Borrow)
213 GLM_FUNC_QUALIFIER
void umulExtended(uint
const& x, uint
const& y, uint & msb, uint & lsb)
215 detail::uint64 Value64 =
static_cast<detail::uint64
>(x) *
static_cast<detail::uint64
>(y);
216 msb =
static_cast<uint
>(Value64 >>
static_cast<detail::uint64
>(32));
217 lsb =
static_cast<uint
>(Value64);
220 template<length_t L, qualifier Q>
221 GLM_FUNC_QUALIFIER
void umulExtended(
vec<L, uint, Q> const& x,
vec<L, uint, Q> const& y,
vec<L, uint, Q>& msb,
vec<L, uint, Q>& lsb)
229 GLM_FUNC_QUALIFIER
void imulExtended(
int x,
int y,
int& msb,
int& lsb)
231 detail::int64 Value64 =
static_cast<detail::int64
>(x) *
static_cast<detail::int64
>(y);
232 msb =
static_cast<int>(Value64 >>
static_cast<detail::int64
>(32));
233 lsb =
static_cast<int>(Value64);
236 template<length_t L, qualifier Q>
237 GLM_FUNC_QUALIFIER
void imulExtended(
vec<L, int, Q> const& x,
vec<L, int, Q> const& y,
vec<L, int, Q>& msb,
vec<L, int, Q>& lsb)
240 lsb =
vec<L, int, Q>(Value64 &
static_cast<detail::int64
>(0xFFFFFFFF));
241 msb =
vec<L, int, Q>((Value64 >>
static_cast<detail::int64
>(32)) &
static_cast<detail::int64
>(0xFFFFFFFF));
245 template<
typename genIUType>
246 GLM_FUNC_QUALIFIER genIUType bitfieldExtract(genIUType Value,
int Offset,
int Bits)
248 return bitfieldExtract(vec<1, genIUType>(Value), Offset, Bits).x;
251 template<length_t L,
typename T, qualifier Q>
254 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
"'bitfieldExtract' only accept integer inputs");
256 return (Value >>
static_cast<T
>(Offset)) &
static_cast<T
>(detail::mask(Bits));
260 template<
typename genIUType>
261 GLM_FUNC_QUALIFIER genIUType bitfieldInsert(genIUType
const& Base, genIUType
const& Insert,
int Offset,
int Bits)
263 GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer,
"'bitfieldInsert' only accept integer values");
265 return bitfieldInsert(vec<1, genIUType>(Base), vec<1, genIUType>(Insert), Offset, Bits).x;
268 template<length_t L,
typename T, qualifier Q>
271 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
"'bitfieldInsert' only accept integer values");
273 T
const Mask =
static_cast<T
>(detail::mask(Bits) << Offset);
274 return (Base & ~Mask) | ((Insert << static_cast<T>(Offset)) & Mask);
278 template<
typename genIUType>
279 GLM_FUNC_QUALIFIER genIUType bitfieldReverse(genIUType x)
281 GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer,
"'bitfieldReverse' only accept integer values");
286 template<length_t L,
typename T, qualifier Q>
289 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
"'bitfieldReverse' only accept integer values");
302 template<
typename genIUType>
303 GLM_FUNC_QUALIFIER
int bitCount(genIUType x)
305 GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer,
"'bitCount' only accept integer values");
310 template<length_t L,
typename T, qualifier Q>
313 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
"'bitCount' only accept integer values");
315# if GLM_COMPILER & GLM_COMPILER_VC
316# pragma warning(push)
317# pragma warning(disable : 4310)
329# if GLM_COMPILER & GLM_COMPILER_VC
335 template<
typename genIUType>
336 GLM_FUNC_QUALIFIER
int findLSB(genIUType Value)
338 GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer,
"'findLSB' only accept integer values");
343 template<length_t L,
typename T, qualifier Q>
346 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
"'findLSB' only accept integer values");
352 template<
typename genIUType>
355 GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer,
"'findMSB' only accept integer values");
360 template<length_t L,
typename T, qualifier Q>
363 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
"'findMSB' only accept integer values");
369#if GLM_CONFIG_SIMD == GLM_ENABLE
370# include "func_integer_simd.inl"
GLM_FUNC_DECL genTypeT mix(genTypeT x, genTypeT y, genTypeU a)
Definition func_common.inl:526
GLM_FUNC_QUALIFIER int findMSB(genIUType v)
Definition func_integer.inl:353
GLM_FUNC_QUALIFIER int findLSB(genIUType Value)
Definition func_integer.inl:336
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec< L, bool, Q > greaterThanEqual(vec< L, T, Q > const &x, vec< L, T, Q > const &y)
Definition func_vector_relational.inl:31
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec< L, bool, Q > greaterThan(vec< L, T, Q > const &x, vec< L, T, Q > const &y)
Definition func_vector_relational.inl:22
detail namespace with internal helper functions
Definition json.h:249
Core features
Definition common.hpp:21
Definition func_integer.inl:48
Definition func_integer.inl:30
Definition func_integer.inl:66
Definition func_integer.inl:104
Definition func_integer.inl:122
Definition _vectorize.hpp:7
Definition qualifier.hpp:60
Definition qualifier.hpp:35