aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2010-02-24 23:17:17 +0100
committerMike Pall <mike>2010-02-24 23:17:17 +0100
commitb95294572ce8efa527e0b0118bb7168117afd171 (patch)
tree1aa393c982f67b4e558805b12ca5b3f4c26509cb /src
parentb32f4f4549b94ea18da1d5b2280c8b6ba0089a9b (diff)
downloadluajit-b95294572ce8efa527e0b0118bb7168117afd171.tar.gz
luajit-b95294572ce8efa527e0b0118bb7168117afd171.tar.bz2
luajit-b95294572ce8efa527e0b0118bb7168117afd171.zip
Move SIMD constants to jit_State to keep them in the low 4GB.
Diffstat (limited to 'src')
-rw-r--r--src/lj_ir.c7
-rw-r--r--src/lj_iropt.h7
-rw-r--r--src/lj_jit.h28
-rw-r--r--src/lj_state.c1
-rw-r--r--src/lj_trace.c14
-rw-r--r--src/lj_trace.h2
6 files changed, 41 insertions, 18 deletions
diff --git a/src/lj_ir.c b/src/lj_ir.c
index 30ac026b..602be31a 100644
--- a/src/lj_ir.c
+++ b/src/lj_ir.c
@@ -235,6 +235,7 @@ TRef lj_ir_knum_addr(jit_State *J, cTValue *tv)
235 goto found; 235 goto found;
236 ref = ir_nextk(J); 236 ref = ir_nextk(J);
237 ir = IR(ref); 237 ir = IR(ref);
238 lua_assert(checkptr32(tv));
238 setmref(ir->ptr, tv); 239 setmref(ir->ptr, tv);
239 ir->t.irt = IRT_NUM; 240 ir->t.irt = IRT_NUM;
240 ir->o = IR_KNUM; 241 ir->o = IR_KNUM;
@@ -250,12 +251,6 @@ TRef lj_ir_knum_nn(jit_State *J, uint64_t nn)
250 return lj_ir_knum_addr(J, ir_knum_find(J, nn)); 251 return lj_ir_knum_addr(J, ir_knum_find(J, nn));
251} 252}
252 253
253/* Special 16 byte aligned SIMD constants. */
254LJ_DATADEF LJ_ALIGN(16) cTValue lj_ir_knum_tv[4] = {
255 { U64x(7fffffff,ffffffff) }, { U64x(7fffffff,ffffffff) },
256 { U64x(80000000,00000000) }, { U64x(80000000,00000000) }
257};
258
259/* Check whether a number is int and return it. -0 is NOT considered an int. */ 254/* Check whether a number is int and return it. -0 is NOT considered an int. */
260static int numistrueint(lua_Number n, int32_t *kp) 255static int numistrueint(lua_Number n, int32_t *kp)
261{ 256{
diff --git a/src/lj_iropt.h b/src/lj_iropt.h
index 947fa820..1884892a 100644
--- a/src/lj_iropt.h
+++ b/src/lj_iropt.h
@@ -64,10 +64,9 @@ static LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n)
64#define lj_ir_knum_one(J) lj_ir_knum_nn(J, U64x(3ff00000,00000000)) 64#define lj_ir_knum_one(J) lj_ir_knum_nn(J, U64x(3ff00000,00000000))
65#define lj_ir_knum_tobit(J) lj_ir_knum_nn(J, U64x(43380000,00000000)) 65#define lj_ir_knum_tobit(J) lj_ir_knum_nn(J, U64x(43380000,00000000))
66 66
67/* Special 16 byte aligned SIMD constants. */ 67/* Special 128 bit SIMD constants. */
68LJ_DATA LJ_ALIGN(16) cTValue lj_ir_knum_tv[4]; 68#define lj_ir_knum_abs(J) lj_ir_knum_addr(J, LJ_KSIMD(J, LJ_KSIMD_ABS))
69#define lj_ir_knum_abs(J) lj_ir_knum_addr(J, &lj_ir_knum_tv[0]) 69#define lj_ir_knum_neg(J) lj_ir_knum_addr(J, LJ_KSIMD(J, LJ_KSIMD_NEG))
70#define lj_ir_knum_neg(J) lj_ir_knum_addr(J, &lj_ir_knum_tv[2])
71 70
72/* Access to constants. */ 71/* Access to constants. */
73LJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir); 72LJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir);
diff --git a/src/lj_jit.h b/src/lj_jit.h
index 23adf30d..f0472282 100644
--- a/src/lj_jit.h
+++ b/src/lj_jit.h
@@ -201,6 +201,17 @@ typedef struct BPropEntry {
201/* Number of slots for the backpropagation cache. Must be a power of 2. */ 201/* Number of slots for the backpropagation cache. Must be a power of 2. */
202#define BPROP_SLOTS 16 202#define BPROP_SLOTS 16
203 203
204/* 128 bit SIMD constants. */
205enum {
206 LJ_KSIMD_ABS,
207 LJ_KSIMD_NEG,
208 LJ_KSIMD__MAX
209};
210
211/* Get 16 byte aligned pointer to SIMD constant. */
212#define LJ_KSIMD(J, n) \
213 ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15))
214
204/* Fold state is used to fold instructions on-the-fly. */ 215/* Fold state is used to fold instructions on-the-fly. */
205typedef struct FoldState { 216typedef struct FoldState {
206 IRIns ins; /* Currently emitted instruction. */ 217 IRIns ins; /* Currently emitted instruction. */
@@ -214,21 +225,21 @@ typedef struct jit_State {
214 225
215 lua_State *L; /* Current Lua state. */ 226 lua_State *L; /* Current Lua state. */
216 const BCIns *pc; /* Current PC. */ 227 const BCIns *pc; /* Current PC. */
217 BCReg maxslot; /* Relative to baseslot. */
218
219 uint32_t flags; /* JIT engine flags. */
220 TRef *base; /* Current frame base, points into J->slots. */
221 BCReg baseslot; /* Current frame base, offset into J->slots. */
222 GCfunc *fn; /* Current function. */ 228 GCfunc *fn; /* Current function. */
223 GCproto *pt; /* Current prototype. */ 229 GCproto *pt; /* Current prototype. */
230 TRef *base; /* Current frame base, points into J->slots. */
224 231
225 FoldState fold; /* Fold state. */ 232 uint32_t flags; /* JIT engine flags. */
233 BCReg maxslot; /* Relative to baseslot. */
234 BCReg baseslot; /* Current frame base, offset into J->slots. */
226 235
227 uint8_t mergesnap; /* Allowed to merge with next snapshot. */ 236 uint8_t mergesnap; /* Allowed to merge with next snapshot. */
228 uint8_t needsnap; /* Need snapshot before recording next bytecode. */ 237 uint8_t needsnap; /* Need snapshot before recording next bytecode. */
229 IRType1 guardemit; /* Accumulated IRT_GUARD for emitted instructions. */ 238 IRType1 guardemit; /* Accumulated IRT_GUARD for emitted instructions. */
230 uint8_t unused1; 239 uint8_t unused1;
231 240
241 FoldState fold; /* Fold state. */
242
232 const BCIns *bc_min; /* Start of allowed bytecode range for root trace. */ 243 const BCIns *bc_min; /* Start of allowed bytecode range for root trace. */
233 MSize bc_extent; /* Extent of the range. */ 244 MSize bc_extent; /* Extent of the range. */
234 245
@@ -241,19 +252,20 @@ typedef struct jit_State {
241 int32_t retdepth; /* Return frame depth (count of RETF). */ 252 int32_t retdepth; /* Return frame depth (count of RETF). */
242 253
243 MRef knum; /* Pointer to chained array of KNUM constants. */ 254 MRef knum; /* Pointer to chained array of KNUM constants. */
255 TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */
244 256
245 IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */ 257 IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */
246 IRRef irtoplim; /* Upper limit of instuction buffer (biased). */ 258 IRRef irtoplim; /* Upper limit of instuction buffer (biased). */
247 IRRef irbotlim; /* Lower limit of instuction buffer (biased). */ 259 IRRef irbotlim; /* Lower limit of instuction buffer (biased). */
248 IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */ 260 IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */
249 261
262 MSize sizesnap; /* Size of temp. snapshot buffer. */
250 SnapShot *snapbuf; /* Temp. snapshot buffer. */ 263 SnapShot *snapbuf; /* Temp. snapshot buffer. */
251 SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */ 264 SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */
252 MSize sizesnap; /* Size of temp. snapshot buffer. */
253 MSize sizesnapmap; /* Size of temp. snapshot map buffer. */ 265 MSize sizesnapmap; /* Size of temp. snapshot map buffer. */
254 266
255 Trace **trace; /* Array of traces. */
256 TraceNo curtrace; /* Current trace number (if not 0). Kept in J->cur. */ 267 TraceNo curtrace; /* Current trace number (if not 0). Kept in J->cur. */
268 Trace **trace; /* Array of traces. */
257 TraceNo freetrace; /* Start of scan for next free trace. */ 269 TraceNo freetrace; /* Start of scan for next free trace. */
258 MSize sizetrace; /* Size of trace array. */ 270 MSize sizetrace; /* Size of trace array. */
259 271
diff --git a/src/lj_state.c b/src/lj_state.c
index 8f8be97b..3305fd18 100644
--- a/src/lj_state.c
+++ b/src/lj_state.c
@@ -134,6 +134,7 @@ static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud)
134 lj_lex_init(L); 134 lj_lex_init(L);
135 fixstring(lj_err_str(L, LJ_ERR_ERRMEM)); /* Preallocate memory error msg. */ 135 fixstring(lj_err_str(L, LJ_ERR_ERRMEM)); /* Preallocate memory error msg. */
136 g->gc.threshold = 4*g->gc.total; 136 g->gc.threshold = 4*g->gc.total;
137 lj_trace_initstate(g);
137 return NULL; 138 return NULL;
138} 139}
139 140
diff --git a/src/lj_trace.c b/src/lj_trace.c
index d55d3a85..e476122c 100644
--- a/src/lj_trace.c
+++ b/src/lj_trace.c
@@ -275,6 +275,20 @@ int lj_trace_flushall(lua_State *L)
275 return 0; 275 return 0;
276} 276}
277 277
278/* Initialize JIT compiler state. */
279void lj_trace_initstate(global_State *g)
280{
281 jit_State *J = G2J(g);
282 TValue *tv;
283 /* Initialize SIMD constants. */
284 tv = LJ_KSIMD(J, LJ_KSIMD_ABS);
285 tv[0].u64 = U64x(7fffffff,ffffffff);
286 tv[1].u64 = U64x(7fffffff,ffffffff);
287 tv = LJ_KSIMD(J, LJ_KSIMD_NEG);
288 tv[0].u64 = U64x(80000000,00000000);
289 tv[1].u64 = U64x(80000000,00000000);
290}
291
278/* Free everything associated with the JIT compiler state. */ 292/* Free everything associated with the JIT compiler state. */
279void lj_trace_freestate(global_State *g) 293void lj_trace_freestate(global_State *g)
280{ 294{
diff --git a/src/lj_trace.h b/src/lj_trace.h
index 6944bd9c..4d19454f 100644
--- a/src/lj_trace.h
+++ b/src/lj_trace.h
@@ -28,6 +28,7 @@ LJ_FUNC void lj_trace_reenableproto(GCproto *pt);
28LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt); 28LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt);
29LJ_FUNC int lj_trace_flush(jit_State *J, TraceNo traceno); 29LJ_FUNC int lj_trace_flush(jit_State *J, TraceNo traceno);
30LJ_FUNC int lj_trace_flushall(lua_State *L); 30LJ_FUNC int lj_trace_flushall(lua_State *L);
31LJ_FUNC void lj_trace_initstate(global_State *g);
31LJ_FUNC void lj_trace_freestate(global_State *g); 32LJ_FUNC void lj_trace_freestate(global_State *g);
32 33
33/* Event handling. */ 34/* Event handling. */
@@ -42,6 +43,7 @@ LJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr);
42#else 43#else
43 44
44#define lj_trace_flushall(L) (UNUSED(L), 0) 45#define lj_trace_flushall(L) (UNUSED(L), 0)
46#define lj_trace_initstate(g) UNUSED(g)
45#define lj_trace_freestate(g) UNUSED(g) 47#define lj_trace_freestate(g) UNUSED(g)
46#define lj_trace_freeproto(g, pt) (UNUSED(g), UNUSED(pt), (void)0) 48#define lj_trace_freeproto(g, pt) (UNUSED(g), UNUSED(pt), (void)0)
47#define lj_trace_abort(g) UNUSED(g) 49#define lj_trace_abort(g) UNUSED(g)