diff options
author | Mike Pall <mike> | 2010-02-26 17:01:33 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-02-26 17:01:33 +0100 |
commit | a0fbb05bf0353ac0fede6deec15db5d2d3a9017f (patch) | |
tree | 5e4ad50a8ea9bcd1d030ffa736aba46a1d6bb161 /src | |
parent | 3c6cec0846ae25dc9d0c2495cb02316694725add (diff) | |
download | luajit-a0fbb05bf0353ac0fede6deec15db5d2d3a9017f.tar.gz luajit-a0fbb05bf0353ac0fede6deec15db5d2d3a9017f.tar.bz2 luajit-a0fbb05bf0353ac0fede6deec15db5d2d3a9017f.zip |
Make penalty PRNG available for general use by compiler.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_jit.h | 10 | ||||
-rw-r--r-- | src/lj_trace.c | 10 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/lj_jit.h b/src/lj_jit.h index f0472282..ff3492bf 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h | |||
@@ -278,7 +278,7 @@ typedef struct jit_State { | |||
278 | 278 | ||
279 | HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */ | 279 | HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */ |
280 | uint32_t penaltyslot; /* Round-robin index into penalty slots. */ | 280 | uint32_t penaltyslot; /* Round-robin index into penalty slots. */ |
281 | uint32_t prngstate; /* PRNG state for penalty randomization. */ | 281 | uint32_t prngstate; /* PRNG state. */ |
282 | 282 | ||
283 | BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ | 283 | BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ |
284 | uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ | 284 | uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ |
@@ -297,6 +297,14 @@ typedef struct jit_State { | |||
297 | int mcprot; /* Protection of current mcode area. */ | 297 | int mcprot; /* Protection of current mcode area. */ |
298 | } jit_State; | 298 | } jit_State; |
299 | 299 | ||
300 | /* Trivial PRNG e.g. used for penalty randomization. */ | ||
301 | static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits) | ||
302 | { | ||
303 | /* Yes, this LCG is very weak, but that doesn't matter for our use case. */ | ||
304 | J->prngstate = J->prngstate * 1103515245 + 12345; | ||
305 | return J->prngstate >> (32-bits); | ||
306 | } | ||
307 | |||
300 | /* Exit stubs. */ | 308 | /* Exit stubs. */ |
301 | #if LJ_TARGET_X86ORX64 | 309 | #if LJ_TARGET_X86ORX64 |
302 | /* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */ | 310 | /* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */ |
diff --git a/src/lj_trace.c b/src/lj_trace.c index e476122c..0b55f717 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c | |||
@@ -310,14 +310,6 @@ void lj_trace_freestate(global_State *g) | |||
310 | 310 | ||
311 | /* -- Penalties and blacklisting ------------------------------------------ */ | 311 | /* -- Penalties and blacklisting ------------------------------------------ */ |
312 | 312 | ||
313 | /* Trivial PRNG for randomization of penalties. */ | ||
314 | static uint32_t penalty_prng(jit_State *J, int bits) | ||
315 | { | ||
316 | /* Yes, this LCG is very weak, but that doesn't matter for our use case. */ | ||
317 | J->prngstate = J->prngstate * 1103515245 + 12345; | ||
318 | return J->prngstate >> (32-bits); | ||
319 | } | ||
320 | |||
321 | /* Blacklist a bytecode instruction. */ | 313 | /* Blacklist a bytecode instruction. */ |
322 | static void blacklist_pc(GCproto *pt, BCIns *pc) | 314 | static void blacklist_pc(GCproto *pt, BCIns *pc) |
323 | { | 315 | { |
@@ -333,7 +325,7 @@ static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e) | |||
333 | if (mref(J->penalty[i].pc, const BCIns) == pc) { /* Cache slot found? */ | 325 | if (mref(J->penalty[i].pc, const BCIns) == pc) { /* Cache slot found? */ |
334 | /* First try to bump its hotcount several times. */ | 326 | /* First try to bump its hotcount several times. */ |
335 | val = ((uint32_t)J->penalty[i].val << 1) + | 327 | val = ((uint32_t)J->penalty[i].val << 1) + |
336 | penalty_prng(J, PENALTY_RNDBITS); | 328 | LJ_PRNG_BITS(J, PENALTY_RNDBITS); |
337 | if (val > PENALTY_MAX) { | 329 | if (val > PENALTY_MAX) { |
338 | blacklist_pc(pt, pc); /* Blacklist it, if that didn't help. */ | 330 | blacklist_pc(pt, pc); /* Blacklist it, if that didn't help. */ |
339 | return; | 331 | return; |