GC parameters encoded as floating-point bytes

This encoding brings more precision and a larger range for these
parameters.
This commit is contained in:
Roberto Ierusalimschy
2023-12-20 16:25:20 -03:00
parent 666e95a66d
commit ad0ea7813b
8 changed files with 113 additions and 57 deletions

20
lgc.h
View File

@@ -189,10 +189,12 @@
for each new allocated object.) */
#define LUAI_GCMUL 200
/* How many objects to allocate before next GC step (log2) */
#define LUAI_GCSTEPSIZE 8 /* 256 objects */
/* How many objects to allocate before next GC step */
#define LUAI_GCSTEPSIZE 250
#define setgcparam(g,p,v) if ((v) >= 0) {g->p = luaO_codeparam(v);}
/*
** Control when GC is running:
*/
@@ -201,20 +203,6 @@
#define GCSTPCLS 4 /* bit true when closing Lua state */
#define gcrunning(g) ((g)->gcstp == 0)
/*
** Macros to set and apply GC parameters. GC parameters are given in
** percentage points, but are stored as lu_byte. To avoid repeated
** divisions by 100, these macros store the original parameter
** multiplied by 128 and divided by 100. To apply them, if it first
** divides the value by 128 it may lose precision; if it first
** multiplies by the parameter, it may overflow. So, it first divides
** by 32, then multiply by the parameter, and then divides the result by
** 4.
*/
#define setgcparam(g,p,v) (g->gcp##p = (cast_uint(v) << 7) / 100u)
#define applygcparam(g,p,v) ((((v) >> 5) * g->gcp##p) >> 2)
/*
** Does one step of collection when debt becomes zero. 'pre'/'pos'