]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: use 32-bit atomics, s/pow/mul
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 11 Jul 2017 15:14:09 +0000 (11:14 -0400)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 11 Jul 2017 18:43:50 +0000 (14:43 -0400)
Some platforms don't support 64-bit atomics, missed converting a
floating point pow() to an integral mul when changing SD algo.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/hash.c
lib/hash.h

index 95643bbae0a5dffc9916196d94e25c7e65c72d41..57a07b5f8e05913e85ff93335093690bca85c804 100644 (file)
@@ -87,13 +87,8 @@ hash_alloc_intern (void *arg)
 }
 
 #define hash_update_ssq(hz, old, new) \
-  do { \
-    long double res; \
-    res = powl(old, 2.0); \
-    hz->stats.ssq -= (uint64_t) res;\
-    res = powl(new, 2.0); \
-    hz->stats.ssq += (uint64_t) res; \
-  } while (0); \
+    atomic_fetch_add_explicit(&hz->stats.ssq, (new + old)*(new - old),\
+                              memory_order_relaxed);
 
 /* Expand hash if the chain length exceeds the threshold. */
 static void hash_expand (struct hash *hash)
index 01d2b1ddc86c16e1ec389be91fa387e6ab1affcd..3b2671afae95c0b5afbba67bcba8b47cdc88d6ab 100644 (file)
@@ -53,9 +53,9 @@ struct hash_backet
 struct hashstats
 {
   /* number of empty hash buckets */
-  _Atomic int empty;
+  _Atomic uint_fast32_t empty;
   /* sum of squares of bucket length */
-  _Atomic uint64_t ssq;
+  _Atomic uint_fast32_t ssq;
 };
 
 struct hash