1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - gregimm.c *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2002 Hacktarux *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25 #include "interpret.h"
27 #include "r4300/recomph.h"
28 #include "r4300/recomp.h"
29 #include "r4300/r4300.h"
30 #include "r4300/ops.h"
31 #include "r4300/macros.h"
33 #include "memory/memory.h"
35 static void genbltz_test(void)
37 int rs_64bit = is64((unsigned int *)dst->f.i.rs);
41 int rs = allocate_register((unsigned int *)dst->f.i.rs);
43 cmp_reg32_imm32(rs, 0);
45 mov_m32_imm32((unsigned int *)(&branch_taken), 1); // 10
46 jmp_imm_short(10); // 2
47 mov_m32_imm32((unsigned int *)(&branch_taken), 0); // 10
49 else if (rs_64bit == -1)
51 cmp_m32_imm32(((unsigned int *)dst->f.i.rs)+1, 0);
53 mov_m32_imm32((unsigned int *)(&branch_taken), 1); // 10
54 jmp_imm_short(10); // 2
55 mov_m32_imm32((unsigned int *)(&branch_taken), 0); // 10
59 int rs2 = allocate_64_register2((unsigned int *)dst->f.i.rs);
61 cmp_reg32_imm32(rs2, 0);
63 mov_m32_imm32((unsigned int *)(&branch_taken), 1); // 10
64 jmp_imm_short(10); // 2
65 mov_m32_imm32((unsigned int *)(&branch_taken), 0); // 10
72 gencallinterp((unsigned int)cached_interpreter_table.BLTZ, 1);
74 if (((dst->addr & 0xFFF) == 0xFFC &&
75 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
77 gencallinterp((unsigned int)cached_interpreter_table.BLTZ, 1);
87 void genbltz_out(void)
89 #ifdef INTERPRET_BLTZ_OUT
90 gencallinterp((unsigned int)cached_interpreter_table.BLTZ_OUT, 1);
92 if (((dst->addr & 0xFFF) == 0xFFC &&
93 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
95 gencallinterp((unsigned int)cached_interpreter_table.BLTZ_OUT, 1);
105 void genbltz_idle(void)
107 #ifdef INTERPRET_BLTZ_IDLE
108 gencallinterp((unsigned int)cached_interpreter_table.BLTZ_IDLE, 1);
110 if (((dst->addr & 0xFFF) == 0xFFC &&
111 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
113 gencallinterp((unsigned int)cached_interpreter_table.BLTZ_IDLE, 1);
123 static void genbgez_test(void)
125 int rs_64bit = is64((unsigned int *)dst->f.i.rs);
129 int rs = allocate_register((unsigned int *)dst->f.i.rs);
131 cmp_reg32_imm32(rs, 0);
133 mov_m32_imm32((unsigned int *)(&branch_taken), 1); // 10
134 jmp_imm_short(10); // 2
135 mov_m32_imm32((unsigned int *)(&branch_taken), 0); // 10
137 else if (rs_64bit == -1)
139 cmp_m32_imm32(((unsigned int *)dst->f.i.rs)+1, 0);
141 mov_m32_imm32((unsigned int *)(&branch_taken), 1); // 10
142 jmp_imm_short(10); // 2
143 mov_m32_imm32((unsigned int *)(&branch_taken), 0); // 10
147 int rs2 = allocate_64_register2((unsigned int *)dst->f.i.rs);
149 cmp_reg32_imm32(rs2, 0);
151 mov_m32_imm32((unsigned int *)(&branch_taken), 1); // 10
152 jmp_imm_short(10); // 2
153 mov_m32_imm32((unsigned int *)(&branch_taken), 0); // 10
159 #ifdef INTERPRET_BGEZ
160 gencallinterp((unsigned int)cached_interpreter_table.BGEZ, 1);
162 if (((dst->addr & 0xFFF) == 0xFFC &&
163 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
165 gencallinterp((unsigned int)cached_interpreter_table.BGEZ, 1);
175 void genbgez_out(void)
177 #ifdef INTERPRET_BGEZ_OUT
178 gencallinterp((unsigned int)cached_interpreter_table.BGEZ_OUT, 1);
180 if (((dst->addr & 0xFFF) == 0xFFC &&
181 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
183 gencallinterp((unsigned int)cached_interpreter_table.BGEZ_OUT, 1);
193 void genbgez_idle(void)
195 #ifdef INTERPRET_BGEZ_IDLE
196 gencallinterp((unsigned int)cached_interpreter_table.BGEZ_IDLE, 1);
198 if (((dst->addr & 0xFFF) == 0xFFC &&
199 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
201 gencallinterp((unsigned int)cached_interpreter_table.BGEZ_IDLE, 1);
213 #ifdef INTERPRET_BLTZL
214 gencallinterp((unsigned int)cached_interpreter_table.BLTZL, 1);
216 if (((dst->addr & 0xFFF) == 0xFFC &&
217 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
219 gencallinterp((unsigned int)cached_interpreter_table.BLTZL, 1);
224 free_all_registers();
229 void genbltzl_out(void)
231 #ifdef INTERPRET_BLTZL_OUT
232 gencallinterp((unsigned int)cached_interpreter_table.BLTZL_OUT, 1);
234 if (((dst->addr & 0xFFF) == 0xFFC &&
235 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
237 gencallinterp((unsigned int)cached_interpreter_table.BLTZL_OUT, 1);
242 free_all_registers();
247 void genbltzl_idle(void)
249 #ifdef INTERPRET_BLTZL_IDLE
250 gencallinterp((unsigned int)cached_interpreter_table.BLTZL_IDLE, 1);
252 if (((dst->addr & 0xFFF) == 0xFFC &&
253 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
255 gencallinterp((unsigned int)cached_interpreter_table.BLTZL_IDLE, 1);
267 #ifdef INTERPRET_BGEZL
268 gencallinterp((unsigned int)cached_interpreter_table.BGEZL, 1);
270 if (((dst->addr & 0xFFF) == 0xFFC &&
271 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
273 gencallinterp((unsigned int)cached_interpreter_table.BGEZL, 1);
278 free_all_registers();
283 void genbgezl_out(void)
285 #ifdef INTERPRET_BGEZL_OUT
286 gencallinterp((unsigned int)cached_interpreter_table.BGEZL_OUT, 1);
288 if (((dst->addr & 0xFFF) == 0xFFC &&
289 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
291 gencallinterp((unsigned int)cached_interpreter_table.BGEZL_OUT, 1);
296 free_all_registers();
301 void genbgezl_idle(void)
303 #ifdef INTERPRET_BGEZL_IDLE
304 gencallinterp((unsigned int)cached_interpreter_table.BGEZL_IDLE, 1);
306 if (((dst->addr & 0xFFF) == 0xFFC &&
307 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
309 gencallinterp((unsigned int)cached_interpreter_table.BGEZL_IDLE, 1);
319 static void genbranchlink(void)
321 int r31_64bit = is64((unsigned int*)®[31]);
325 int r31 = allocate_register_w((unsigned int *)®[31]);
327 mov_reg32_imm32(r31, dst->addr+8);
329 else if (r31_64bit == -1)
331 mov_m32_imm32((unsigned int *)®[31], dst->addr + 8);
332 if (dst->addr & 0x80000000)
333 mov_m32_imm32(((unsigned int *)®[31])+1, 0xFFFFFFFF);
335 mov_m32_imm32(((unsigned int *)®[31])+1, 0);
339 int r311 = allocate_64_register1_w((unsigned int *)®[31]);
340 int r312 = allocate_64_register2_w((unsigned int *)®[31]);
342 mov_reg32_imm32(r311, dst->addr+8);
343 if (dst->addr & 0x80000000)
344 mov_reg32_imm32(r312, 0xFFFFFFFF);
346 mov_reg32_imm32(r312, 0);
352 #ifdef INTERPRET_BLTZAL
353 gencallinterp((unsigned int)cached_interpreter_table.BLTZAL, 1);
355 if (((dst->addr & 0xFFF) == 0xFFC &&
356 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
358 gencallinterp((unsigned int)cached_interpreter_table.BLTZAL, 1);
369 void genbltzal_out(void)
371 #ifdef INTERPRET_BLTZAL_OUT
372 gencallinterp((unsigned int)cached_interpreter_table.BLTZAL_OUT, 1);
374 if (((dst->addr & 0xFFF) == 0xFFC &&
375 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
377 gencallinterp((unsigned int)cached_interpreter_table.BLTZAL_OUT, 1);
388 void genbltzal_idle(void)
390 #ifdef INTERPRET_BLTZAL_IDLE
391 gencallinterp((unsigned int)cached_interpreter_table.BLTZAL_IDLE, 1);
393 if (((dst->addr & 0xFFF) == 0xFFC &&
394 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
396 gencallinterp((unsigned int)cached_interpreter_table.BLTZAL_IDLE, 1);
409 #ifdef INTERPRET_BGEZAL
410 gencallinterp((unsigned int)cached_interpreter_table.BGEZAL, 1);
412 if (((dst->addr & 0xFFF) == 0xFFC &&
413 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
415 gencallinterp((unsigned int)cached_interpreter_table.BGEZAL, 1);
426 void genbgezal_out(void)
428 #ifdef INTERPRET_BGEZAL_OUT
429 gencallinterp((unsigned int)cached_interpreter_table.BGEZAL_OUT, 1);
431 if (((dst->addr & 0xFFF) == 0xFFC &&
432 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
434 gencallinterp((unsigned int)cached_interpreter_table.BGEZAL_OUT, 1);
445 void genbgezal_idle(void)
447 #ifdef INTERPRET_BGEZAL_IDLE
448 gencallinterp((unsigned int)cached_interpreter_table.BGEZAL_IDLE, 1);
450 if (((dst->addr & 0xFFF) == 0xFFC &&
451 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
453 gencallinterp((unsigned int)cached_interpreter_table.BGEZAL_IDLE, 1);
464 void genbltzall(void)
466 #ifdef INTERPRET_BLTZALL
467 gencallinterp((unsigned int)cached_interpreter_table.BLTZALL, 1);
469 if (((dst->addr & 0xFFF) == 0xFFC &&
470 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
472 gencallinterp((unsigned int)cached_interpreter_table.BLTZALL, 1);
478 free_all_registers();
483 void genbltzall_out(void)
485 #ifdef INTERPRET_BLTZALL_OUT
486 gencallinterp((unsigned int)cached_interpreter_table.BLTZALL_OUT, 1);
488 if (((dst->addr & 0xFFF) == 0xFFC &&
489 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
491 gencallinterp((unsigned int)cached_interpreter_table.BLTZALL_OUT, 1);
497 free_all_registers();
502 void genbltzall_idle(void)
504 #ifdef INTERPRET_BLTZALL_IDLE
505 gencallinterp((unsigned int)cached_interpreter_table.BLTZALL_IDLE, 1);
507 if (((dst->addr & 0xFFF) == 0xFFC &&
508 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
510 gencallinterp((unsigned int)cached_interpreter_table.BLTZALL_IDLE, 1);
521 void genbgezall(void)
523 #ifdef INTERPRET_BGEZALL
524 gencallinterp((unsigned int)cached_interpreter_table.BGEZALL, 1);
526 if (((dst->addr & 0xFFF) == 0xFFC &&
527 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
529 gencallinterp((unsigned int)cached_interpreter_table.BGEZALL, 1);
535 free_all_registers();
540 void genbgezall_out(void)
542 #ifdef INTERPRET_BGEZALL_OUT
543 gencallinterp((unsigned int)cached_interpreter_table.BGEZALL_OUT, 1);
545 if (((dst->addr & 0xFFF) == 0xFFC &&
546 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
548 gencallinterp((unsigned int)cached_interpreter_table.BGEZALL_OUT, 1);
554 free_all_registers();
559 void genbgezall_idle(void)
561 #ifdef INTERPRET_BGEZALL_IDLE
562 gencallinterp((unsigned int)cached_interpreter_table.BGEZALL_IDLE, 1);
564 if (((dst->addr & 0xFFF) == 0xFFC &&
565 (dst->addr < 0x80000000 || dst->addr >= 0xC0000000))||no_compiled_jump)
567 gencallinterp((unsigned int)cached_interpreter_table.BGEZALL_IDLE, 1);