summaryrefslogtreecommitdiff
path: root/nasmlib.h
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2010-04-21 16:43:20 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2010-04-21 16:43:20 -0700
commit084b13227e7f5597666391b9cc7dcc9cb91a2657 (patch)
tree5c1fb372a20bf8354780fc898f6b4887d768bdea /nasmlib.h
parent34543131ca11f7881329e869c695c06184309afe (diff)
downloadnasm-084b13227e7f5597666391b9cc7dcc9cb91a2657.tar.gz
nasm-084b13227e7f5597666391b9cc7dcc9cb91a2657.tar.bz2
nasm-084b13227e7f5597666391b9cc7dcc9cb91a2657.zip
Add generic ilog2 functions
Add ilog2_{32,64}() and alignlog2_{32,64}() ... the latter is intended for alignment statements and return -1 for non-power-of-2 other than 0 (which returns 0). Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'nasmlib.h')
-rw-r--r--nasmlib.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/nasmlib.h b/nasmlib.h
index 5efb0b4..02876c7 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -463,4 +463,16 @@ int idata_bytes(int opcode);
/* check if value is power of 2 */
#define is_power2(v) ((v) && ((v) & ((v) - 1)) == 0)
+/*
+ * floor(log2(v))
+ */
+int ilog2_32(uint32_t v);
+int ilog2_64(uint64_t v);
+
+/*
+ * v == 0 ? 0 : is_power2(x) ? ilog2_X(v) : -1
+ */
+int alignlog2_32(uint32_t v);
+int alignlog2_64(uint64_t v);
+
#endif