20 #include <type_traits> 24 #include <glog/logging.h> 29 using namespace folly;
53 template <
typename T,
typename B>
54 T referenceDivFloor(
T numer,
T denom) {
63 while (mul(r, d) > n) {
66 while (mul(r + 1, d) <= n) {
69 T rv =
static_cast<T>(r);
70 assert(static_cast<B>(rv) == r);
74 template <
typename T,
typename B>
75 T referenceDivCeil(
T numer,
T denom) {
84 while (mul(r, d) < n) {
87 while (mul(r - 1, d) >= n) {
90 T rv =
static_cast<T>(r);
91 assert(static_cast<B>(rv) == r);
95 template <
typename T,
typename B>
96 T referenceDivRoundAway(
T numer,
T denom) {
97 if ((numer < 0) != (denom < 0)) {
98 return referenceDivFloor<T, B>(numer, denom);
100 return referenceDivCeil<T, B>(numer, denom);
104 template <
typename T>
105 std::vector<T> cornerValues() {
107 for (
T i = 1;
i < 24; ++
i) {
122 template <
typename A,
typename B,
typename C>
124 using T = decltype(static_cast<A>(1) / static_cast<B>(1));
125 auto numers = cornerValues<A>();
127 auto denoms = cornerValues<B>();
131 d ==
static_cast<T>(-1)) {
152 runDivTests<int8_t, int8_t, int64_t>();
153 runDivTests<int8_t, uint8_t, int64_t>();
154 runDivTests<int8_t, int16_t, int64_t>();
155 runDivTests<int8_t, uint16_t, int64_t>();
156 runDivTests<int8_t, int32_t, int64_t>();
157 runDivTests<int8_t, uint32_t, int64_t>();
158 #if FOLLY_HAVE_INT128_T 159 runDivTests<int8_t, int64_t, __int128>();
160 runDivTests<int8_t, uint64_t, __int128>();
164 runDivTests<int16_t, int8_t, int64_t>();
165 runDivTests<int16_t, uint8_t, int64_t>();
166 runDivTests<int16_t, int16_t, int64_t>();
167 runDivTests<int16_t, uint16_t, int64_t>();
168 runDivTests<int16_t, int32_t, int64_t>();
169 runDivTests<int16_t, uint32_t, int64_t>();
170 #if FOLLY_HAVE_INT128_T 171 runDivTests<int16_t, int64_t, __int128>();
172 runDivTests<int16_t, uint64_t, __int128>();
176 runDivTests<int32_t, int8_t, int64_t>();
177 runDivTests<int32_t, uint8_t, int64_t>();
178 runDivTests<int32_t, int16_t, int64_t>();
179 runDivTests<int32_t, uint16_t, int64_t>();
180 runDivTests<int32_t, int32_t, int64_t>();
181 runDivTests<int32_t, uint32_t, int64_t>();
182 #if FOLLY_HAVE_INT128_T 183 runDivTests<int32_t, int64_t, __int128>();
184 runDivTests<int32_t, uint64_t, __int128>();
187 #if FOLLY_HAVE_INT128_T 189 runDivTests<int64_t, int8_t, __int128>();
190 runDivTests<int64_t, uint8_t, __int128>();
191 runDivTests<int64_t, int16_t, __int128>();
192 runDivTests<int64_t, uint16_t, __int128>();
193 runDivTests<int64_t, int32_t, __int128>();
194 runDivTests<int64_t, uint32_t, __int128>();
195 runDivTests<int64_t, int64_t, __int128>();
196 runDivTests<int64_t, uint64_t, __int128>();
200 runDivTests<uint8_t, int8_t, int64_t>();
201 runDivTests<uint8_t, uint8_t, int64_t>();
202 runDivTests<uint8_t, int16_t, int64_t>();
203 runDivTests<uint8_t, uint16_t, int64_t>();
204 runDivTests<uint8_t, int32_t, int64_t>();
205 runDivTests<uint8_t, uint32_t, int64_t>();
206 #if FOLLY_HAVE_INT128_T 207 runDivTests<uint8_t, int64_t, __int128>();
208 runDivTests<uint8_t, uint64_t, __int128>();
212 runDivTests<uint16_t, int8_t, int64_t>();
213 runDivTests<uint16_t, uint8_t, int64_t>();
214 runDivTests<uint16_t, int16_t, int64_t>();
215 runDivTests<uint16_t, uint16_t, int64_t>();
216 runDivTests<uint16_t, int32_t, int64_t>();
217 runDivTests<uint16_t, uint32_t, int64_t>();
218 #if FOLLY_HAVE_INT128_T 219 runDivTests<uint16_t, int64_t, __int128>();
220 runDivTests<uint16_t, uint64_t, __int128>();
224 runDivTests<uint32_t, int8_t, int64_t>();
225 runDivTests<uint32_t, uint8_t, int64_t>();
226 runDivTests<uint32_t, int16_t, int64_t>();
227 runDivTests<uint32_t, uint16_t, int64_t>();
228 runDivTests<uint32_t, int32_t, int64_t>();
229 runDivTests<uint32_t, uint32_t, int64_t>();
230 #if FOLLY_HAVE_INT128_T 231 runDivTests<uint32_t, int64_t, __int128>();
232 runDivTests<uint32_t, uint64_t, __int128>();
235 #if FOLLY_HAVE_INT128_T 237 runDivTests<uint64_t, int8_t, __int128>();
238 runDivTests<uint64_t, uint8_t, __int128>();
239 runDivTests<uint64_t, int16_t, __int128>();
240 runDivTests<uint64_t, uint16_t, __int128>();
241 runDivTests<uint64_t, int32_t, __int128>();
242 runDivTests<uint64_t, uint32_t, __int128>();
243 runDivTests<uint64_t, int64_t, __int128>();
244 runDivTests<uint64_t, uint64_t, __int128>();
constexpr T divRoundAwayBranchless(T num, T denom)
constexpr T divFloorBranchful(T num, T denom)
constexpr T divCeilBranchful(T num, T denom)
#define EXPECT_EQ(val1, val2)
constexpr detail::IdivResultType< N, D > divTrunc(N num, D denom)
—— Concurrent Priority Queue Implementation ——
constexpr detail::IdivResultType< N, D > divRoundAway(N num, D denom)
FOLLY_PUSH_WARNING RHS rhs
constexpr detail::IdivResultType< N, D > divFloor(N num, D denom)
constexpr detail::IdivResultType< N, D > divCeil(N num, D denom)
static const char *const value
constexpr T divRoundAwayBranchful(T num, T denom)
constexpr T divCeilBranchless(T num, T denom)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
constexpr T divFloorBranchless(T num, T denom)