git subrepo pull --force deps/lightrec
authorPaul Cercueil <paul@crapouillou.net>
Sat, 29 Oct 2022 14:50:50 +0000 (15:50 +0100)
committerPaul Cercueil <paul@crapouillou.net>
Sat, 29 Oct 2022 14:50:50 +0000 (15:50 +0100)
subrepo:
  subdir:   "deps/lightrec"
  merged:   "4e55a15656"
upstream:
  origin:   "https://github.com/pcercuei/lightrec.git"
  branch:   "master"
  commit:   "4e55a15656"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

deps/lightrec/.gitrepo
deps/lightrec/emitter.c

index ceb8643..0941dea 100644 (file)
@@ -6,7 +6,7 @@
 [subrepo]
        remote = https://github.com/pcercuei/lightrec.git
        branch = master
-       commit = 782c220e5dd9bdf179415a4d058823ff439254b8
-       parent = 5ced3945423cda0010597b27b7da6bce77b12baa
+       commit = 4e55a15656deb7b2529546af114668fb5dc6870e
+       parent = fc7764f123b6445060e56dd27152fffefdec9404
        method = merge
        cmdver = 0.4.3
index 3f7da58..be50d6d 100644 (file)
@@ -1885,6 +1885,7 @@ rec_mtc0(struct lightrec_cstate *state, const struct block *block, u16 offset)
        const union code c = block->opcode_list[offset].c;
        jit_state_t *_jit = block->_jit;
        u8 rt, tmp = 0, tmp2, status;
+       jit_node_t *to_end;
 
        jit_note(__FILE__, __LINE__);
 
@@ -1957,15 +1958,23 @@ rec_mtc0(struct lightrec_cstate *state, const struct block *block, u16 offset)
                jit_orr(tmp, tmp, tmp2);
        }
 
+       lightrec_free_reg(reg_cache, rt);
+
        if (c.r.rd == 12 || c.r.rd == 13) {
-               jit_stxi_i(offsetof(struct lightrec_state, exit_flags),
-                          LIGHTREC_REG_STATE, tmp);
+               to_end = jit_beqi(tmp, 0);
 
-               lightrec_free_reg(reg_cache, tmp);
-               lightrec_free_reg(reg_cache, tmp2);
-       }
+               jit_ldxi_i(tmp2, LIGHTREC_REG_STATE,
+                          offsetof(struct lightrec_state, target_cycle));
+               jit_subr(tmp2, tmp2, LIGHTREC_REG_CYCLE);
+               jit_movi(LIGHTREC_REG_CYCLE, 0);
+               jit_stxi_i(offsetof(struct lightrec_state, target_cycle),
+                          LIGHTREC_REG_STATE, tmp2);
+               jit_stxi_i(offsetof(struct lightrec_state, current_cycle),
+                          LIGHTREC_REG_STATE, tmp2);
 
-       lightrec_free_reg(reg_cache, rt);
+
+               jit_patch(to_end);
+       }
 
        if (!op_flag_no_ds(block->opcode_list[offset].flags) &&
            (c.r.rd == 12 || c.r.rd == 13)) {
@@ -2128,7 +2137,7 @@ static void rec_cp2_basic_CFC2(struct lightrec_cstate *state,
                break;
        default:
                rt = lightrec_alloc_reg_out(reg_cache, _jit, c.r.rt, REG_ZEXT);
-               jit_ldxi_i(rt, LIGHTREC_REG_STATE, cp2c_i_offset(c.r.rd));
+               jit_ldxi_ui(rt, LIGHTREC_REG_STATE, cp2c_i_offset(c.r.rd));
                break;
        }
 
@@ -2390,6 +2399,7 @@ static void rec_meta_MULT2(struct lightrec_cstate *state,
        u32 flags = block->opcode_list[offset].flags;
        bool is_signed = c.i.op == OP_META_MULT2;
        u8 rs, lo, hi, rflags = 0, hiflags = 0;
+       unsigned int i;
 
        if (!op_flag_no_hi(flags) && c.r.op < 32) {
                rflags = is_signed ? REG_EXT : REG_ZEXT;
@@ -2401,28 +2411,38 @@ static void rec_meta_MULT2(struct lightrec_cstate *state,
 
        rs = lightrec_alloc_reg_in(reg_cache, _jit, c.i.rs, rflags);
 
-       if (!op_flag_no_lo(flags)) {
-               lo = lightrec_alloc_reg_out(reg_cache, _jit, reg_lo, 0);
-
-               if (c.r.op < 32)
-                       jit_lshi(lo, rs, c.r.op);
-               else
-                       jit_movi(lo, 0);
+       /*
+        * We must handle the case where one of the output registers is our rs
+        * input register. Thanksfully, computing LO/HI can be done in any
+        * order. Here, we make sure that the computation that overwrites the
+        * input register is always performed last.
+        */
+       for (i = 0; i < 2; i++) {
+               if ((!i ^ (reg_lo == c.i.rs)) && !op_flag_no_lo(flags)) {
+                       lo = lightrec_alloc_reg_out(reg_cache, _jit, reg_lo, 0);
+
+                       if (c.r.op < 32)
+                               jit_lshi(lo, rs, c.r.op);
+                       else
+                               jit_movi(lo, 0);
 
-               lightrec_free_reg(reg_cache, lo);
-       }
+                       lightrec_free_reg(reg_cache, lo);
+                       continue;
+               }
 
-       if (!op_flag_no_hi(flags)) {
-               hi = lightrec_alloc_reg_out(reg_cache, _jit, reg_hi, hiflags);
+               if ((!!i ^ (reg_lo == c.i.rs)) && !op_flag_no_hi(flags)) {
+                       hi = lightrec_alloc_reg_out(reg_cache, _jit,
+                                                   reg_hi, hiflags);
 
-               if (c.r.op >= 32)
-                       jit_lshi(hi, rs, c.r.op - 32);
-               else if (is_signed)
-                       jit_rshi(hi, rs, 32 - c.r.op);
-               else
-                       jit_rshi_u(hi, rs, 32 - c.r.op);
+                       if (c.r.op >= 32)
+                               jit_lshi(hi, rs, c.r.op - 32);
+                       else if (is_signed)
+                               jit_rshi(hi, rs, 32 - c.r.op);
+                       else
+                               jit_rshi_u(hi, rs, 32 - c.r.op);
 
-               lightrec_free_reg(reg_cache, hi);
+                       lightrec_free_reg(reg_cache, hi);
+               }
        }
 
        lightrec_free_reg(reg_cache, rs);