diff options
| author | tmk <nobody@nowhere> | 2012-10-18 01:11:06 +0900 | 
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-10-18 01:11:06 +0900 | 
| commit | 3c822b511e7af60332a7e5a938c08bafb2516ba3 (patch) | |
| tree | 0a78cce225b04930de14935dffd36ce8f3bf2d76 /common/util.c | |
| parent | 93e33fb8f694c9685accd72ed0458a2cf3d3f04a (diff) | |
| parent | fffc375b45ad795c4a8d3cde94783dac195a2613 (diff) | |
| download | firmware-3c822b511e7af60332a7e5a938c08bafb2516ba3.tar.gz firmware-3c822b511e7af60332a7e5a938c08bafb2516ba3.tar.bz2 firmware-3c822b511e7af60332a7e5a938c08bafb2516ba3.zip  | |
Merge branch 'layerfix'
Diffstat (limited to 'common/util.c')
| -rw-r--r-- | common/util.c | 16 | 
1 files changed, 10 insertions, 6 deletions
diff --git a/common/util.c b/common/util.c index 36afdd447..644301fe8 100644 --- a/common/util.c +++ b/common/util.c @@ -17,19 +17,23 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #include "util.h" -// bit population -int bitpop(uint8_t bits) +// bit population - return number of on-bit +uint8_t bitpop(uint8_t bits)  { -    int c; +    uint8_t c;      for (c = 0; bits; c++)          bits &= bits -1;      return c; +/* +    const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; +    return bit_count[bits>>4] + bit_count[bits&0x0F] +*/  } -// most significant on-bit -int biton(uint8_t bits) +// most significant on-bit - return highest location of on-bit +uint8_t biton(uint8_t bits)  { -    int n = 0; +    uint8_t n = 0;      if (bits >> 4) { bits >>= 4; n += 4;}      if (bits >> 2) { bits >>= 2; n += 2;}      if (bits >> 1) { bits >>= 1; n += 1;}  | 
