]> diplodocus.org Git - nmh/commitdiff
sbr/vector.c: Rewrite BVEC_BYTES(n) macro to remove branch.
authorRalph Corderoy <ralph@inputplus.co.uk>
Fri, 28 Apr 2017 11:16:01 +0000 (12:16 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Fri, 28 Apr 2017 11:16:01 +0000 (12:16 +0100)
Use the idiom of integer truncation.

sbr/vector.c

index c2bd0df913b3003e5781ab42ac33fd7aa7b69f01..84c717e591c28e7aef1fe08ec6268fc09eb9c2a9 100644 (file)
@@ -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;