aboutsummaryrefslogtreecommitdiff
path: root/lgc.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-20 16:25:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-20 16:25:20 -0300
commitad0ea7813b39e76b377983138ca995189e22054f (patch)
tree087e3585a4b4bf5ae65f56b9599bbff9c361a123 /lgc.h
parent666e95a66d1a2ceb98bdf320980b3f655264a9c9 (diff)
downloadlua-ad0ea7813b39e76b377983138ca995189e22054f.tar.gz
lua-ad0ea7813b39e76b377983138ca995189e22054f.tar.bz2
lua-ad0ea7813b39e76b377983138ca995189e22054f.zip
GC parameters encoded as floating-point bytes
This encoding brings more precision and a larger range for these parameters.
Diffstat (limited to 'lgc.h')
-rw-r--r--lgc.h20
1 files changed, 4 insertions, 16 deletions
diff --git a/lgc.h b/lgc.h
index e8dee8a0..6a03f787 100644
--- a/lgc.h
+++ b/lgc.h
@@ -189,10 +189,12 @@
189 for each new allocated object.) */ 189 for each new allocated object.) */
190#define LUAI_GCMUL 200 190#define LUAI_GCMUL 200
191 191
192/* How many objects to allocate before next GC step (log2) */ 192/* How many objects to allocate before next GC step */
193#define LUAI_GCSTEPSIZE 8 /* 256 objects */ 193#define LUAI_GCSTEPSIZE 250
194 194
195 195
196#define setgcparam(g,p,v) if ((v) >= 0) {g->p = luaO_codeparam(v);}
197
196/* 198/*
197** Control when GC is running: 199** Control when GC is running:
198*/ 200*/
@@ -201,20 +203,6 @@
201#define GCSTPCLS 4 /* bit true when closing Lua state */ 203#define GCSTPCLS 4 /* bit true when closing Lua state */
202#define gcrunning(g) ((g)->gcstp == 0) 204#define gcrunning(g) ((g)->gcstp == 0)
203 205
204/*
205** Macros to set and apply GC parameters. GC parameters are given in
206** percentage points, but are stored as lu_byte. To avoid repeated
207** divisions by 100, these macros store the original parameter
208** multiplied by 128 and divided by 100. To apply them, if it first
209** divides the value by 128 it may lose precision; if it first
210** multiplies by the parameter, it may overflow. So, it first divides
211** by 32, then multiply by the parameter, and then divides the result by
212** 4.
213*/
214
215#define setgcparam(g,p,v) (g->gcp##p = (cast_uint(v) << 7) / 100u)
216#define applygcparam(g,p,v) ((((v) >> 5) * g->gcp##p) >> 2)
217
218 206
219/* 207/*
220** Does one step of collection when debt becomes zero. 'pre'/'pos' 208** Does one step of collection when debt becomes zero. 'pre'/'pos'