summaryrefslogtreecommitdiff
path: root/src/flexdef.h
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2017-02-12 19:59:52 +0800
committerWill Estes <westes575@gmail.com>2017-02-16 13:26:21 -0500
commitc7a545ae0907c81cf52139dd391659586570f60c (patch)
treeedf686d64f473abea392aee425521a22116d9f11 /src/flexdef.h
parent122e58965acaf67386d1fc6893f069bd27e5aa26 (diff)
scanner: compute powers of two faster.
Replace the naive "for" loop in determining power of two with a clever bitwise solution. This code is around the Internet already and is in Public Domain.
Diffstat (limited to 'src/flexdef.h')
-rw-r--r--src/flexdef.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/flexdef.h b/src/flexdef.h
index 97aec14..e5ab8e0 100644
--- a/src/flexdef.h
+++ b/src/flexdef.h
@@ -109,6 +109,8 @@
#define ABS(x) ((x) < 0 ? -(x) : (x))
#endif
+/* Whether an integer is a power of two */
+#define is_power_of_2(n) ((n) > 0 && ((n) & ((n) - 1)) == 0)
#define unspecified -1