mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-15 04:00:53 +00:00
engine: update libdivide
This commit is contained in:
parent
1cab7b9765
commit
575541e32c
1 changed files with 29 additions and 22 deletions
51
source/thirdparty/include/libdivide.h
vendored
51
source/thirdparty/include/libdivide.h
vendored
|
@ -11,8 +11,8 @@
|
||||||
#ifndef LIBDIVIDE_H
|
#ifndef LIBDIVIDE_H
|
||||||
#define LIBDIVIDE_H
|
#define LIBDIVIDE_H
|
||||||
|
|
||||||
#define LIBDIVIDE_VERSION "2.0"
|
#define LIBDIVIDE_VERSION "3.0"
|
||||||
#define LIBDIVIDE_VERSION_MAJOR 2
|
#define LIBDIVIDE_VERSION_MAJOR 3
|
||||||
#define LIBDIVIDE_VERSION_MINOR 0
|
#define LIBDIVIDE_VERSION_MINOR 0
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <type_traits>
|
||||||
#else
|
#else
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -297,10 +298,17 @@ static inline int32_t libdivide_count_leading_zeros32(uint32_t val) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
int32_t result = 0;
|
if (val == 0)
|
||||||
uint32_t hi = 1U << 31;
|
return 32;
|
||||||
for (; ~val & hi; hi >>= 1) {
|
int32_t result = 8;
|
||||||
result++;
|
uint32_t hi = 0xFFU << 24;
|
||||||
|
while ((val & hi) == 0) {
|
||||||
|
hi >>= 8;
|
||||||
|
result += 8;
|
||||||
|
}
|
||||||
|
while (val & hi) {
|
||||||
|
result -= 1;
|
||||||
|
hi <<= 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1981,16 +1989,16 @@ enum {
|
||||||
|
|
||||||
// The dispatcher selects a specific division algorithm for a given
|
// The dispatcher selects a specific division algorithm for a given
|
||||||
// type and ALGO using partial template specialization.
|
// type and ALGO using partial template specialization.
|
||||||
template<typename T, int ALGO> struct dispatcher { };
|
template<bool IS_INTEGRAL, bool IS_SIGNED, int SIZEOF, int ALGO> struct dispatcher { };
|
||||||
|
|
||||||
template<> struct dispatcher<int32_t, BRANCHFULL> { DISPATCHER_GEN(int32_t, s32) };
|
template<> struct dispatcher<true, true, sizeof(int32_t), BRANCHFULL> { DISPATCHER_GEN(int32_t, s32) };
|
||||||
template<> struct dispatcher<int32_t, BRANCHFREE> { DISPATCHER_GEN(int32_t, s32_branchfree) };
|
template<> struct dispatcher<true, true, sizeof(int32_t), BRANCHFREE> { DISPATCHER_GEN(int32_t, s32_branchfree) };
|
||||||
template<> struct dispatcher<uint32_t, BRANCHFULL> { DISPATCHER_GEN(uint32_t, u32) };
|
template<> struct dispatcher<true, false, sizeof(uint32_t), BRANCHFULL> { DISPATCHER_GEN(uint32_t, u32) };
|
||||||
template<> struct dispatcher<uint32_t, BRANCHFREE> { DISPATCHER_GEN(uint32_t, u32_branchfree) };
|
template<> struct dispatcher<true, false, sizeof(uint32_t), BRANCHFREE> { DISPATCHER_GEN(uint32_t, u32_branchfree) };
|
||||||
template<> struct dispatcher<int64_t, BRANCHFULL> { DISPATCHER_GEN(int64_t, s64) };
|
template<> struct dispatcher<true, true, sizeof(int64_t), BRANCHFULL> { DISPATCHER_GEN(int64_t, s64) };
|
||||||
template<> struct dispatcher<int64_t, BRANCHFREE> { DISPATCHER_GEN(int64_t, s64_branchfree) };
|
template<> struct dispatcher<true, true, sizeof(int64_t), BRANCHFREE> { DISPATCHER_GEN(int64_t, s64_branchfree) };
|
||||||
template<> struct dispatcher<uint64_t, BRANCHFULL> { DISPATCHER_GEN(uint64_t, u64) };
|
template<> struct dispatcher<true, false, sizeof(uint64_t), BRANCHFULL> { DISPATCHER_GEN(uint64_t, u64) };
|
||||||
template<> struct dispatcher<uint64_t, BRANCHFREE> { DISPATCHER_GEN(uint64_t, u64_branchfree) };
|
template<> struct dispatcher<true, false, sizeof(uint64_t), BRANCHFREE> { DISPATCHER_GEN(uint64_t, u64_branchfree) };
|
||||||
|
|
||||||
// This is the main divider class for use by the user (C++ API).
|
// This is the main divider class for use by the user (C++ API).
|
||||||
// The actual division algorithm is selected using the dispatcher struct
|
// The actual division algorithm is selected using the dispatcher struct
|
||||||
|
@ -2034,9 +2042,11 @@ public:
|
||||||
return div.divide(n);
|
return div.divide(n);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Storage for the actual divisor
|
// Storage for the actual divisor
|
||||||
dispatcher<T, ALGO> div;
|
dispatcher<std::is_integral<T>::value,
|
||||||
|
std::is_signed<T>::value, sizeof(T), ALGO> div;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Overload of operator / for scalar division
|
// Overload of operator / for scalar division
|
||||||
|
@ -2066,12 +2076,9 @@ T& operator/=(T& n, const divider<T, ALGO>& div) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __cplusplus >= 201103L || \
|
// libdivdie::branchfree_divider<T>
|
||||||
(defined(_MSC_VER) && _MSC_VER >= 1800)
|
template <typename T>
|
||||||
// libdivdie::branchfree_divider<T>
|
using branchfree_divider = divider<T, BRANCHFREE>;
|
||||||
template <typename T>
|
|
||||||
using branchfree_divider = divider<T, BRANCHFREE>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace libdivide
|
} // namespace libdivide
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue