diff options
author | Björn Gustavsson <[email protected]> | 2017-10-01 07:02:44 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2017-10-01 07:02:44 +0200 |
commit | f75fa8129fcd18fc56407778960252e6c10a3a37 (patch) | |
tree | ce8b3ed6fe4b46ac142cb2d88ea0dc5a3c776377 /erts/emulator/beam/big.h | |
parent | 87deee8a9513714317ce7b620d3260314aad3f1e (diff) | |
parent | 281ae7c2cf7e2dfd48cf50b2f68fd76f7c6ab0e2 (diff) | |
download | otp-f75fa8129fcd18fc56407778960252e6c10a3a37.tar.gz otp-f75fa8129fcd18fc56407778960252e6c10a3a37.tar.bz2 otp-f75fa8129fcd18fc56407778960252e6c10a3a37.zip |
Merge pull request #1583 from bjorng/bjorn/erts/simplify-is_ssmall
Eliminate MY_IS_SSMALL()
Diffstat (limited to 'erts/emulator/beam/big.h')
-rw-r--r-- | erts/emulator/beam/big.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/erts/emulator/beam/big.h b/erts/emulator/beam/big.h index 48efce20e7..7556205063 100644 --- a/erts/emulator/beam/big.h +++ b/erts/emulator/beam/big.h @@ -70,7 +70,20 @@ typedef Uint dsize_t; /* Vector size type */ /* Check for small */ #define IS_USMALL(sgn,x) ((sgn) ? ((x) <= MAX_SMALL+1) : ((x) <= MAX_SMALL)) -#define IS_SSMALL(x) (((x) >= MIN_SMALL) && ((x) <= MAX_SMALL)) + +/* + * It seems that both clang and gcc will generate sub-optimal code + * for the more obvious way to write the range check: + * + * #define IS_SSMALL(x) (((x) >= MIN_SMALL) && ((x) <= MAX_SMALL)) + * + * Note that IS_SSMALL() may be used in the 32-bit emulator with + * a Uint64 argument. Therefore, we must test the size of the argument + * to ensure that the cast does not discard the high-order 32 bits. + */ +#define _IS_SSMALL32(x) (((Uint32) ((((x)) >> (SMALL_BITS-1)) + 1)) < 2) +#define _IS_SSMALL64(x) (((Uint64) ((((x)) >> (SMALL_BITS-1)) + 1)) < 2) +#define IS_SSMALL(x) (sizeof(x) == sizeof(Uint32) ? _IS_SSMALL32(x) : _IS_SSMALL64(x)) /* The heap size needed for a bignum */ #define BIG_NEED_SIZE(x) ((x) + 1) |