]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
build: remove all gnulib bit manipulation modules
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 3 Oct 2019 14:51:30 +0000 (15:51 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Mon, 7 Oct 2019 12:39:26 +0000 (13:39 +0100)
We're using gnulib to get ffs, ffsl, rotl32, count_one_bits,
and count_leading_zeros. Except for rotl32 they can all be
replaced with gcc/clangs builtins. rotl32 is a one-line
trivial function.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
13 files changed:
bootstrap.conf
src/conf/capabilities.c
src/conf/domain_conf.c
src/conf/snapshot_conf.c
src/internal.h
src/libxl/xen_common.c
src/util/virbitmap.c
src/util/vircgroupv2.c
src/util/virhashcode.c
src/util/virhostcpu.c
src/util/virhostmem.c
src/util/virrandom.c
tools/vsh.c

index fe8f7fc9c3bd275daeb69f6acb5009b74f3bc975..7b20f1c37106aaeb726ad16bd00f79aafcfe6b3f 100644 (file)
@@ -22,7 +22,6 @@ accept
 areadlink
 base64
 bind
-bitrotate
 byteswap
 c-ctype
 c-strcase
@@ -34,8 +33,6 @@ clock-time
 close
 connect
 configmake
-count-leading-zeros
-count-one-bits
 dirname-lgpl
 environ
 execinfo
@@ -43,8 +40,6 @@ fclose
 fcntl
 fcntl-h
 fdatasync
-ffs
-ffsl
 fnmatch
 fsync
 getaddrinfo
index 1231b9727c658ac71dbb534c2f5fa62717650feb..7419d9cfc8198ba7e3a4ae69af992d5dab8012c7 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <config.h>
 
-#include <strings.h>
 #include <unistd.h>
 
 #include "capabilities.h"
@@ -1152,7 +1151,7 @@ virCapabilitiesFormatHostXML(virCapsHostPtr host,
         virBufferAddLit(buf, "<power_management>\n");
         virBufferAdjustIndent(buf, 2);
         while (pm) {
-            int bit = ffs(pm) - 1;
+            int bit = __builtin_ffs(pm) - 1;
             virBufferAsprintf(buf, "<%s/>\n",
                               virCapsHostPMTargetTypeToString(bit));
             pm &= ~(1U << bit);
index 5d090876f8ac7bf8b5254311a50706b02438d78d..a53cd6a72592c97db25c09994f53cccb8da8a524 100644 (file)
@@ -45,7 +45,6 @@
 #include "virstoragefile.h"
 #include "virfile.h"
 #include "virbitmap.h"
-#include "count-one-bits.h"
 #include "secret_conf.h"
 #include "netdev_vport_profile_conf.h"
 #include "netdev_bandwidth_conf.h"
index 96ad8ca953c3f4879ff04269f84ba2683f40e6f1..a77f5213029308c7861fa0bf9d4aabb94e555518 100644 (file)
@@ -29,7 +29,6 @@
 #include "internal.h"
 #include "virbitmap.h"
 #include "virbuffer.h"
-#include "count-one-bits.h"
 #include "datatypes.h"
 #include "domain_conf.h"
 #include "virlog.h"
index adc1e3f496a4ef4eb6c19277be7bb80d7cf63441..fc251067f0a322328971268de8a89ca6b228cb4c 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 #if STATIC_ANALYSIS
 # undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble.  */
@@ -63,7 +64,6 @@
 
 #include "c-strcase.h"
 #include "ignore-value.h"
-#include "count-leading-zeros.h"
 
 /* String equality tests, suggested by Jim Meyering. */
 #define STREQ(a, b) (strcmp(a, b) == 0)
     } while (0)
 
 
+/* Count leading zeros in an unsigned int.
+ *
+ * Wrapper needed as __builtin_clz is undefined if value is zero
+ */
+#define VIR_CLZ(value) \
+    (value ? __builtin_clz(value) : (8 * sizeof(unsigned)))
 
 /* divide value by size, rounding up */
 #define VIR_DIV_UP(value, size) (((value) + (size) - 1) / (size))
  * for 0 or number more than 2^31 (for 32bit unsigned int). */
 #define VIR_ROUND_UP_POWER_OF_TWO(value) \
     ((value) > 0 && (value) <= 1U << (sizeof(unsigned int) * 8 - 1) ? \
-     1U << (sizeof(unsigned int) * 8 - count_leading_zeros((value) - 1)) : 0)
+     1U << (sizeof(unsigned int) * 8 - VIR_CLZ((value) - 1)) : 0)
 
 
 /* Specific error values for use in forwarding programs such as
index d327f03d730ffe3d16d9293d2f95278bb4b1190f..2680e88a60854a23f07b2732fb3d346192c4cbb0 100644 (file)
@@ -31,7 +31,6 @@
 #include "virconf.h"
 #include "viralloc.h"
 #include "viruuid.h"
-#include "count-one-bits.h"
 #include "xenxs_private.h"
 #include "domain_conf.h"
 #include "virstring.h"
index a61f4b20956d8e59562a47cbb97993edabaf8ae5..ed8f06acc72d7edc1084a45137ca52247b51ab06 100644 (file)
@@ -27,7 +27,6 @@
 #include "viralloc.h"
 #include "virbuffer.h"
 #include "c-ctype.h"
-#include "count-one-bits.h"
 #include "virstring.h"
 #include "virutil.h"
 #include "virerror.h"
@@ -1028,7 +1027,7 @@ virBitmapNextSetBit(virBitmapPtr bitmap,
     if (bits == 0)
         return -1;
 
-    return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT;
+    return __builtin_ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT;
 }
 
 
@@ -1127,7 +1126,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap,
     if (bits == 0)
         return -1;
 
-    return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT;
+    return __builtin_ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT;
 }
 
 
@@ -1144,7 +1143,7 @@ virBitmapCountBits(virBitmapPtr bitmap)
     size_t ret = 0;
 
     for (i = 0; i < bitmap->map_len; i++)
-        ret += count_one_bits_l(bitmap->map[i]);
+        ret += __builtin_popcountl(bitmap->map[i]);
 
     return ret;
 }
index 143083e56f55c9fa3f05d9d3bb6207962e3886eb..ace04bba04183913442cb2a276abe4b57ba55ad3 100644 (file)
@@ -339,7 +339,7 @@ static int
 virCgroupV2GetAnyController(virCgroupPtr group)
 {
     /* The least significant bit is position 1. */
-    return ffs(group->unified.controllers) - 1;
+    return __builtin_ffs(group->unified.controllers) - 1;
 }
 
 
index 310ec891c809ce6a32f40eda8cc86d42fe64967e..98d5dceeba1bbd3d2f7bdedebcfca101a18e8f05 100644 (file)
 #include <config.h>
 
 #include "virhashcode.h"
-#include "bitrotate.h"
+
+static uint32_t rotl32(uint32_t x, int8_t r)
+{
+    return (x << r) | (x >> (32 - r));
+}
 
 /* slower than original but handles platforms that do only aligned reads */
 static inline uint32_t getblock(const uint8_t *p, int i)
index 8c00804b0ef29186d4b1822f3c4fb905b481cc7b..83e48530065b6dd64f71d4038d622b34e42fbe38 100644 (file)
@@ -44,7 +44,6 @@
 #include "virhostcpupriv.h"
 #include "physmem.h"
 #include "virerror.h"
-#include "count-one-bits.h"
 #include "intprops.h"
 #include "virarch.h"
 #include "virfile.h"
index 19cd282724905f0409c442456c8a735bb9e9df33..d16e0217e580510cfa1ec913c2e2c67bc3a2789d 100644 (file)
@@ -37,7 +37,6 @@
 #include "virhostmem.h"
 #include "physmem.h"
 #include "virerror.h"
-#include "count-one-bits.h"
 #include "virarch.h"
 #include "virfile.h"
 #include "virtypedparam.h"
index 93c5bf3a2ccd955eddb01b6e758fddb0a2c51837..8dcab1ac475cb761fff9434279c7568fd8545aeb 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <inttypes.h>
 #include <math.h>
-#include <strings.h>
 #include <time.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -32,7 +31,6 @@
 
 #include "virrandom.h"
 #include "virthread.h"
-#include "count-one-bits.h"
 #include "virutil.h"
 #include "virerror.h"
 #include "virfile.h"
@@ -97,7 +95,7 @@ double virRandom(void)
 uint32_t virRandomInt(uint32_t max)
 {
     if ((max & (max - 1)) == 0)
-        return virRandomBits(ffs(max) - 1);
+        return virRandomBits(__builtin_ffs(max) - 1);
 
     double val = virRandom();
     return val * max;
index 9bdd90e362d9688639fcfa598555a0fdfe66cce4..bf8b6b412b8847f8f5fad9eee67ec955ec659ecc 100644 (file)
@@ -555,7 +555,7 @@ vshCmddefGetData(const vshCmdDef *cmd, uint64_t *opts_need_arg,
         return NULL;
 
     /* Grab least-significant set bit */
-    i = ffsl(*opts_need_arg) - 1;
+    i = __builtin_ffsl(*opts_need_arg) - 1;
     opt = &cmd->opts[i];
     if (opt->type != VSH_OT_ARGV)
         *opts_need_arg &= ~(1ULL << i);