summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-09-19 10:48:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-21 01:13:54 -0700
commit1d8fcfcd0d1b93d04ea5adcb980ffac38bd3d140 (patch)
tree0eb4927a778fa1ff4899c1738ecfafefaf487622 /include
parentdbfb5c1deeb6ee54663baaee6052849b8cba5bd5 (diff)
downloadchrome-ec-1d8fcfcd0d1b93d04ea5adcb980ffac38bd3d140.tar.gz
common: Add __fls function
Returns the most significant bit set. Replace 31 - __builtin_clz(x), so x must be different from 0. Use get_next_bit when not on the performance path, on performance path set the bit field just after reading it. BRANCH=smaug BUG=none TEST=compile, check Ryu still works. Change-Id: Ie1a4cda4188f45b4bf92d0549d5c8fb401a30e5d Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/301300
Diffstat (limited to 'include')
-rw-r--r--include/gpio.h2
-rw-r--r--include/util.h5
2 files changed, 5 insertions, 2 deletions
diff --git a/include/gpio.h b/include/gpio.h
index 2e7555d241..31f68b1c4b 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -47,7 +47,7 @@
#define GPIO_INT_BOTH_DSLEEP (GPIO_INT_BOTH | GPIO_INT_DSLEEP)
/* Convert GPIO mask to GPIO number / index. */
-#define GPIO_MASK_TO_NUM(mask) (31 - __builtin_clz(mask))
+#define GPIO_MASK_TO_NUM(mask) (__fls(mask))
/* Convert a GPIO to a port + mask pair */
#define GPIO_TO_PORT_MASK_PAIR(gpio) \
diff --git a/include/util.h b/include/util.h
index 86c7a8dc0c..8fec4a14e8 100644
--- a/include/util.h
+++ b/include/util.h
@@ -77,7 +77,10 @@
/* True of x is a power of two */
#define POWER_OF_TWO(x) (x && !(x & (x - 1)))
-/**
+/* find the most significant bit. Not defined in n == 0. */
+#define __fls(n) (31 - __builtin_clz(n))
+
+/*
* macros for integer division with various rounding variants
* default integer division rounds down.
*/