]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Make penalty PRNG available for general use by compiler.
authorMike Pall <mike>
Fri, 26 Feb 2010 16:01:33 +0000 (17:01 +0100)
committerMike Pall <mike>
Fri, 26 Feb 2010 16:01:33 +0000 (17:01 +0100)
src/lj_jit.h
src/lj_trace.c

index f0472282ba525f12e7f02f026856a4a1797bdf56..ff3492bf58a70116086d23b87aef72ce9ffa2e76 100644 (file)
@@ -278,7 +278,7 @@ typedef struct jit_State {
 
   HotPenalty penalty[PENALTY_SLOTS];  /* Penalty slots. */
   uint32_t penaltyslot;        /* Round-robin index into penalty slots. */
-  uint32_t prngstate;  /* PRNG state for penalty randomization. */
+  uint32_t prngstate;  /* PRNG state. */
 
   BPropEntry bpropcache[BPROP_SLOTS];  /* Backpropagation cache slots. */
   uint32_t bpropslot;  /* Round-robin index into bpropcache slots. */
@@ -297,6 +297,14 @@ typedef struct jit_State {
   int mcprot;          /* Protection of current mcode area. */
 } jit_State;
 
+/* Trivial PRNG e.g. used for penalty randomization. */
+static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits)
+{
+  /* Yes, this LCG is very weak, but that doesn't matter for our use case. */
+  J->prngstate = J->prngstate * 1103515245 + 12345;
+  return J->prngstate >> (32-bits);
+}
+
 /* Exit stubs. */
 #if LJ_TARGET_X86ORX64
 /* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */
index e476122c6827bc853bd2dd57fd4fe30f47b7cd22..0b55f717d97ba86451296a963bc79380e44eabff 100644 (file)
@@ -310,14 +310,6 @@ void lj_trace_freestate(global_State *g)
 
 /* -- Penalties and blacklisting ------------------------------------------ */
 
-/* Trivial PRNG for randomization of penalties. */
-static uint32_t penalty_prng(jit_State *J, int bits)
-{
-  /* Yes, this LCG is very weak, but that doesn't matter for our use case. */
-  J->prngstate = J->prngstate * 1103515245 + 12345;
-  return J->prngstate >> (32-bits);
-}
-
 /* Blacklist a bytecode instruction. */
 static void blacklist_pc(GCproto *pt, BCIns *pc)
 {
@@ -333,7 +325,7 @@ static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)
     if (mref(J->penalty[i].pc, const BCIns) == pc) {  /* Cache slot found? */
       /* First try to bump its hotcount several times. */
       val = ((uint32_t)J->penalty[i].val << 1) +
-           penalty_prng(J, PENALTY_RNDBITS);
+           LJ_PRNG_BITS(J, PENALTY_RNDBITS);
       if (val > PENALTY_MAX) {
        blacklist_pc(pt, pc);  /* Blacklist it, if that didn't help. */
        return;