#include "vm/jit/mips/codegen.h"
#include "vm/jit/mips/md-abi.h"
-#include "mm/memory.h"
+#include "mm/memory.hpp"
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
-#include "vm/builtin.h"
+#include "vm/jit/builtin.hpp"
#include "vm/options.h"
#include "vm/jit/abi.h"
#include "vm/jit/abi-asm.h"
#include "vm/jit/asmpart.h"
#include "vm/jit/dseg.h"
-#include "vm/jit/emit-common.h"
+#include "vm/jit/emit-common.hpp"
#include "vm/jit/jit.hpp"
-#include "vm/jit/patcher-common.h"
-#include "vm/jit/replace.h"
-#include "vm/jit/trap.h"
+#include "vm/jit/patcher-common.hpp"
+#include "vm/jit/replace.hpp"
+#include "vm/jit/trap.hpp"
/* emit_load *******************************************************************
void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt)
{
- s4 checkdisp;
- s4 branchdisp;
-
- /* calculate the different displacements */
-
- checkdisp = (disp - 4);
- branchdisp = (disp - 4) >> 2;
+ // Calculate the displacements.
+ int32_t checkdisp = (disp - 4);
+ int32_t branchdisp = (disp - 4) >> 2;
/* check which branch to generate */
if (condition == BRANCH_UNCONDITIONAL) {
- /* check displacement for overflow */
-
- if ((checkdisp < (s4) 0xffff8000) || (checkdisp > (s4) 0x00007fff)) {
+ // Check displacement for overflow.
+ if (opt_AlwaysEmitLongBranches || ((checkdisp < (int32_t) 0xffff8000) || (checkdisp > (int32_t) 0x00007fff))) {
/* if the long-branches flag isn't set yet, do it */
if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
CODEGENDATA_FLAG_LONGBRANCHES);
}
- vm_abort("emit_branch: emit unconditional long-branch code");
+ // Calculate the offset relative to PV.
+ int32_t currentrpc = cd->mcodeptr - cd->mcodebase;
+ int32_t offset = currentrpc + disp;
+
+ // Sanity check.
+ assert(offset % 4 == 0);
+
+ // Do the long-branch.
+ M_LUI(REG_ITMP3, offset >> 16);
+ M_OR_IMM(REG_ITMP3, offset, REG_ITMP3);
+ M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
+ M_JMP(REG_ITMP3);
+ M_NOP;
+ M_NOP; // This nop is to have 6 instructions (see BRANCH_NOPS).
}
else {
M_BR(branchdisp);
}
}
else {
- /* and displacement for overflow */
-
- if ((checkdisp < (s4) 0xffff8000) || (checkdisp > (s4) 0x00007fff)) {
+ // Check displacement for overflow.
+ if (opt_AlwaysEmitLongBranches || ((checkdisp < (int32_t) 0xffff8000) || (checkdisp > (int32_t) 0x00007fff))) {
/* if the long-branches flag isn't set yet, do it */
if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
CODEGENDATA_FLAG_LONGBRANCHES);
}
+ // Calculate the offset relative to PV before we generate
+ // new code.
+ int32_t currentrpc = cd->mcodeptr - cd->mcodebase;
+ int32_t offset = currentrpc + disp;
+
+ // Sanity check.
+ assert(offset % 4 == 0);
+
switch (condition) {
case BRANCH_EQ:
M_BNE(GET_HIGH_REG(reg), GET_LOW_REG(reg), 5);
vm_abort("emit_branch: unknown condition %d", condition);
}
- /* The actual branch code which is over-jumped (NOTE: we
- don't use a branch delay slot here). */
+ // The actual branch code which is over-jumped. NOTE: We
+ // don't use a branch delay slot for the conditional
+ // branch.
- M_LUI(REG_ITMP3, branchdisp >> 16);
- M_OR_IMM(REG_ITMP3, branchdisp, REG_ITMP3);
+ // Do the long-branch.
+ M_LUI(REG_ITMP3, offset >> 16);
+ M_OR_IMM(REG_ITMP3, offset, REG_ITMP3);
M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
M_JMP(REG_ITMP3);
M_NOP;
-
}
else {
switch (condition) {
uint32_t emit_trap(codegendata *cd)
{
- uint32_t mcode;
-
- /* Get machine code which is patched back in later. The
- trap is 1 instruction word long. */
-
- mcode = *((uint32_t *) cd->mcodeptr);
+ // Get machine code which is patched back in later. The trap is 1
+ // instruction word long.
+ uint32_t mcode = *((uint32_t*) cd->mcodeptr);
- M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_PATCHER);
+ M_RESERVED;
return mcode;
}