From: Ralph Corderoy Date: Fri, 28 Apr 2017 11:16:01 +0000 (+0100) Subject: sbr/vector.c: Rewrite BVEC_BYTES(n) macro to remove branch. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/c687e5bdd1da1a27b72cc9a4e94a1a2641fcf0d5?ds=inline;hp=b5a92b55eb5670e982899e5dfd9aaa1d35db002f sbr/vector.c: Rewrite BVEC_BYTES(n) macro to remove branch. Use the idiom of integer truncation. --- diff --git a/sbr/vector.c b/sbr/vector.c index c2bd0df9..84c717e5 100644 --- a/sbr/vector.c +++ b/sbr/vector.c @@ -36,8 +36,8 @@ #define BVEC_BITS_BITS (BVEC_SIZEOF_BITS * CHAR_BIT) #define BVEC_WORD(max) ((max) / BVEC_BITS_BITS) #define BVEC_OFFSET(max) ((max) % BVEC_BITS_BITS) -#define BVEC_BYTES(n) \ - ((BVEC_WORD(n) + (BVEC_OFFSET(n) == 0 ? 0 : 1)) * BVEC_SIZEOF_BITS) +/* The number of elements bits needs to cover bit n, measured in bytes. */ +#define BVEC_BYTES(n) (((n) / BVEC_BITS_BITS + 1) * BVEC_SIZEOF_BITS) struct bvector { unsigned long *bits;