Skip to contentSkip to conversation

target-mips: generate fences

PATCH In review Leon Alrae 2 participants 4 messages Sep 8, 2016 – Sep 12, 2016

lore
Share & tools
lore

Leon Alrae

author
#0 lore raw

PATCH v2 1/1 target-mips: generate fences

Make use of memory barrier TCG opcode in MIPS front end.

---
v2:
* generate weaker barriers according to stype

---
 target-mips/translate.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
target-mips/translate.c +30 -2
index c212e4f..1e66274 100644
@@ -13109,6 +13109,34 @@ static void gen_ldst_pair (DisasContext *ctx, uint32_t opc, int rd,
     tcg_temp_free(t1);
 }
 
+static void gen_sync(int stype)
+{
+    TCGOrder tcg_mo = TCG_BAR_SC;
+
+    switch (stype) {
+    case 0x4: /* SYNC_WMB */
+        tcg_mo |= TCG_MO_ST_ST;
+        break;
+    case 0x10: /* SYNC_MB */
+        tcg_mo |= TCG_MO_ALL;
+        break;
+    case 0x11: /* SYNC_ACQUIRE */
+        tcg_mo |= TCG_MO_LD_LD | TCG_MO_LD_ST;
+        break;
+    case 0x12: /* SYNC_RELEASE */
+        tcg_mo |= TCG_MO_ST_ST | TCG_MO_LD_ST;
+        break;
+    case 0x13: /* SYNC_RMB */
+        tcg_mo |= TCG_MO_LD_LD;
+        break;
+    default:
+        tcg_mo |= TCG_MO_ALL;
+        break;
+    }
+
+    tcg_gen_mb(tcg_mo);
+}
+
 static void gen_pool32axf (CPUMIPSState *env, DisasContext *ctx, int rt, int rs)
 {
     int extension = (ctx->opcode >> 6) & 0x3f;
@@ -13384,7 +13412,7 @@ static void gen_pool32axf (CPUMIPSState *env, DisasContext *ctx, int rt, int rs)
     case 0x2d:
         switch (minor) {
         case SYNC:
-            /* NOP */
+            gen_sync(extract32(ctx->opcode, 16, 5));
             break;
         case SYSCALL:
             generate_exception_end(ctx, EXCP_SYSCALL);
@@ -17201,7 +17229,7 @@ static void decode_opc_special(CPUMIPSState *env, DisasContext *ctx)
         break;
     case OPC_SYNC:
         check_insn(ctx, ISA_MIPS2);
-        /* Treat as NOP. */
+        gen_sync(extract32(ctx->opcode, 6, 5));
         break;
 
 #if defined(TARGET_MIPS64)
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Leon Alrae

Make use of memory barrier TCG opcode in MIPS front end.

---
v2:
* generate weaker barriers according to stype

---
 target-mips/translate.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

Ah, even better.

Quoted 14 lines
target-mips/translate.c +14 -0
+static void gen_sync(int stype)
+{
+    TCGOrder tcg_mo = TCG_BAR_SC;
+
+    switch (stype) {
+    case 0x4: /* SYNC_WMB */
+        tcg_mo |= TCG_MO_ST_ST;
+        break;
+    case 0x10: /* SYNC_MB */
+        tcg_mo |= TCG_MO_ALL;
+        break;
+    case 0x11: /* SYNC_ACQUIRE */
+        tcg_mo |= TCG_MO_LD_LD | TCG_MO_LD_ST;
+        break;

target-mips/translate.c static void gen_ldst_pair (DisasContext *ctx, uint32_t opc, int rd, · line 13135

Quoted 10 lines
target-mips/translate.c +10 -0
+    case 0x12: /* SYNC_RELEASE */
+        tcg_mo |= TCG_MO_ST_ST | TCG_MO_LD_ST;
+        break;
+    case 0x13: /* SYNC_RMB */
+        tcg_mo |= TCG_MO_LD_LD;
+        break;
+    default:
+        tcg_mo |= TCG_MO_ALL;
+        break;
+    }

See git://github.com/rth7680/qemu.git tcg-next wherein this suggests that some enhancement is desired in tcg/mips/ as well. Not that I have a mips32r6 board with which to test. Would you or James Hogan be able to improve that?

r~

author
#2 lore raw
Quoted 20 lines · Richard Henderson
Quoted 20 lines
target-mips/translate.c +20 -0
+static void gen_sync(int stype)
+{
+    TCGOrder tcg_mo = TCG_BAR_SC;
+
+    switch (stype) {
+    case 0x4: /* SYNC_WMB */
+        tcg_mo |= TCG_MO_ST_ST;
+        break;
+    case 0x10: /* SYNC_MB */
+        tcg_mo |= TCG_MO_ALL;
+        break;
+    case 0x11: /* SYNC_ACQUIRE */
+        tcg_mo |= TCG_MO_LD_LD | TCG_MO_LD_ST;
+        break;
+    case 0x12: /* SYNC_RELEASE */
+        tcg_mo |= TCG_MO_ST_ST | TCG_MO_LD_ST;
+        break;
+    case 0x13: /* SYNC_RMB */
+        tcg_mo |= TCG_MO_LD_LD;
+        break;
Quoted 8 lines

target-mips/translate.c static void gen_ldst_pair (DisasContext *ctx, uint32_t opc, int rd, · line 13135

Quoted 4 lines
target-mips/translate.c +4 -0
+    default:
+        tcg_mo |= TCG_MO_ALL;
+        break;
+    }

See git://github.com/rth7680/qemu.git tcg-next wherein this suggests that some enhancement is desired in tcg/mips/ as well. Not that I have a mips32r6 board with which to test. Would you or James Hogan be able to improve that?

Actually the lightweight variants of SYNC exist also in earlier revisions of MIPS architecture; therefore this can be tested for example on mips32r2.

According to manuals the support is optional, and if given CPU doesn't implement lightweight SYNCs (i.e. with stype != 0) then they are supposed to behave in the same way as SYNC 0. (which also means I simplified that here and always interpret the stype to take advantage of weaker ordering barriers).

Thanks,
Leon

#3 lore raw
Quoted 7 lines · Leon Alrae

Actually the lightweight variants of SYNC exist also in earlier revisions of MIPS architecture; therefore this can be tested for example on mips32r2.

According to manuals the support is optional, and if given CPU doesn't implement lightweight SYNCs (i.e. with stype != 0) then they are supposed to behave in the same way as SYNC 0. (which also means I simplified that here and always interpret the stype to take advantage of weaker ordering barriers).

Noted. I've adjusted the patch in the tcg-next tree to always generate the weaker forms of sync.

r~