2004-06-29 04:02:25 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-06-29 04:02:25 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
#ifndef OPAL_BIT_OPS_H
|
|
|
|
#define OPAL_BIT_OPS_H
|
2004-06-29 04:02:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
static inline int opal_hibit(int value, int start)
|
2004-06-29 04:02:25 +04:00
|
|
|
{
|
|
|
|
unsigned int mask;
|
|
|
|
|
|
|
|
--start;
|
|
|
|
mask = 1 << start;
|
|
|
|
|
|
|
|
for (; start >= 0; --start, mask >>= 1) {
|
|
|
|
if (value & mask) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the cube dimension of a given value.
|
|
|
|
*
|
|
|
|
* @param value The integer value to examine
|
|
|
|
*
|
|
|
|
* @returns cubedim The smallest cube dimension containing that value
|
|
|
|
*
|
|
|
|
* Look at the integer "value" and calculate the smallest power of two
|
|
|
|
* dimension that contains that value.
|
|
|
|
*
|
|
|
|
* WARNING: *NO* error checking is performed. This is meant to be a
|
|
|
|
* fast inline function.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
static inline int opal_cube_dim(int value)
|
2004-06-29 04:02:25 +04:00
|
|
|
{
|
2004-10-20 03:58:12 +04:00
|
|
|
int dim, size;
|
2004-06-29 04:02:25 +04:00
|
|
|
|
|
|
|
for (dim = 0, size = 1; size < value; ++dim, size <<= 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dim;
|
|
|
|
}
|
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
#endif /* OPAL_BIT_OPS_H */
|