Patchwork [v4,29/33] tcg-aarch64: Use symbolic names for branches

login
register
mail settings
Submitter Richard Henderson
Date Sept. 14, 2013, 9:54 p.m.
Message ID <1379195690-6509-30-git-send-email-rth@twiddle.net>
Download mbox | patch
Permalink /patch/274977/
State New
Headers show

Comments

Richard Henderson - Sept. 14, 2013, 9:54 p.m.
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 tcg/aarch64/tcg-target.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

Patch

diff --git a/tcg/aarch64/tcg-target.c b/tcg/aarch64/tcg-target.c
index 3d1108c..335a5d0 100644
--- a/tcg/aarch64/tcg-target.c
+++ b/tcg/aarch64/tcg-target.c
@@ -327,6 +327,14 @@  typedef enum {
     /* PC relative addressing instructions */
     INSN_ADR   = 0x10000000,
     INSN_ADRP  = 0x90000000,
+
+    /* Branch instructions */
+    INSN_B     = 0x14000000,
+    INSN_BL    = 0x94000000,
+    INSN_BR    = 0xd61f0000,
+    INSN_BLR   = 0xd63f0000,
+    INSN_RET   = 0xd65f0000,
+    INSN_B_C   = 0x54000000,
 } AArch64Insn;
 
 static inline enum aarch64_ldst_op_data
@@ -837,15 +845,14 @@  static void tcg_out_cmp(TCGContext *s, TCGType ext, TCGReg a,
 
 static inline void tcg_out_goto(TCGContext *s, tcg_target_long target)
 {
-    tcg_target_long offset;
-    offset = (target - (tcg_target_long)s->code_ptr) / 4;
+    tcg_target_long offset = (target - (tcg_target_long)s->code_ptr) / 4;
 
     if (offset < -0x02000000 || offset >= 0x02000000) {
         /* out of 26bit range */
         tcg_abort();
     }
 
-    tcg_out32(s, 0x14000000 | (offset & 0x03ffffff));
+    tcg_out32(s, INSN_B | (offset & 0x03ffffff));
 }
 
 static inline void tcg_out_goto_noaddr(TCGContext *s)
@@ -855,25 +862,21 @@  static inline void tcg_out_goto_noaddr(TCGContext *s)
        kept coherent during retranslation.
        Mask away possible garbage in the high bits for the first translation,
        while keeping the offset bits for retranslation. */
-    uint32_t insn;
-    insn = (tcg_in32(s) & 0x03ffffff) | 0x14000000;
-    tcg_out32(s, insn);
+    uint32_t old = tcg_in32(s) & 0x03ffffff;
+    tcg_out32(s, INSN_B | old);
 }
 
 static inline void tcg_out_goto_cond_noaddr(TCGContext *s, TCGCond c)
 {
-    /* see comments in tcg_out_goto_noaddr */
-    uint32_t insn;
-    insn = tcg_in32(s) & (0x07ffff << 5);
-    insn |= 0x54000000 | tcg_cond_to_aarch64[c];
-    tcg_out32(s, insn);
+    /* See comments in tcg_out_goto_noaddr.  */
+    uint32_t old = tcg_in32(s) & (0x07ffff << 5);
+    tcg_out32(s, INSN_B_C | tcg_cond_to_aarch64[c] | old);
 }
 
 static inline void tcg_out_goto_cond(TCGContext *s, TCGCond c,
                                      tcg_target_long target)
 {
-    tcg_target_long offset;
-    offset = (target - (tcg_target_long)s->code_ptr) / 4;
+    tcg_target_long offset = (target - (tcg_target_long)s->code_ptr) / 4;
 
     if (offset < -0x40000 || offset >= 0x40000) {
         /* out of 19bit range */
@@ -881,37 +884,34 @@  static inline void tcg_out_goto_cond(TCGContext *s, TCGCond c,
     }
 
     offset &= 0x7ffff;
-    tcg_out32(s, 0x54000000 | tcg_cond_to_aarch64[c] | offset << 5);
+    tcg_out32(s, INSN_B_C | tcg_cond_to_aarch64[c] | offset << 5);
 }
 
 static inline void tcg_out_callr(TCGContext *s, TCGReg reg)
 {
-    tcg_out32(s, 0xd63f0000 | reg << 5);
+    tcg_out32(s, INSN_BLR | reg << 5);
 }
 
 static inline void tcg_out_gotor(TCGContext *s, TCGReg reg)
 {
-    tcg_out32(s, 0xd61f0000 | reg << 5);
+    tcg_out32(s, INSN_BR | reg << 5);
 }
 
 static inline void tcg_out_call(TCGContext *s, tcg_target_long target)
 {
-    tcg_target_long offset;
-
-    offset = (target - (tcg_target_long)s->code_ptr) / 4;
+    tcg_target_long offset = (target - (tcg_target_long)s->code_ptr) / 4;
 
     if (offset < -0x02000000 || offset >= 0x02000000) { /* out of 26bit rng */
         tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_TMP, target);
         tcg_out_callr(s, TCG_REG_TMP);
     } else {
-        tcg_out32(s, 0x94000000 | (offset & 0x03ffffff));
+        tcg_out32(s, INSN_BL | (offset & 0x03ffffff));
     }
 }
 
-static inline void tcg_out_ret(TCGContext *s)
+static inline void tcg_out_ret(TCGContext *s, TCGReg rn)
 {
-    /* emit RET { LR } */
-    tcg_out32(s, 0xd65f03c0);
+    tcg_out32(s, INSN_RET | rn << 5);
 }
 
 void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr)
@@ -1993,5 +1993,5 @@  static void tcg_target_qemu_prologue(TCGContext *s)
     /* pop (FP, LR), restore SP to previous frame, return */
     tcg_out_pop_pair(s, TCG_REG_SP,
                      TCG_REG_FP, TCG_REG_LR, frame_size_callee_saved);
-    tcg_out_ret(s);
+    tcg_out_ret(s, TCG_REG_LR);
 }