diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-13 16:17:21 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-13 16:17:21 -0300 |
commit | 279c3a6961c60252f0368fdea889caf977f85fe0 (patch) | |
tree | 1614c0b508f34657f81d155dec6dffd92e671479 /lopcodes.h | |
parent | 49c42f3615bd876657bf697e3bf040ce796ae238 (diff) | |
download | lua-279c3a6961c60252f0368fdea889caf977f85fe0.tar.gz lua-279c3a6961c60252f0368fdea889caf977f85fe0.tar.bz2 lua-279c3a6961c60252f0368fdea889caf977f85fe0.zip |
A few changes in tests about number of bits in integers
- The preprocessor must work with at least 'long', and therefore must
do shifts of up to 31 bits correctly.
- Whenever possible, use unsigned types in shifts.
Diffstat (limited to 'lopcodes.h')
-rw-r--r-- | lopcodes.h | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -57,12 +57,18 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ | |||
57 | 57 | ||
58 | #define POS_sJ POS_A | 58 | #define POS_sJ POS_A |
59 | 59 | ||
60 | |||
60 | /* | 61 | /* |
61 | ** limits for opcode arguments. | 62 | ** limits for opcode arguments. |
62 | ** we use (signed) int to manipulate most arguments, | 63 | ** we use (signed) 'int' to manipulate most arguments, |
63 | ** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) | 64 | ** so they must fit in ints. |
64 | */ | 65 | */ |
65 | #if SIZE_Bx < LUAI_BITSINT-1 | 66 | |
67 | /* Check whether type 'int' has at least 'b' bits ('b' < 32) */ | ||
68 | #define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1) | ||
69 | |||
70 | |||
71 | #if L_INTHASBITS(SIZE_Bx) | ||
66 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) | 72 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) |
67 | #else | 73 | #else |
68 | #define MAXARG_Bx MAX_INT | 74 | #define MAXARG_Bx MAX_INT |
@@ -71,13 +77,13 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ | |||
71 | #define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ | 77 | #define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ |
72 | 78 | ||
73 | 79 | ||
74 | #if SIZE_Ax < LUAI_BITSINT-1 | 80 | #if L_INTHASBITS(SIZE_Ax) |
75 | #define MAXARG_Ax ((1<<SIZE_Ax)-1) | 81 | #define MAXARG_Ax ((1<<SIZE_Ax)-1) |
76 | #else | 82 | #else |
77 | #define MAXARG_Ax MAX_INT | 83 | #define MAXARG_Ax MAX_INT |
78 | #endif | 84 | #endif |
79 | 85 | ||
80 | #if SIZE_sJ < LUAI_BITSINT-1 | 86 | #if L_INTHASBITS(SIZE_sJ) |
81 | #define MAXARG_sJ ((1 << SIZE_sJ) - 1) | 87 | #define MAXARG_sJ ((1 << SIZE_sJ) - 1) |
82 | #else | 88 | #else |
83 | #define MAXARG_sJ MAX_INT | 89 | #define MAXARG_sJ MAX_INT |