1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /* mips 32-bit arch dependent functions. */
28
emit_copysign(struct sljit_compiler * compiler,sljit_s32 op,sljit_sw src1,sljit_sw src2,sljit_sw dst)29 static sljit_s32 emit_copysign(struct sljit_compiler *compiler, sljit_s32 op,
30 sljit_sw src1, sljit_sw src2, sljit_sw dst)
31 {
32 int is_32 = (op & SLJIT_32);
33 sljit_ins mfhc = MFC1, mthc = MTC1;
34 sljit_ins src1_r = FS(src1), src2_r = FS(src2), dst_r = FS(dst);
35
36 if (!is_32) {
37 switch (cpu_feature_list & CPU_FEATURE_FR) {
38 #if defined(SLJIT_MIPS_REV) && SLJIT_MIPS_REV >= 2
39 case CPU_FEATURE_FR:
40 mfhc = MFHC1;
41 mthc = MTHC1;
42 break;
43 #endif /* SLJIT_MIPS_REV >= 2 */
44 default:
45 src1_r |= (1 << 11);
46 src2_r |= (1 << 11);
47 dst_r |= (1 << 11);
48 break;
49 }
50 }
51
52 FAIL_IF(push_inst(compiler, mfhc | T(TMP_REG1) | src1_r, DR(TMP_REG1)));
53 FAIL_IF(push_inst(compiler, mfhc | T(TMP_REG2) | src2_r, DR(TMP_REG2)));
54 if (!is_32 && src1 != dst)
55 FAIL_IF(push_inst(compiler, MOV_fmt(FMT_S) | FS(src1) | FD(dst), MOVABLE_INS));
56 #if !defined(SLJIT_MIPS_REV) || SLJIT_MIPS_REV <= 1
57 else
58 FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
59 #endif /* MIPS III */
60 FAIL_IF(push_inst(compiler, XOR | T(TMP_REG1) | D(TMP_REG2) | S(TMP_REG2), DR(TMP_REG2)));
61 FAIL_IF(push_inst(compiler, SRL | T(TMP_REG2) | D(TMP_REG2) | SH_IMM(31), DR(TMP_REG2)));
62 FAIL_IF(push_inst(compiler, SLL | T(TMP_REG2) | D(TMP_REG2) | SH_IMM(31), DR(TMP_REG2)));
63 FAIL_IF(push_inst(compiler, XOR | T(TMP_REG2) | D(TMP_REG1) | S(TMP_REG1), DR(TMP_REG1)));
64 FAIL_IF(push_inst(compiler, mthc | T(TMP_REG1) | dst_r, MOVABLE_INS));
65 #if !defined(SLJIT_MIPS_REV) || SLJIT_MIPS_REV <= 1
66 if (mthc == MTC1)
67 return push_inst(compiler, NOP, UNMOVABLE_INS);
68 #endif /* MIPS III */
69 return SLJIT_SUCCESS;
70 }
71
load_immediate(struct sljit_compiler * compiler,sljit_s32 dst_ar,sljit_sw imm)72 static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_ar, sljit_sw imm)
73 {
74 if (!(imm & ~0xffff))
75 return push_inst(compiler, ORI | SA(0) | TA(dst_ar) | IMM(imm), dst_ar);
76
77 if (imm < 0 && imm >= SIMM_MIN)
78 return push_inst(compiler, ADDIU | SA(0) | TA(dst_ar) | IMM(imm), dst_ar);
79
80 FAIL_IF(push_inst(compiler, LUI | TA(dst_ar) | IMM(imm >> 16), dst_ar));
81 return (imm & 0xffff) ? push_inst(compiler, ORI | SA(dst_ar) | TA(dst_ar) | IMM(imm), dst_ar) : SLJIT_SUCCESS;
82 }
83
emit_const(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw init_value)84 static SLJIT_INLINE sljit_s32 emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw init_value)
85 {
86 FAIL_IF(push_inst(compiler, LUI | T(dst) | IMM(init_value >> 16), DR(dst)));
87 return push_inst(compiler, ORI | S(dst) | T(dst) | IMM(init_value), DR(dst));
88 }
89
sljit_emit_fset64(struct sljit_compiler * compiler,sljit_s32 freg,sljit_f64 value)90 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fset64(struct sljit_compiler *compiler,
91 sljit_s32 freg, sljit_f64 value)
92 {
93 union {
94 struct {
95 #if defined(SLJIT_LITTLE_ENDIAN) && SLJIT_LITTLE_ENDIAN
96 sljit_s32 lo;
97 sljit_s32 hi;
98 #else /* !SLJIT_LITTLE_ENDIAN */
99 sljit_s32 hi;
100 sljit_s32 lo;
101 #endif /* SLJIT_LITTLE_ENDIAN */
102 } bin;
103 sljit_f64 value;
104 } u;
105
106 CHECK_ERROR();
107 CHECK(check_sljit_emit_fset64(compiler, freg, value));
108
109 u.value = value;
110
111 if (u.bin.lo != 0)
112 FAIL_IF(load_immediate(compiler, DR(TMP_REG1), u.bin.lo));
113 if (u.bin.hi != 0)
114 FAIL_IF(load_immediate(compiler, DR(TMP_REG2), u.bin.hi));
115
116 FAIL_IF(push_inst(compiler, MTC1 | (u.bin.lo != 0 ? T(TMP_REG1) : TA(0)) | FS(freg), MOVABLE_INS));
117 switch (cpu_feature_list & CPU_FEATURE_FR) {
118 #if defined(SLJIT_MIPS_REV) && SLJIT_MIPS_REV >= 2
119 case CPU_FEATURE_FR:
120 return push_inst(compiler, MTHC1 | (u.bin.hi != 0 ? T(TMP_REG2) : TA(0)) | FS(freg), MOVABLE_INS);
121 #endif /* SLJIT_MIPS_REV >= 2 */
122 default:
123 FAIL_IF(push_inst(compiler, MTC1 | (u.bin.hi != 0 ? T(TMP_REG2) : TA(0)) | FS(freg) | (1 << 11), MOVABLE_INS));
124 break;
125 }
126 #if !defined(SLJIT_MIPS_REV) || SLJIT_MIPS_REV <= 1
127 FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
128 #endif /* MIPS III */
129 return SLJIT_SUCCESS;
130 }
131
sljit_emit_fcopy(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 freg,sljit_s32 reg)132 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fcopy(struct sljit_compiler *compiler, sljit_s32 op,
133 sljit_s32 freg, sljit_s32 reg)
134 {
135 sljit_s32 reg2 = 0;
136 sljit_ins inst = FS(freg);
137 sljit_ins mthc = MTC1, mfhc = MFC1;
138 int is_32 = (op & SLJIT_32);
139
140 CHECK_ERROR();
141 CHECK(check_sljit_emit_fcopy(compiler, op, freg, reg));
142
143 op = GET_OPCODE(op);
144 if (reg & REG_PAIR_MASK) {
145 reg2 = REG_PAIR_SECOND(reg);
146 reg = REG_PAIR_FIRST(reg);
147
148 inst |= T(reg2);
149
150 if (op == SLJIT_COPY_TO_F64)
151 FAIL_IF(push_inst(compiler, MTC1 | inst, MOVABLE_INS));
152 else
153 FAIL_IF(push_inst(compiler, MFC1 | inst, DR(reg2)));
154
155 inst = FS(freg) | (1 << 11);
156 #if defined(SLJIT_MIPS_REV) && SLJIT_MIPS_REV >= 2
157 if (cpu_feature_list & CPU_FEATURE_FR) {
158 mthc = MTHC1;
159 mfhc = MFHC1;
160 inst = FS(freg);
161 }
162 #endif /* SLJIT_MIPS_REV >= 2 */
163 }
164
165 inst |= T(reg);
166 if (!is_32 && !reg2) {
167 switch (cpu_feature_list & CPU_FEATURE_FR) {
168 #if defined(SLJIT_MIPS_REV) && SLJIT_MIPS_REV >= 2
169 case CPU_FEATURE_FR:
170 mthc = MTHC1;
171 mfhc = MFHC1;
172 break;
173 #endif /* SLJIT_MIPS_REV >= 2 */
174 default:
175 inst |= (1 << 11);
176 break;
177 }
178 }
179
180 if (op == SLJIT_COPY_TO_F64)
181 FAIL_IF(push_inst(compiler, mthc | inst, MOVABLE_INS));
182 else
183 FAIL_IF(push_inst(compiler, mfhc | inst, DR(reg)));
184
185 #if !defined(SLJIT_MIPS_REV) || SLJIT_MIPS_REV <= 1
186 if (mthc == MTC1 || mfhc == MFC1)
187 return push_inst(compiler, NOP, UNMOVABLE_INS);
188 #endif /* MIPS III */
189 return SLJIT_SUCCESS;
190 }
191
sljit_set_jump_addr(sljit_uw addr,sljit_uw new_target,sljit_sw executable_offset)192 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
193 {
194 sljit_ins *inst = (sljit_ins *)addr;
195 SLJIT_UNUSED_ARG(executable_offset);
196
197 SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0);
198 SLJIT_ASSERT((inst[0] & 0xffe00000) == LUI && (inst[1] & 0xfc000000) == ORI);
199 inst[0] = (inst[0] & 0xffff0000) | ((new_target >> 16) & 0xffff);
200 inst[1] = (inst[1] & 0xffff0000) | (new_target & 0xffff);
201 SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1);
202 inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset);
203 SLJIT_CACHE_FLUSH(inst, inst + 2);
204 }
205
sljit_set_const(sljit_uw addr,sljit_sw new_constant,sljit_sw executable_offset)206 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
207 {
208 sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset);
209 }
210
call_with_args(struct sljit_compiler * compiler,sljit_s32 arg_types,sljit_ins * ins_ptr,sljit_u32 * extra_space)211 static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_ins *ins_ptr, sljit_u32 *extra_space)
212 {
213 sljit_u32 is_tail_call = *extra_space & SLJIT_CALL_RETURN;
214 sljit_u32 offset = 0;
215 sljit_s32 float_arg_count = 0;
216 sljit_s32 word_arg_count = 0;
217 sljit_s32 types = 0;
218 sljit_ins prev_ins = NOP;
219 sljit_ins ins = NOP;
220 sljit_u8 offsets[4];
221 sljit_u8 *offsets_ptr = offsets;
222 #if defined(SLJIT_LITTLE_ENDIAN) && SLJIT_LITTLE_ENDIAN
223 sljit_ins f64_hi = TA(7), f64_lo = TA(6);
224 #else
225 sljit_ins f64_hi = TA(6), f64_lo = TA(7);
226 #endif /* SLJIT_LITTLE_ENDIAN */
227
228 SLJIT_ASSERT(reg_map[TMP_REG2] == 4 && freg_map[TMP_FREG1] == 12);
229
230 arg_types >>= SLJIT_ARG_SHIFT;
231
232 /* See ABI description in sljit_emit_enter. */
233
234 while (arg_types) {
235 types = (types << SLJIT_ARG_SHIFT) | (arg_types & SLJIT_ARG_MASK);
236 *offsets_ptr = (sljit_u8)offset;
237
238 switch (arg_types & SLJIT_ARG_MASK) {
239 case SLJIT_ARG_TYPE_F64:
240 if (offset & 0x7) {
241 offset += sizeof(sljit_sw);
242 *offsets_ptr = (sljit_u8)offset;
243 }
244
245 if (word_arg_count == 0 && float_arg_count <= 1)
246 *offsets_ptr = (sljit_u8)(254 + float_arg_count);
247
248 offset += sizeof(sljit_f64);
249 float_arg_count++;
250 break;
251 case SLJIT_ARG_TYPE_F32:
252 if (word_arg_count == 0 && float_arg_count <= 1)
253 *offsets_ptr = (sljit_u8)(254 + float_arg_count);
254
255 offset += sizeof(sljit_f32);
256 float_arg_count++;
257 break;
258 default:
259 offset += sizeof(sljit_sw);
260 word_arg_count++;
261 break;
262 }
263
264 arg_types >>= SLJIT_ARG_SHIFT;
265 offsets_ptr++;
266 }
267
268 /* Stack is aligned to 16 bytes. */
269 SLJIT_ASSERT(offset <= 8 * sizeof(sljit_sw));
270
271 if (offset > 4 * sizeof(sljit_sw) && (!is_tail_call || offset > compiler->args_size)) {
272 if (is_tail_call) {
273 offset = (offset + sizeof(sljit_sw) + 15) & ~(sljit_uw)0xf;
274 FAIL_IF(emit_stack_frame_release(compiler, (sljit_s32)offset, &prev_ins));
275 *extra_space = offset;
276 } else {
277 FAIL_IF(push_inst(compiler, ADDIU | S(SLJIT_SP) | T(SLJIT_SP) | IMM(-16), DR(SLJIT_SP)));
278 *extra_space = 16;
279 }
280 } else {
281 if (is_tail_call)
282 FAIL_IF(emit_stack_frame_release(compiler, 0, &prev_ins));
283 *extra_space = 0;
284 }
285
286 while (types) {
287 --offsets_ptr;
288
289 switch (types & SLJIT_ARG_MASK) {
290 case SLJIT_ARG_TYPE_F64:
291 if (*offsets_ptr < 4 * sizeof(sljit_sw)) {
292 if (prev_ins != NOP)
293 FAIL_IF(push_inst(compiler, prev_ins, MOVABLE_INS));
294
295 /* Must be preceded by at least one other argument,
296 * and its starting offset must be 8 because of alignment. */
297 SLJIT_ASSERT((*offsets_ptr >> 2) == 2);
298 switch (cpu_feature_list & CPU_FEATURE_FR) {
299 #if defined(SLJIT_MIPS_REV) && SLJIT_MIPS_REV >= 2
300 case CPU_FEATURE_FR:
301 prev_ins = MFHC1 | f64_hi | FS(float_arg_count);
302 break;
303 #endif /* SLJIT_MIPS_REV >= 2 */
304 default:
305 prev_ins = MFC1 | f64_hi | FS(float_arg_count) | (1 << 11);
306 break;
307 }
308 ins = MFC1 | f64_lo | FS(float_arg_count);
309 } else if (*offsets_ptr < 254)
310 ins = SDC1 | S(SLJIT_SP) | FT(float_arg_count) | IMM(*offsets_ptr);
311 else if (*offsets_ptr == 254)
312 ins = MOV_fmt(FMT_D) | FS(SLJIT_FR0) | FD(TMP_FREG1);
313
314 float_arg_count--;
315 break;
316 case SLJIT_ARG_TYPE_F32:
317 if (*offsets_ptr < 4 * sizeof (sljit_sw))
318 ins = MFC1 | TA(4 + (*offsets_ptr >> 2)) | FS(float_arg_count);
319 else if (*offsets_ptr < 254)
320 ins = SWC1 | S(SLJIT_SP) | FT(float_arg_count) | IMM(*offsets_ptr);
321 else if (*offsets_ptr == 254)
322 ins = MOV_fmt(FMT_S) | FS(SLJIT_FR0) | FD(TMP_FREG1);
323
324 float_arg_count--;
325 break;
326 default:
327 if (*offsets_ptr >= 4 * sizeof (sljit_sw))
328 ins = SW | S(SLJIT_SP) | T(word_arg_count) | IMM(*offsets_ptr);
329 else if ((*offsets_ptr >> 2) != word_arg_count - 1)
330 ins = ADDU | S(word_arg_count) | TA(0) | DA(4 + (*offsets_ptr >> 2));
331 else if (*offsets_ptr == 0)
332 ins = ADDU | S(SLJIT_R0) | TA(0) | DA(4);
333
334 word_arg_count--;
335 break;
336 }
337
338 if (ins != NOP) {
339 if (prev_ins != NOP)
340 FAIL_IF(push_inst(compiler, prev_ins, MOVABLE_INS));
341 prev_ins = ins;
342 ins = NOP;
343 }
344
345 types >>= SLJIT_ARG_SHIFT;
346 }
347
348 *ins_ptr = prev_ins;
349
350 return SLJIT_SUCCESS;
351 }
352
sljit_emit_call(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 arg_types)353 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
354 sljit_s32 arg_types)
355 {
356 struct sljit_jump *jump;
357 sljit_u32 extra_space = 0;
358 sljit_ins ins = NOP;
359
360 CHECK_ERROR_PTR();
361 CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types));
362
363 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
364 PTR_FAIL_IF(!jump);
365 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
366
367 if ((type & 0xff) != SLJIT_CALL_REG_ARG) {
368 extra_space = (sljit_u32)type;
369 PTR_FAIL_IF(call_with_args(compiler, arg_types, &ins, &extra_space));
370 } else if (type & SLJIT_CALL_RETURN)
371 PTR_FAIL_IF(emit_stack_frame_release(compiler, 0, &ins));
372
373 SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25);
374
375 if (ins == NOP && compiler->delay_slot != UNMOVABLE_INS)
376 jump->flags |= IS_MOVABLE;
377
378 if (!(type & SLJIT_CALL_RETURN) || extra_space > 0) {
379 jump->flags |= IS_JAL;
380
381 if ((type & 0xff) != SLJIT_CALL_REG_ARG)
382 jump->flags |= IS_CALL;
383
384 PTR_FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
385 } else
386 PTR_FAIL_IF(push_inst(compiler, JR | S(PIC_ADDR_REG), UNMOVABLE_INS));
387
388 jump->addr = compiler->size;
389 PTR_FAIL_IF(push_inst(compiler, ins, UNMOVABLE_INS));
390
391 /* Maximum number of instructions required for generating a constant. */
392 compiler->size += 2;
393
394 if (extra_space == 0)
395 return jump;
396
397 if (type & SLJIT_CALL_RETURN)
398 PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG,
399 SLJIT_MEM1(SLJIT_SP), (sljit_sw)(extra_space - sizeof(sljit_sw))));
400
401 if (type & SLJIT_CALL_RETURN)
402 PTR_FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS));
403
404 PTR_FAIL_IF(push_inst(compiler, ADDIU | S(SLJIT_SP) | T(SLJIT_SP) | IMM(extra_space),
405 (type & SLJIT_CALL_RETURN) ? UNMOVABLE_INS : DR(SLJIT_SP)));
406 return jump;
407 }
408
sljit_emit_icall(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 arg_types,sljit_s32 src,sljit_sw srcw)409 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
410 sljit_s32 arg_types,
411 sljit_s32 src, sljit_sw srcw)
412 {
413 sljit_u32 extra_space = (sljit_u32)type;
414 sljit_ins ins;
415
416 CHECK_ERROR();
417 CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw));
418
419 if (src & SLJIT_MEM) {
420 ADJUST_LOCAL_OFFSET(src, srcw);
421 FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, DR(PIC_ADDR_REG), src, srcw));
422 src = PIC_ADDR_REG;
423 srcw = 0;
424 }
425
426 if ((type & 0xff) == SLJIT_CALL_REG_ARG) {
427 if (type & SLJIT_CALL_RETURN) {
428 if (src >= SLJIT_FIRST_SAVED_REG && src <= (SLJIT_S0 - SLJIT_KEPT_SAVEDS_COUNT(compiler->options))) {
429 FAIL_IF(push_inst(compiler, ADDU | S(src) | TA(0) | D(PIC_ADDR_REG), DR(PIC_ADDR_REG)));
430 src = PIC_ADDR_REG;
431 srcw = 0;
432 }
433
434 FAIL_IF(emit_stack_frame_release(compiler, 0, &ins));
435
436 if (ins != NOP)
437 FAIL_IF(push_inst(compiler, ins, MOVABLE_INS));
438 }
439
440 SLJIT_SKIP_CHECKS(compiler);
441 return sljit_emit_ijump(compiler, type, src, srcw);
442 }
443
444 SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25);
445
446 if (src == SLJIT_IMM)
447 FAIL_IF(load_immediate(compiler, DR(PIC_ADDR_REG), srcw));
448 else if (src != PIC_ADDR_REG)
449 FAIL_IF(push_inst(compiler, ADDU | S(src) | TA(0) | D(PIC_ADDR_REG), DR(PIC_ADDR_REG)));
450
451 FAIL_IF(call_with_args(compiler, arg_types, &ins, &extra_space));
452
453 /* Register input. */
454 if (!(type & SLJIT_CALL_RETURN) || extra_space > 0)
455 FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
456 else
457 FAIL_IF(push_inst(compiler, JR | S(PIC_ADDR_REG), UNMOVABLE_INS));
458 FAIL_IF(push_inst(compiler, ins, UNMOVABLE_INS));
459
460 if (extra_space == 0)
461 return SLJIT_SUCCESS;
462
463 if (type & SLJIT_CALL_RETURN)
464 FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG,
465 SLJIT_MEM1(SLJIT_SP), (sljit_sw)(extra_space - sizeof(sljit_sw))));
466
467 if (type & SLJIT_CALL_RETURN)
468 FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS));
469
470 return push_inst(compiler, ADDIU | S(SLJIT_SP) | T(SLJIT_SP) | IMM(extra_space),
471 (type & SLJIT_CALL_RETURN) ? UNMOVABLE_INS : DR(SLJIT_SP));
472 }
473