From cc8e66754b1a5d0c11985cb0feb51ead49668744 Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 2 Apr 2013 16:09:43 +0900 Subject: Refine ACT_LAYER and ACT_LAYER_TAP - Remove ACT_LAYER_BITOP --- common/util.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'common/util.c') diff --git a/common/util.c b/common/util.c index ff1926d7d1..6d4d6bfda1 100644 --- a/common/util.c +++ b/common/util.c @@ -38,6 +38,14 @@ uint8_t bitpop16(uint16_t bits) return c; } +uint8_t bitpop32(uint32_t bits) +{ + uint8_t c; + for (c = 0; bits; c++) + bits &= bits - 1; + return c; +} + // most significant on-bit - return highest location of on-bit // NOTE: return 0 when bit0 is on or all bits are off uint8_t biton(uint8_t bits) @@ -58,3 +66,14 @@ uint8_t biton16(uint16_t bits) if (bits >> 1) { bits >>= 1; n += 1;} return n; } + +uint8_t biton32(uint32_t bits) +{ + uint8_t n = 0; + if (bits >>16) { bits >>=16; n +=16;} + if (bits >> 8) { bits >>= 8; n += 8;} + if (bits >> 4) { bits >>= 4; n += 4;} + if (bits >> 2) { bits >>= 2; n += 2;} + if (bits >> 1) { bits >>= 1; n += 1;} + return n; +} -- cgit v1.2.3