aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorRichard Carlsson <richardc@klarna.com>2017-04-27 14:44:10 +0200
committerRichard Carlsson <richardc@klarna.com>2017-04-27 14:48:40 +0200
commit282a7cab9989abb7a1b2daca7aec907d53163ff4 (patch)
treeae66254176af7dd2d8e48668cdcd178521dd4636 /erts
parentd9c2e78d4e7b6166245e79a70bd4d95c8a1b742a (diff)
downloadotp-282a7cab9989abb7a1b2daca7aec907d53163ff4.tar.gz
otp-282a7cab9989abb7a1b2daca7aec907d53163ff4.tar.bz2
otp-282a7cab9989abb7a1b2daca7aec907d53163ff4.zip
Rename macro and add clarifying comment
The macro previously named 'LOG2' is in fact computing the LSB (not the MSB) of its input, and can only be used to compute log2(n) when n is is a power of 2, that is, when its LSB is also its MSB.
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/sys/common/erl_mseg.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/erts/emulator/sys/common/erl_mseg.c b/erts/emulator/sys/common/erl_mseg.c
index d1895f3793..1e99078906 100644
--- a/erts/emulator/sys/common/erl_mseg.c
+++ b/erts/emulator/sys/common/erl_mseg.c
@@ -83,12 +83,13 @@ static const int debruijn[32] = {
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
-#define LOG2(X) (debruijn[((Uint32)(((X) & -(X)) * 0x077CB531U)) >> 27])
+#define LSB(X) (debruijn[((Uint32)(((X) & -(X)) * 0x077CB531U)) >> 27])
#define CACHE_AREAS (32 - MSEG_ALIGN_BITS)
/* FIXME: segment sizes > 2 GB result in bogus negative indices */
-#define SIZE_TO_CACHE_AREA_IDX(S) (LOG2((S)) - MSEG_ALIGN_BITS)
+/* NOTE: using LSB instead of proper log2 only works if S is a power of 2 */
+#define SIZE_TO_CACHE_AREA_IDX(S) (LSB((S)) - MSEG_ALIGN_BITS)
#define MAX_CACHE_SIZE (30)
#define MSEG_FLG_IS_2POW(X) ((X) & ERTS_MSEG_FLG_2POW)