1
1

Add an inline hibit calculation function

This commit was SVN r1073.
Этот коммит содержится в:
Jeff Squyres 2004-04-21 00:40:08 +00:00
родитель c9f6089bc3
Коммит 5e5655e778
2 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -13,6 +13,7 @@ headers = \
argv.h \ argv.h \
cmd_line.h \ cmd_line.h \
few.h \ few.h \
hibit.h \
if.h \ if.h \
output.h \ output.h \
path.h \ path.h \

38
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 */