New macro 'l_numbits'

This commit is contained in:
Roberto Ierusalimschy 2025-03-27 12:38:29 -03:00
parent b0f3df16a4
commit ef5d171cc8
6 changed files with 9 additions and 15 deletions

View file

@ -87,7 +87,7 @@ static void dumpByte (DumpState *D, int y) {
** size for 'dumpVarint' buffer: each byte can store up to 7 bits.
** (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

View file

@ -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
/*

View file

@ -15,6 +15,8 @@
#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
** used by Lua. (It is signed due to the use of debt in several
@ -33,7 +35,7 @@ typedef unsigned long lu_mem;
#endif /* } */
#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) */
@ -61,7 +63,7 @@ typedef lu_byte TStatus;
** 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.)
*/
#define log2maxs(t) cast_int(sizeof(t) * 8 - 2)
#define log2maxs(t) (l_numbits(t) - 2)
/*

View file

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

View file

@ -142,9 +142,6 @@ LUA_API void *debug_realloc (void *ud, void *block,
#define STRCACHE_N 23
#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,

2
lvm.c
View file

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