From c9d018a253f382e40d1c5ed5c17671f9c8f26051 Mon Sep 17 00:00:00 2001 From: cathugger Date: Sun, 21 Mar 2021 17:16:23 +0000 Subject: [PATCH] whatever i implemented it anyway --- GNUmakefile.in | 2 +- filters_main.inc.h | 13 +------------ ifilter_bitsum.h | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 ifilter_bitsum.h diff --git a/GNUmakefile.in b/GNUmakefile.in index c457061..71beef6 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -399,7 +399,7 @@ ioutil.c.o: types.h ioutil.h keccak.c.o: types.h keccak.h main.c.o: types.h vec.h base32.h cpucount.h keccak.h ioutil.h common.h yaml.h main.c.o: filters.h worker.h filters_inc.inc.h filters_main.inc.h -main.c.o: filters_common.inc.h +main.c.o: filters_common.inc.h ifilter_bitsum.h test_base16.c.o: types.h base16.h test_base32.c.o: types.h base32.h test_base64.c.o: types.h base64.h diff --git a/filters_main.inc.h b/filters_main.inc.h index 65028a6..e986f9d 100644 --- a/filters_main.inc.h +++ b/filters_main.inc.h @@ -1,5 +1,6 @@ #include "filters_common.inc.h" +#include "ifilter_bitsum.h" #ifdef INTFILTER @@ -80,18 +81,6 @@ static void ifilter_expand( } } -static IFT ifilter_bitsum(IFT x) -{ - if (sizeof(IFT) == 16) - return (((IFT) 1) << - (__builtin_popcountll((unsigned long long) (x >> (sizeof(IFT) * 8 / 2))) + - __builtin_popcountll((unsigned long long) x))) - 1; - if (sizeof(IFT) == 8) - return (((IFT) 1) << __builtin_popcountll((unsigned long long) x)) - 1; - - return (((IFT) 1) << __builtin_popcount((unsigned int) x)) - 1; -} - static inline void ifilter_addflatten(struct intfilter *ifltr,IFT mask) { if (VEC_LENGTH(filters) == 0) { diff --git a/ifilter_bitsum.h b/ifilter_bitsum.h new file mode 100644 index 0000000..fdbe45e --- /dev/null +++ b/ifilter_bitsum.h @@ -0,0 +1,27 @@ +#ifdef __GNUC__ + +static IFT ifilter_bitsum(IFT x) +{ + if (sizeof(IFT) == 16) + return (((IFT) 1) << + (__builtin_popcountll((unsigned long long) (x >> (sizeof(IFT) * 8 / 2))) + + __builtin_popcountll((unsigned long long) x))) - 1; + if (sizeof(IFT) == 8) + return (((IFT) 1) << __builtin_popcountll((unsigned long long) x)) - 1; + + return (((IFT) 1) << __builtin_popcount((unsigned int) x)) - 1; +} + +#else + +static IFT ifilter_bitsum(IFT x) +{ + int v = 0; + while (x != 0) { + x &= x - 1; + v++; + } + return (((IFT) 1) << v) - 1; +} + +#endif