From 5e5655e778d1df7427aa4fe6462e7741de24b1b2 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 21 Apr 2004 00:40:08 +0000 Subject: [PATCH] Add an inline hibit calculation function This commit was SVN r1073. --- src/util/Makefile.am | 1 + src/util/hibit.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/util/hibit.h diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 19785d7d93..7bbb5ba131 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -13,6 +13,7 @@ headers = \ argv.h \ cmd_line.h \ few.h \ + hibit.h \ if.h \ output.h \ path.h \ diff --git a/src/util/hibit.h b/src/util/hibit.h new file mode 100644 index 0000000000..6942d74ea0 --- /dev/null +++ b/src/util/hibit.h @@ -0,0 +1,38 @@ +/* + * $HEADER$ + */ + +#ifndef LAM_HIBIT_H +#define LAM_HIBIT_H + +/** + * Calculates the highest bit in an integer + * + * @param value The integer value to examine + * @param start Position to start looking + * + * @returns pos Position of highest-set integer or -1 if none are set. + * + * Look at the integer "value" starting at position "start", and move + * to the right. Return the index of the highest bit that is set to + * 1. + * + * WARNING: *NO* error checking is performed. This is meant to be a + * fast inline function. + */ +static inline int lam_hibit(int value, int start) +{ + unsigned int mask; + + --start; + mask = 1 << start; + + for (; start >= 0; --start, mask >>= 1) { + if (value & mask) + break; + } + + return start; +} + +#endif /* LAM_HIBIT_H */