]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: don't normalize input of crush_ln iteratively
authorPiotr Dałek <git@predictor.org.pl>
Wed, 31 Aug 2016 15:24:31 +0000 (17:24 +0200)
committerPiotr Dałek <git@predictor.org.pl>
Wed, 31 Aug 2016 19:18:54 +0000 (21:18 +0200)
Use __builtin_clz() supported by GCC and Clang to figure out
how many bits we should shift instead of shifting by a bit
in a loop until the value gets normalized. Improves performance
of this function by up to 3x in worst-case scenario and overall
straw2 performance by ~10%.

Signed-off-by: Piotr Dałek <git@predictor.org.pl>
src/crush/mapper.c

index 832900f6821bf30091e549cb6cedb32e36325b37..6f6b09e5807e1036502574083110d6176ea3abd7 100644 (file)
@@ -253,9 +253,13 @@ static __u64 crush_ln(unsigned int xin)
 
        /* normalize input */
        iexpon = 15;
-       while (!(x & 0x18000)) {
-               x <<= 1;
-               iexpon--;
+
+       // figure out number of bits we need to shift and
+       // do it in one step instead of iteratively     
+       if (!(x & 0x18000)) {
+         int bits = __builtin_clz(x & 0x1FFFF) - 16;
+         x <<= bits;
+         iexpon = 15 - bits;
        }
 
        index1 = (x >> 8) << 1;