Add generic hweight helpers
authorJens Axboe <axboe@kernel.dk>
Mon, 21 Jan 2013 17:55:02 +0000 (10:55 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 21 Jan 2013 17:55:02 +0000 (10:55 -0700)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
lib/hweight.c [new file with mode: 0644]
lib/hweight.h [new file with mode: 0644]
options.c
verify.c

index 03e46fa..967996d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
                memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
                json.c lib/zipf.c lib/axmap.c lib/lfsr.c gettime-thread.c \
-               helpers.c lib/flist_sort.c
+               helpers.c lib/flist_sort.c lib/hweight.c
 
 ifdef CONFIG_64BIT_LLP64
   CFLAGS += -DBITS_PER_LONG=32
diff --git a/lib/hweight.c b/lib/hweight.c
new file mode 100644 (file)
index 0000000..738ed27
--- /dev/null
@@ -0,0 +1,19 @@
+#include "hweight.h"
+
+unsigned int hweight8(uint8_t w)
+{
+       unsigned int res = w - ((w >> 1) & 0x55);
+
+       res = (res & 0x33) + ((res >> 2) & 0x33);
+       return (res + (res >> 4)) & 0x0F;
+}
+
+unsigned int hweight32(uint32_t w)
+{
+       unsigned int res = w - ((w >> 1) & 0x55555555);
+
+       res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+       res = (res + (res >> 4)) & 0x0F0F0F0F;
+       res = res + (res >> 8);
+       return (res + (res >> 16)) & 0x000000FF;
+}
diff --git a/lib/hweight.h b/lib/hweight.h
new file mode 100644 (file)
index 0000000..1965eaa
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef FIO_HWEIGHT_H
+#define FIO_HWEIGHT_H
+
+#include <inttypes.h>
+
+unsigned int hweight8(uint8_t w);
+unsigned int hweight32(uint32_t w);
+
+#endif
index 8d460be..2b71abd 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1961,6 +1961,11 @@ static struct fio_option options[FIO_MAX_OPTS] = {
                .parent = "verify_async",
        },
 #endif
+       {
+               .name   = "experimental_verify",
+               .off1   = td_var_offset(experimental_verify),
+               .type   = FIO_OPT_BOOL,
+       },
 #ifdef FIO_HAVE_TRIM
        {
                .name   = "trim_percentage",
index c0485d5..cb13b62 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -13,6 +13,7 @@
 #include "smalloc.h"
 #include "trim.h"
 #include "lib/rand.h"
+#include "lib/hweight.h"
 
 #include "crc/md5.h"
 #include "crc/crc64.h"
@@ -308,14 +309,6 @@ static inline void *io_u_verify_off(struct verify_header *hdr, struct vcont *vc)
        return vc->io_u->buf + vc->hdr_num * hdr->len + hdr_size(hdr);
 }
 
-static unsigned int hweight8(unsigned int w)
-{
-       unsigned int res = w - ((w >> 1) & 0x55);
-
-       res = (res & 0x33) + ((res >> 2) & 0x33);
-       return (res + (res >> 4)) & 0x0F;
-}
-
 static int verify_io_u_pattern(struct verify_header *hdr, struct vcont *vc)
 {
        struct thread_data *td = vc->td;