diff options
| author | tylo <[email protected]> | 2020-03-09 19:28:43 +0100 |
|---|---|---|
| committer | tylo <[email protected]> | 2020-03-09 19:28:43 +0100 |
| commit | dd30f5c701609a8c6dc09b9b48967df54767b7ed (patch) | |
| tree | 9a91af0c323ec605d2649962417ad3d78fa87a06 | |
| parent | b3c5e7e311c6fa2ba37448cc6703d3c4add3637a (diff) | |
| download | STC-modified-dd30f5c701609a8c6dc09b9b48967df54767b7ed.tar.gz STC-modified-dd30f5c701609a8c6dc09b9b48967df54767b7ed.zip | |
fast_reduce
| -rw-r--r-- | cmap.h | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -207,4 +207,11 @@ typedef Value cmap_##tag##_value_t #define FIBONACCI_DECL size_t fib1 = 0, fib2 = 1, fibx
#define FIBONACCI_NEXT (fibx = fib1 + fib2, fib1 = fib2, fib2 = fibx)
+// https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
+//
+static inline uint32_t fast_reduce(uint32_t x, uint32_t N) {
+ return ((uint64_t) x * (uint64_t) N) >> 32;
+}
+#define cmap_reduce(x, N) ((uint32_t)(((uint64_t) (x) * (uint64_t) (N)) >> 32))
+
#endif
|
