diff options
Diffstat (limited to 'src/lj_ir.c')
-rw-r--r-- | src/lj_ir.c | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/src/lj_ir.c b/src/lj_ir.c index 124d5791..9c0a2224 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
@@ -204,80 +204,6 @@ found: | |||
204 | return TREF(ref, IRT_INT); | 204 | return TREF(ref, IRT_INT); |
205 | } | 205 | } |
206 | 206 | ||
207 | /* The MRef inside the KNUM/KINT64 IR instructions holds the address of the | ||
208 | ** 64 bit constant. The constants themselves are stored in a chained array | ||
209 | ** and shared across traces. | ||
210 | ** | ||
211 | ** Rationale for choosing this data structure: | ||
212 | ** - The address of the constants is embedded in the generated machine code | ||
213 | ** and must never move. A resizable array or hash table wouldn't work. | ||
214 | ** - Most apps need very few non-32 bit integer constants (less than a dozen). | ||
215 | ** - Linear search is hard to beat in terms of speed and low complexity. | ||
216 | */ | ||
217 | typedef struct K64Array { | ||
218 | MRef next; /* Pointer to next list. */ | ||
219 | MSize numk; /* Number of used elements in this array. */ | ||
220 | TValue k[LJ_MIN_K64SZ]; /* Array of constants. */ | ||
221 | } K64Array; | ||
222 | |||
223 | /* Free all chained arrays. */ | ||
224 | void lj_ir_k64_freeall(jit_State *J) | ||
225 | { | ||
226 | K64Array *k; | ||
227 | for (k = mref(J->k64p, K64Array); k; ) { | ||
228 | K64Array *next = mref(k->next, K64Array); | ||
229 | lj_mem_free(J2G(J), k, sizeof(K64Array)); | ||
230 | k = next; | ||
231 | } | ||
232 | setmref(J->k64p, NULL); | ||
233 | } | ||
234 | |||
235 | /* Get new 64 bit constant slot. */ | ||
236 | static TValue *ir_k64_add(jit_State *J, K64Array *kp, uint64_t u64) | ||
237 | { | ||
238 | TValue *ntv; | ||
239 | if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */ | ||
240 | K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array); | ||
241 | setmref(kn->next, NULL); | ||
242 | kn->numk = 0; | ||
243 | if (kp) | ||
244 | setmref(kp->next, kn); /* Chain to the end of the list. */ | ||
245 | else | ||
246 | setmref(J->k64p, kn); /* Link first array. */ | ||
247 | kp = kn; | ||
248 | } | ||
249 | ntv = &kp->k[kp->numk++]; /* Add to current array. */ | ||
250 | ntv->u64 = u64; | ||
251 | return ntv; | ||
252 | } | ||
253 | |||
254 | /* Find 64 bit constant in chained array or add it. */ | ||
255 | cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64) | ||
256 | { | ||
257 | K64Array *k, *kp = NULL; | ||
258 | MSize idx; | ||
259 | /* Search for the constant in the whole chain of arrays. */ | ||
260 | for (k = mref(J->k64p, K64Array); k; k = mref(k->next, K64Array)) { | ||
261 | kp = k; /* Remember previous element in list. */ | ||
262 | for (idx = 0; idx < k->numk; idx++) { /* Search one array. */ | ||
263 | TValue *tv = &k->k[idx]; | ||
264 | if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */ | ||
265 | return tv; | ||
266 | } | ||
267 | } | ||
268 | /* Otherwise add a new constant. */ | ||
269 | return ir_k64_add(J, kp, u64); | ||
270 | } | ||
271 | |||
272 | TValue *lj_ir_k64_reserve(jit_State *J) | ||
273 | { | ||
274 | K64Array *k, *kp = NULL; | ||
275 | lj_ir_k64_find(J, 0); /* Intern dummy 0 to protect the reserved slot. */ | ||
276 | /* Find last K64Array, if any. */ | ||
277 | for (k = mref(J->k64p, K64Array); k; k = mref(k->next, K64Array)) kp = k; | ||
278 | return ir_k64_add(J, kp, 0); /* Set to 0. Final value is set later. */ | ||
279 | } | ||
280 | |||
281 | /* Intern 64 bit constant, given by its 64 bit pattern. */ | 207 | /* Intern 64 bit constant, given by its 64 bit pattern. */ |
282 | TRef lj_ir_k64(jit_State *J, IROp op, uint64_t u64) | 208 | TRef lj_ir_k64(jit_State *J, IROp op, uint64_t u64) |
283 | { | 209 | { |