From 279c3a6961c60252f0368fdea889caf977f85fe0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 May 2019 16:17:21 -0300 Subject: 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. --- lopcodes.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lopcodes.h') diff --git a/lopcodes.h b/lopcodes.h index bbdd6897..a314dcd1 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -57,12 +57,18 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ #define POS_sJ POS_A + /* ** limits for opcode arguments. -** we use (signed) int to manipulate most arguments, -** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) +** we use (signed) 'int' to manipulate most arguments, +** so they must fit in ints. */ -#if SIZE_Bx < LUAI_BITSINT-1 + +/* Check whether type 'int' has at least 'b' bits ('b' < 32) */ +#define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1) + + +#if L_INTHASBITS(SIZE_Bx) #define MAXARG_Bx ((1<>1) /* 'sBx' is signed */ -#if SIZE_Ax < LUAI_BITSINT-1 +#if L_INTHASBITS(SIZE_Ax) #define MAXARG_Ax ((1<