From c687e5bdd1da1a27b72cc9a4e94a1a2641fcf0d5 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Fri, 28 Apr 2017 12:16:01 +0100 Subject: [PATCH] sbr/vector.c: Rewrite BVEC_BYTES(n) macro to remove branch. Use the idiom of integer truncation. --- sbr/vector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; -- 2.56.0