26 T brokenButWidespreadDivCeil(
T num,
T denom) {
27 return (num + denom - 1) / denom;
31 T viaFloatDivCeil(
T num,
T denom) {
32 return static_cast<T>(ceilf(static_cast<float>(num) / denom));
36 T viaDoubleDivCeil(
T num,
T denom) {
37 return static_cast<T>(
ceil(static_cast<double>(num) / denom));
41 T viaLongDoubleDivCeil(
T num,
T denom) {
42 return static_cast<T>(ceill(static_cast<long double>(num) / denom));
46 std::vector<T> divValues() {
60 template <
typename T,
typename F>
61 void runDivTests(
const F& func,
size_t iters) {
62 std::vector<T> denoms;
63 std::vector<T> numers;
65 denoms = divValues<T>();
68 std::mt19937 rnd(1234);
69 std::shuffle(denoms.begin(), denoms.end(), rnd);
70 std::shuffle(numers.begin(), numers.end(), rnd);
96 runDivTests<int8_t>(&folly::divTrunc<int8_t, int8_t>, iters);
99 runDivTests<int8_t>(&folly::divFloor<int8_t, int8_t>, iters);
102 runDivTests<int8_t>(&folly::divCeil<int8_t, int8_t>, iters);
105 runDivTests<int8_t>(&folly::detail::divCeilBranchless<int8_t>, iters);
108 runDivTests<int8_t>(&folly::detail::divCeilBranchful<int8_t>, iters);
111 runDivTests<int8_t>(&brokenButWidespreadDivCeil<int8_t>, iters);
114 runDivTests<int8_t>(&viaFloatDivCeil<int8_t>, iters);
117 runDivTests<int8_t>(&viaDoubleDivCeil<int8_t>, iters);
120 runDivTests<int8_t>(&viaLongDoubleDivCeil<int8_t>, iters);
123 runDivTests<int8_t>(&folly::divRoundAway<int8_t, int8_t>, iters);
128 runDivTests<int16_t>(&folly::divTrunc<int16_t, int16_t>, iters);
131 runDivTests<int16_t>(&folly::divFloor<int16_t, int16_t>, iters);
134 runDivTests<int16_t>(&folly::divCeil<int16_t, int16_t>, iters);
137 runDivTests<int16_t>(&folly::detail::divCeilBranchless<int16_t>, iters);
140 runDivTests<int16_t>(&folly::detail::divCeilBranchful<int16_t>, iters);
143 runDivTests<int16_t>(&brokenButWidespreadDivCeil<int16_t>, iters);
146 runDivTests<int16_t>(&viaFloatDivCeil<int16_t>, iters);
149 runDivTests<int16_t>(&viaDoubleDivCeil<int16_t>, iters);
152 runDivTests<int16_t>(&viaLongDoubleDivCeil<int16_t>, iters);
155 runDivTests<int16_t>(&folly::divRoundAway<int16_t, int16_t>, iters);
160 runDivTests<int32_t>(&folly::divTrunc<int32_t, int32_t>, iters);
163 runDivTests<int32_t>(&folly::divFloor<int32_t, int32_t>, iters);
166 runDivTests<int32_t>(&folly::divCeil<int32_t, int32_t>, iters);
169 runDivTests<int32_t>(&folly::detail::divCeilBranchless<int32_t>, iters);
172 runDivTests<int32_t>(&folly::detail::divCeilBranchful<int32_t>, iters);
175 runDivTests<int32_t>(&brokenButWidespreadDivCeil<int32_t>, iters);
178 runDivTests<int32_t>(&viaFloatDivCeil<int32_t>, iters);
181 runDivTests<int32_t>(&viaDoubleDivCeil<int32_t>, iters);
184 runDivTests<int32_t>(&viaLongDoubleDivCeil<int32_t>, iters);
187 runDivTests<int32_t>(&folly::divRoundAway<int32_t, int32_t>, iters);
192 runDivTests<int64_t>(&folly::divTrunc<int64_t, int64_t>, iters);
195 runDivTests<int64_t>(&folly::divFloor<int64_t, int64_t>, iters);
198 runDivTests<int64_t>(&folly::divCeil<int64_t, int64_t>, iters);
201 runDivTests<int64_t>(&folly::detail::divCeilBranchless<int64_t>, iters);
204 runDivTests<int64_t>(&folly::detail::divCeilBranchful<int64_t>, iters);
207 runDivTests<int64_t>(&brokenButWidespreadDivCeil<int64_t>, iters);
210 runDivTests<int64_t>(&viaFloatDivCeil<int64_t>, iters);
213 runDivTests<int64_t>(&viaDoubleDivCeil<int64_t>, iters);
216 runDivTests<int64_t>(&viaLongDoubleDivCeil<int64_t>, iters);
219 runDivTests<int64_t>(&folly::divRoundAway<int64_t, int64_t>, iters);
224 runDivTests<uint8_t>(&folly::divTrunc<uint8_t, uint8_t>, iters);
227 runDivTests<uint8_t>(&folly::divFloor<uint8_t, uint8_t>, iters);
230 runDivTests<uint8_t>(&folly::divCeil<uint8_t, uint8_t>, iters);
233 runDivTests<uint8_t>(&folly::detail::divCeilBranchless<uint8_t>, iters);
236 runDivTests<uint8_t>(&folly::detail::divCeilBranchful<uint8_t>, iters);
239 runDivTests<uint8_t>(&brokenButWidespreadDivCeil<uint8_t>, iters);
242 runDivTests<uint8_t>(&viaFloatDivCeil<uint8_t>, iters);
245 runDivTests<uint8_t>(&viaDoubleDivCeil<uint8_t>, iters);
248 runDivTests<uint8_t>(&viaLongDoubleDivCeil<uint8_t>, iters);
251 runDivTests<uint8_t>(&folly::divRoundAway<uint8_t, uint8_t>, iters);
256 runDivTests<uint16_t>(&folly::divTrunc<uint16_t, uint16_t>, iters);
259 runDivTests<uint16_t>(&folly::divFloor<uint16_t, uint16_t>, iters);
262 runDivTests<uint16_t>(&folly::divCeil<uint16_t, uint16_t>, iters);
265 runDivTests<uint16_t>(&folly::detail::divCeilBranchless<uint16_t>, iters);
268 runDivTests<uint16_t>(&folly::detail::divCeilBranchful<uint16_t>, iters);
271 runDivTests<uint16_t>(&brokenButWidespreadDivCeil<uint16_t>, iters);
274 runDivTests<uint16_t>(&viaFloatDivCeil<uint16_t>, iters);
277 runDivTests<uint16_t>(&viaDoubleDivCeil<uint16_t>, iters);
280 runDivTests<uint16_t>(&viaLongDoubleDivCeil<uint16_t>, iters);
283 runDivTests<uint16_t>(&folly::divRoundAway<uint16_t, uint16_t>, iters);
288 runDivTests<uint32_t>(&folly::divTrunc<uint32_t, uint32_t>, iters);
291 runDivTests<uint32_t>(&folly::divFloor<uint32_t, uint32_t>, iters);
294 runDivTests<uint32_t>(&folly::divCeil<uint32_t, uint32_t>, iters);
297 runDivTests<uint32_t>(&folly::detail::divCeilBranchless<uint32_t>, iters);
300 runDivTests<uint32_t>(&folly::detail::divCeilBranchful<uint32_t>, iters);
303 runDivTests<uint32_t>(&brokenButWidespreadDivCeil<uint32_t>, iters);
306 runDivTests<uint32_t>(&viaFloatDivCeil<uint32_t>, iters);
309 runDivTests<uint32_t>(&viaDoubleDivCeil<uint32_t>, iters);
312 runDivTests<uint32_t>(&viaLongDoubleDivCeil<uint32_t>, iters);
315 runDivTests<uint32_t>(&folly::divRoundAway<uint32_t, uint32_t>, iters);
320 runDivTests<uint64_t>(&folly::divTrunc<uint64_t, uint64_t>, iters);
323 runDivTests<uint64_t>(&folly::divFloor<uint64_t, uint64_t>, iters);
326 runDivTests<uint64_t>(&folly::divCeil<uint64_t, uint64_t>, iters);
329 runDivTests<uint64_t>(&folly::detail::divCeilBranchless<uint64_t>, iters);
332 runDivTests<uint64_t>(&folly::detail::divCeilBranchful<uint64_t>, iters);
335 runDivTests<uint64_t>(&brokenButWidespreadDivCeil<uint64_t>, iters);
338 runDivTests<uint64_t>(&viaFloatDivCeil<uint64_t>, iters);
341 runDivTests<uint64_t>(&viaDoubleDivCeil<uint64_t>, iters);
344 runDivTests<uint64_t>(&viaLongDoubleDivCeil<uint64_t>, iters);
347 runDivTests<uint64_t>(&folly::divRoundAway<uint64_t, uint64_t>, iters);
351 gflags::ParseCommandLineFlags(&argc, &argv,
true);
constexpr To ceil(std::chrono::duration< Rep, Period > const &d)
#define BENCHMARK_SUSPEND
BENCHMARK_RELATIVE(branchlessDivCeilInt8, iters)
BENCHMARK(divTruncInt8, iters)
static const char *const value
int main(int argc, char **argv)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type