Commit 55757fa4 authored by Richard Gobeille's avatar Richard Gobeille

engine: update libdivide

parent ecd401b9
......@@ -11,8 +11,8 @@
#ifndef LIBDIVIDE_H
#define LIBDIVIDE_H
#define LIBDIVIDE_VERSION "2.0"
#define LIBDIVIDE_VERSION_MAJOR 2
#define LIBDIVIDE_VERSION "3.0"
#define LIBDIVIDE_VERSION_MAJOR 3
#define LIBDIVIDE_VERSION_MINOR 0
#include <stdint.h>
......@@ -20,6 +20,7 @@
#if defined(__cplusplus)
#include <cstdlib>
#include <cstdio>
#include <type_traits>
#else
#include <stdlib.h>
#include <stdio.h>
......@@ -297,10 +298,17 @@ static inline int32_t libdivide_count_leading_zeros32(uint32_t val) {
}
return 0;
#else
int32_t result = 0;
uint32_t hi = 1U << 31;
for (; ~val & hi; hi >>= 1) {
result++;
if (val == 0)
return 32;
int32_t result = 8;
uint32_t hi = 0xFFU << 24;
while ((val & hi) == 0) {
hi >>= 8;
result += 8;
}
while (val & hi) {
result -= 1;
hi <<= 1;
}
return result;
#endif
......@@ -1981,16 +1989,16 @@ enum {
// The dispatcher selects a specific division algorithm for a given
// 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<int32_t, BRANCHFREE> { DISPATCHER_GEN(int32_t, s32_branchfree) };
template<> struct dispatcher<uint32_t, BRANCHFULL> { DISPATCHER_GEN(uint32_t, u32) };
template<> struct dispatcher<uint32_t, BRANCHFREE> { DISPATCHER_GEN(uint32_t, u32_branchfree) };
template<> struct dispatcher<int64_t, BRANCHFULL> { DISPATCHER_GEN(int64_t, s64) };
template<> struct dispatcher<int64_t, BRANCHFREE> { DISPATCHER_GEN(int64_t, s64_branchfree) };
template<> struct dispatcher<uint64_t, BRANCHFULL> { DISPATCHER_GEN(uint64_t, u64) };
template<> struct dispatcher<uint64_t, BRANCHFREE> { DISPATCHER_GEN(uint64_t, u64_branchfree) };
template<> struct dispatcher<true, true, sizeof(int32_t), BRANCHFULL> { DISPATCHER_GEN(int32_t, s32) };
template<> struct dispatcher<true, true, sizeof(int32_t), BRANCHFREE> { DISPATCHER_GEN(int32_t, s32_branchfree) };
template<> struct dispatcher<true, false, sizeof(uint32_t), BRANCHFULL> { DISPATCHER_GEN(uint32_t, u32) };
template<> struct dispatcher<true, false, sizeof(uint32_t), BRANCHFREE> { DISPATCHER_GEN(uint32_t, u32_branchfree) };
template<> struct dispatcher<true, true, sizeof(int64_t), BRANCHFULL> { DISPATCHER_GEN(int64_t, s64) };
template<> struct dispatcher<true, true, sizeof(int64_t), BRANCHFREE> { DISPATCHER_GEN(int64_t, s64_branchfree) };
template<> struct dispatcher<true, false, sizeof(uint64_t), BRANCHFULL> { DISPATCHER_GEN(uint64_t, u64) };
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).
// The actual division algorithm is selected using the dispatcher struct
......@@ -2034,9 +2042,11 @@ public:
return div.divide(n);
}
#endif
private:
// 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
......@@ -2066,12 +2076,9 @@ T& operator/=(T& n, const divider<T, ALGO>& div) {
}
#endif
#if __cplusplus >= 201103L || \
(defined(_MSC_VER) && _MSC_VER >= 1800)
// libdivdie::branchfree_divider<T>
template <typename T>
using branchfree_divider = divider<T, BRANCHFREE>;
#endif
// libdivdie::branchfree_divider<T>
template <typename T>
using branchfree_divider = divider<T, BRANCHFREE>;
} // namespace libdivide
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment