diff options
Diffstat (limited to 'src/lj_ir.c')
-rw-r--r-- | src/lj_ir.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/lj_ir.c b/src/lj_ir.c index 9682e05e..567aec86 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
@@ -209,24 +209,13 @@ void lj_ir_k64_freeall(jit_State *J) | |||
209 | lj_mem_free(J2G(J), k, sizeof(K64Array)); | 209 | lj_mem_free(J2G(J), k, sizeof(K64Array)); |
210 | k = next; | 210 | k = next; |
211 | } | 211 | } |
212 | setmref(J->k64, NULL); | ||
212 | } | 213 | } |
213 | 214 | ||
214 | /* Find 64 bit constant in chained array or add it. */ | 215 | /* Get new 64 bit constant slot. */ |
215 | cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64) | 216 | static TValue *ir_k64_add(jit_State *J, K64Array *kp, uint64_t u64) |
216 | { | 217 | { |
217 | K64Array *k, *kp = NULL; | ||
218 | TValue *ntv; | 218 | TValue *ntv; |
219 | MSize idx; | ||
220 | /* Search for the constant in the whole chain of arrays. */ | ||
221 | for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) { | ||
222 | kp = k; /* Remember previous element in list. */ | ||
223 | for (idx = 0; idx < k->numk; idx++) { /* Search one array. */ | ||
224 | TValue *tv = &k->k[idx]; | ||
225 | if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */ | ||
226 | return tv; | ||
227 | } | ||
228 | } | ||
229 | /* Constant was not found, need to add it. */ | ||
230 | if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */ | 219 | if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */ |
231 | K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array); | 220 | K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array); |
232 | setmref(kn->next, NULL); | 221 | setmref(kn->next, NULL); |
@@ -242,6 +231,33 @@ cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64) | |||
242 | return ntv; | 231 | return ntv; |
243 | } | 232 | } |
244 | 233 | ||
234 | /* Find 64 bit constant in chained array or add it. */ | ||
235 | cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64) | ||
236 | { | ||
237 | K64Array *k, *kp = NULL; | ||
238 | MSize idx; | ||
239 | /* Search for the constant in the whole chain of arrays. */ | ||
240 | for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) { | ||
241 | kp = k; /* Remember previous element in list. */ | ||
242 | for (idx = 0; idx < k->numk; idx++) { /* Search one array. */ | ||
243 | TValue *tv = &k->k[idx]; | ||
244 | if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */ | ||
245 | return tv; | ||
246 | } | ||
247 | } | ||
248 | /* Otherwise add a new constant. */ | ||
249 | return ir_k64_add(J, kp, u64); | ||
250 | } | ||
251 | |||
252 | TValue *lj_ir_k64_reserve(jit_State *J) | ||
253 | { | ||
254 | K64Array *k, *kp = NULL; | ||
255 | lj_ir_k64_find(J, 0); /* Intern dummy 0 to protect the reserved slot. */ | ||
256 | /* Find last K64Array, if any. */ | ||
257 | for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) kp = k; | ||
258 | return ir_k64_add(J, kp, 0); /* Set to 0. Final value is set later. */ | ||
259 | } | ||
260 | |||
245 | /* Intern 64 bit constant, given by its address. */ | 261 | /* Intern 64 bit constant, given by its address. */ |
246 | TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv) | 262 | TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv) |
247 | { | 263 | { |