From ff7f7a7180d25da9d425671a48867b50bb7e7ac2 Mon Sep 17 00:00:00 2001
From: Mike Pall <mike>
Date: Sat, 22 Oct 2011 01:35:57 +0200
Subject: Cleanup various endianess issues in assembler backend.

---
 src/lj_asm.c        | 31 +++++++++++++++++--------------
 src/lj_asm_arm.h    |  6 +++---
 src/lj_asm_x86.h    |  4 ++--
 src/lj_ir.h         |  2 +-
 src/lj_opt_split.c  |  2 +-
 src/lj_target_arm.h |  1 +
 src/lj_target_x86.h |  1 +
 7 files changed, 26 insertions(+), 21 deletions(-)

(limited to 'src')

diff --git a/src/lj_asm.c b/src/lj_asm.c
index b12b7466..4187a1d9 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -703,14 +703,14 @@ static void ra_leftov(ASMState *as, Reg dest, IRRef lref)
 #endif
 
 #if !LJ_TARGET_X86ORX64
-/* Force a RID_RET/RID_RETHI destination register pair (marked as free). */
+/* Force a RID_RETLO/RID_RETHI destination register pair (marked as free). */
 static void ra_destpair(ASMState *as, IRIns *ir)
 {
   Reg destlo = ir->r, desthi = (ir+1)->r;
   /* First spill unrelated refs blocking the destination registers. */
-  if (!rset_test(as->freeset, RID_RET) &&
-      destlo != RID_RET && desthi != RID_RET)
-    ra_restore(as, regcost_ref(as->cost[RID_RET]));
+  if (!rset_test(as->freeset, RID_RETLO) &&
+      destlo != RID_RETLO && desthi != RID_RETLO)
+    ra_restore(as, regcost_ref(as->cost[RID_RETLO]));
   if (!rset_test(as->freeset, RID_RETHI) &&
       destlo != RID_RETHI && desthi != RID_RETHI)
     ra_restore(as, regcost_ref(as->cost[RID_RETHI]));
@@ -719,7 +719,7 @@ static void ra_destpair(ASMState *as, IRIns *ir)
     ra_free(as, destlo);
     ra_modified(as, destlo);
   } else {
-    destlo = RID_RET;
+    destlo = RID_RETLO;
   }
   if (ra_hasreg(desthi)) {
     ra_free(as, desthi);
@@ -729,24 +729,24 @@ static void ra_destpair(ASMState *as, IRIns *ir)
   }
   /* Check for conflicts and shuffle the registers as needed. */
   if (destlo == RID_RETHI) {
-    if (desthi == RID_RET) {
+    if (desthi == RID_RETLO) {
       emit_movrr(as, ir, RID_RETHI, RID_TMP);
-      emit_movrr(as, ir, RID_RET, RID_RETHI);
-      emit_movrr(as, ir, RID_TMP, RID_RET);
+      emit_movrr(as, ir, RID_RETLO, RID_RETHI);
+      emit_movrr(as, ir, RID_TMP, RID_RETLO);
     } else {
-      emit_movrr(as, ir, RID_RETHI, RID_RET);
+      emit_movrr(as, ir, RID_RETHI, RID_RETLO);
       if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI);
     }
-  } else if (desthi == RID_RET) {
-    emit_movrr(as, ir, RID_RET, RID_RETHI);
-    if (destlo != RID_RET) emit_movrr(as, ir, destlo, RID_RET);
+  } else if (desthi == RID_RETLO) {
+    emit_movrr(as, ir, RID_RETLO, RID_RETHI);
+    if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO);
   } else {
     if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI);
-    if (destlo != RID_RET) emit_movrr(as, ir, destlo, RID_RET);
+    if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO);
   }
   /* Restore spill slots (if any). */
   if (ra_hasspill((ir+1)->s)) ra_save(as, ir+1, RID_RETHI);
-  if (ra_hasspill(ir->s)) ra_save(as, ir, RID_RET);
+  if (ra_hasspill(ir->s)) ra_save(as, ir, RID_RETLO);
 }
 #endif
 
@@ -1519,6 +1519,9 @@ static void asm_setup_regsp(ASMState *as)
       case IR_CALLN: case IR_CALLXS:
 #if LJ_SOFTFP
       case IR_MIN: case IR_MAX:
+#endif
+#if LJ_BE
+	(ir-1)->prev = REGSP_HINT(RID_RETLO);
 #endif
 	ir->prev = REGSP_HINT(RID_RETHI);
 	continue;
diff --git a/src/lj_asm_arm.h b/src/lj_asm_arm.h
index 9da618ce..20c5d40a 100644
--- a/src/lj_asm_arm.h
+++ b/src/lj_asm_arm.h
@@ -516,7 +516,7 @@ static void asm_href(ASMState *as, IRIns *ir, IROp merge)
   int destused = ra_used(ir);
   Reg dest = ra_dest(as, ir, allow);
   Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
-  Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_LR;
+  Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP;
   IRRef refkey = ir->op2;
   IRIns *irkey = IR(refkey);
   IRType1 kt = irkey->t;
@@ -1213,7 +1213,7 @@ static void asm_fpmin_max(ASMState *as, IRIns *ir, int cc)
   ra_evictset(as, drop);
   ra_destpair(as, ir);
   emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETHI, RID_R3);
-  emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RET, RID_R2);
+  emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETLO, RID_R2);
   emit_call(as, (void *)ci->func);
   for (r = RID_R0; r <= RID_R3; r++)
     ra_leftov(as, r, args[r-RID_R0]);
@@ -1407,7 +1407,7 @@ static void asm_hiop(ASMState *as, IRIns *ir)
   case IR_CALLS:
   case IR_CALLXS:
     if (!uselo)
-      ra_allocref(as, ir->op1, RID2RSET(RID_RET));  /* Mark lo op as used. */
+      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */
     break;
   case IR_ASTORE: case IR_HSTORE: case IR_USTORE:
   case IR_TOSTR: case IR_CNEWI:
diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h
index 21ab7c25..ae90309b 100644
--- a/src/lj_asm_x86.h
+++ b/src/lj_asm_x86.h
@@ -479,7 +479,7 @@ static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
 		  dest, RID_ESP, ofs);
       }
       if ((ci->flags & CCI_CASTU64)) {
-	emit_movtomro(as, RID_RET, RID_ESP, ofs);
+	emit_movtomro(as, RID_RETLO, RID_ESP, ofs);
 	emit_movtomro(as, RID_RETHI, RID_ESP, ofs+4);
       } else {
 	emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,
@@ -2180,7 +2180,7 @@ static void asm_hiop(ASMState *as, IRIns *ir)
   case IR_CALLXS:
     ra_destreg(as, ir, RID_RETHI);
     if (!uselo)
-      ra_allocref(as, ir->op1, RID2RSET(RID_RET));  /* Mark call as used. */
+      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark call as used. */
     break;
   case IR_CNEWI:
     /* Nothing to do here. Handled by CNEWI itself. */
diff --git a/src/lj_ir.h b/src/lj_ir.h
index 1c9c90d7..7a9f1a9c 100644
--- a/src/lj_ir.h
+++ b/src/lj_ir.h
@@ -195,7 +195,7 @@ IRFPMDEF(FPMENUM)
   _(CDATA_TYPEID, offsetof(GCcdata, typeid)) \
   _(CDATA_PTR,	sizeof(GCcdata)) \
   _(CDATA_INT64, sizeof(GCcdata)) \
-  _(CDATA_INT64HI, sizeof(GCcdata) + 4)
+  _(CDATA_INT64_4, sizeof(GCcdata) + 4)
 
 typedef enum {
 #define FLENUM(name, ofs)	IRFL_##name,
diff --git a/src/lj_opt_split.c b/src/lj_opt_split.c
index 1ea2c057..61275b03 100644
--- a/src/lj_opt_split.c
+++ b/src/lj_opt_split.c
@@ -411,7 +411,7 @@ static void split_ir(jit_State *J)
 	break;
       case IR_FLOAD:
 	lua_assert(ir->op2 == IRFL_CDATA_INT64);
-	hi = split_emit(J, IRTI(IR_FLOAD), nir->op1, IRFL_CDATA_INT64HI);
+	hi = split_emit(J, IRTI(IR_FLOAD), nir->op1, IRFL_CDATA_INT64_4);
 #if LJ_BE
 	ir->prev = hi; hi = nref;
 #endif
diff --git a/src/lj_target_arm.h b/src/lj_target_arm.h
index 78a5679d..210fe497 100644
--- a/src/lj_target_arm.h
+++ b/src/lj_target_arm.h
@@ -28,6 +28,7 @@ enum {
 
   /* Calling conventions. */
   RID_RET = RID_R0,
+  RID_RETLO = RID_R0,
   RID_RETHI = RID_R1,
   RID_FPRET = RID_R0,
 
diff --git a/src/lj_target_x86.h b/src/lj_target_x86.h
index 34b247d4..c4445ba4 100644
--- a/src/lj_target_x86.h
+++ b/src/lj_target_x86.h
@@ -37,6 +37,7 @@ enum {
 #if LJ_64
   RID_FPRET = RID_XMM0,
 #else
+  RID_RETLO = RID_EAX,
   RID_RETHI = RID_EDX,
 #endif
 
-- 
cgit v1.2.3-55-g6feb