Browse Source

New macro 'l_numbits'

Roberto Ierusalimschy 4 months ago
parent
commit
ef5d171cc8
6 changed files with 9 additions and 15 deletions
  1. 1 1
      ldump.c
  2. 2 7
      lfunc.c
  3. 4 2
      llimits.h
  4. 1 1
      ltable.c
  5. 0 3
      ltests.h
  6. 1 1
      lvm.c

+ 1 - 1
ldump.c

@@ -87,7 +87,7 @@ static void dumpByte (DumpState *D, int y) {
 ** size for 'dumpVarint' buffer: each byte can store up to 7 bits.
 ** size for 'dumpVarint' buffer: each byte can store up to 7 bits.
 ** (The "+6" rounds up the division.)
 ** (The "+6" rounds up the division.)
 */
 */
-#define DIBS    ((sizeof(size_t) * CHAR_BIT + 6) / 7)
+#define DIBS    ((l_numbits(size_t) + 6) / 7)
 
 
 /*
 /*
 ** Dumps an unsigned integer using the MSB Varint encoding
 ** Dumps an unsigned integer using the MSB Varint encoding

+ 2 - 7
lfunc.c

@@ -162,13 +162,8 @@ static void prepcallclosemth (lua_State *L, StkId level, TStatus status,
 }
 }
 
 
 
 
-/*
-** Maximum value for deltas in 'tbclist', dependent on the type
-** of delta. (This macro assumes that an 'L' is in scope where it
-** is used.)
-*/
-#define MAXDELTA  \
-	((256ul << ((sizeof(L->stack.p->tbclist.delta) - 1) * 8)) - 1)
+/* Maximum value for deltas in 'tbclist' */
+#define MAXDELTA       USHRT_MAX
 
 
 
 
 /*
 /*

+ 4 - 2
llimits.h

@@ -15,6 +15,8 @@
 #include "lua.h"
 #include "lua.h"
 
 
 
 
+#define l_numbits(t)	cast_int(sizeof(t) * CHAR_BIT)
+
 /*
 /*
 ** 'l_mem' is a signed integer big enough to count the total memory
 ** 'l_mem' is a signed integer big enough to count the total memory
 ** used by Lua.  (It is signed due to the use of debt in several
 ** used by Lua.  (It is signed due to the use of debt in several
@@ -33,7 +35,7 @@ typedef unsigned long lu_mem;
 #endif				/* } */
 #endif				/* } */
 
 
 #define MAX_LMEM  \
 #define MAX_LMEM  \
-	cast(l_mem, (cast(lu_mem, 1) << (sizeof(l_mem) * 8 - 1)) - 1)
+	cast(l_mem, (cast(lu_mem, 1) << (l_numbits(l_mem) - 1)) - 1)
 
 
 
 
 /* chars used as small naturals (so that 'char' is reserved for characters) */
 /* chars used as small naturals (so that 'char' is reserved for characters) */
@@ -61,7 +63,7 @@ typedef lu_byte TStatus;
 ** floor of the log2 of the maximum signed value for integral type 't'.
 ** floor of the log2 of the maximum signed value for integral type 't'.
 ** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
 ** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
 */
 */
-#define log2maxs(t)	cast_int(sizeof(t) * 8 - 2)
+#define log2maxs(t)	(l_numbits(t) - 2)
 
 
 
 
 /*
 /*

+ 1 - 1
ltable.c

@@ -67,7 +67,7 @@ typedef union {
 ** MAXABITS is the largest integer such that 2^MAXABITS fits in an
 ** MAXABITS is the largest integer such that 2^MAXABITS fits in an
 ** unsigned int.
 ** unsigned int.
 */
 */
-#define MAXABITS	cast_int(sizeof(int) * CHAR_BIT - 1)
+#define MAXABITS	(l_numbits(int) - 1)
 
 
 
 
 /*
 /*

+ 0 - 3
ltests.h

@@ -142,9 +142,6 @@ LUA_API void *debug_realloc (void *ud, void *block,
 #define STRCACHE_N	23
 #define STRCACHE_N	23
 #define STRCACHE_M	5
 #define STRCACHE_M	5
 
 
-#undef LUAI_USER_ALIGNMENT_T
-#define LUAI_USER_ALIGNMENT_T   union { char b[sizeof(void*) * 8]; }
-
 
 
 /*
 /*
 ** This one is not compatible with tests for opcode optimizations,
 ** This one is not compatible with tests for opcode optimizations,

+ 1 - 1
lvm.c

@@ -774,7 +774,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
 
 
 
 
 /* number of bits in an integer */
 /* number of bits in an integer */
-#define NBITS	cast_int(sizeof(lua_Integer) * CHAR_BIT)
+#define NBITS	l_numbits(lua_Integer)
 
 
 
 
 /*
 /*