aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/printf.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-09 17:51:41 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-09 17:51:41 +0100
commita444ae89b582c59aea1255f9fdf07e822f78bf26 (patch)
tree2ec5fb4caa19ab12f062c311970d0a3fd0ebd9a8 /src/libutil/printf.c
parentc5997cb28259f093d11839845c76bf12d92f396f (diff)
downloadrspamd-a444ae89b582c59aea1255f9fdf07e822f78bf26.tar.gz
rspamd-a444ae89b582c59aea1255f9fdf07e822f78bf26.zip
[Minor] Cleanup, use __builtin_clz, mention algorithm source
Diffstat (limited to 'src/libutil/printf.c')
-rw-r--r--src/libutil/printf.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 5895dc89d..0ad2dce27 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -126,7 +126,7 @@ rspamd_decimal_digits32 (guint32 val)
unsigned long r = 0;
_BitScanReverse (&r, val | 1);
tmp = (r + 1) * 1233 >> 12;
-#elif defined(__GNUC__) && (__GNUC__ >= 30)
+#elif defined(__GNUC__) && (__GNUC__ >= 3)
tmp = (32 - __builtin_clz (val | 1U)) * 1233 >> 12;
#else /* Software version */
@@ -189,7 +189,7 @@ rspamd_decimal_digits64 (guint64 val)
_BitScanReverse64 (&r, val | 1);
tmp = (r + 1) * 1233 >> 12;
#endif
-#elif defined(__GNUC__) && (__GNUC__ >= 30)
+#elif defined(__GNUC__) && (__GNUC__ >= 3)
tmp = (64 - __builtin_clzll (val | 1ULL)) * 1233 >> 12;
#else /* Software version */
static const unsigned debruijn_tbl[32] = { 0, 9, 1, 10, 13, 21, 2, 29,
@@ -226,6 +226,14 @@ rspamd_decimal_digits64 (guint64 val)
return tmp - (val < powers_of_10[tmp]) + 1;
}
+/*
+ * Idea from https://github.com/miloyip/itoa-benchmark:
+ * Uses lookup table (LUT) of digit pairs for division/modulo of 100.
+ *
+ * Mentioned in:
+ * https://www.slideshare.net/andreialexandrescu1/three-optimization-tips-for-c-15708507
+ */
+
static const char int_lookup_table[200] = {
'0','0','0','1','0','2','0','3','0','4',
'0','5','0','6','0','7','0','8','0','9',