Skip to contentSkip to conversation

tcg arm/mips/ia64: add a comment about retranslation and caches

PATCH In review Aurelien Jarno 3 participants 3 messages Jan 10, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg arm/mips/ia64: add a comment about retranslation and caches

Add a comment about cache coherency and retranslation, so that people developping new targets based on existing ones are warned of the issue.

Cc Alexander Graf <[email protected]>
Cc Edgar E. Iglesias <[email protected]>
---
 tcg/arm/tcg-target.c  |    3 +++
 tcg/ia64/tcg-target.c |    3 +++
 tcg/mips/tcg-target.c |    4 +++-
 3 files changed, 9 insertions(+), 1 deletions(-)
tcg/arm/tcg-target.c +3 -0
index 1eb5605..918e2f7 100644
@@ -352,6 +352,9 @@ static inline void tcg_out_b(TCGContext *s, int cond, int32_t offset)
 
 static inline void tcg_out_b_noaddr(TCGContext *s, int cond)
 {
+    /* We pay attention here to not modify the branch target by skipping
+       the corresponding bytes. This ensure that caches and memory are
+       kept coherent during retranslation. */
 #ifdef HOST_WORDS_BIGENDIAN
     tcg_out8(s, (cond << 4) | 0x0a);
     s->code_ptr += 3;
tcg/ia64/tcg-target.c +3 -0
index e2e44f7..8dac7f7 100644
@@ -871,6 +871,9 @@ static void tcg_out_br(TCGContext *s, int label_index)
 {
     TCGLabel *l = &s->labels[label_index];
 
+    /* We pay attention here to not modify the branch target by reading
+       the existing value and using it again. This ensure that caches and
+       memory are kept coherent during retranslation. */
     tcg_out_bundle(s, mmB,
                    tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
                    tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
tcg/mips/tcg-target.c +3 -1
index 4e92a50..e04b0dc 100644
@@ -351,7 +351,9 @@ static inline void tcg_out_opc_imm(TCGContext *s, int opc, int rt, int rs, int i
  */
 static inline void tcg_out_opc_br(TCGContext *s, int opc, int rt, int rs)
 {
-    /* We need to keep the offset unchanged for retranslation */
+    /* We pay attention here to not modify the branch target by reading
+       the existing value and using it again. This ensure that caches and
+       memory are kept coherent during retranslation. */
     uint16_t offset = (uint16_t)(*(uint32_t *) s->code_ptr);
 
     tcg_out_opc_imm(s, opc, rt, rs, offset);
Signature · 1 line
1.7.2.3
Acked-by on v1 1/1
#2 lore raw
In reply to Aurelien Jarno
Quoted 6 lines · Aurelien Jarno

Add a comment about cache coherency and retranslation, so that people developping new targets based on existing ones are warned of the issue.

Cc Alexander Graf <[email protected]>
Cc Edgar E. Iglesias <[email protected]>

Looks good to me, thanks.

Quoted 52 lines
---
 tcg/arm/tcg-target.c  |    3 +++
 tcg/ia64/tcg-target.c |    3 +++
 tcg/mips/tcg-target.c |    4 +++-
 3 files changed, 9 insertions(+), 1 deletions(-)
tcg/arm/tcg-target.c +3 -0
index 1eb5605..918e2f7 100644
@@ -352,6 +352,9 @@ static inline void tcg_out_b(TCGContext *s, int cond, int32_t offset)
 
 static inline void tcg_out_b_noaddr(TCGContext *s, int cond)
 {
+    /* We pay attention here to not modify the branch target by skipping
+       the corresponding bytes. This ensure that caches and memory are
+       kept coherent during retranslation. */
 #ifdef HOST_WORDS_BIGENDIAN
     tcg_out8(s, (cond << 4) | 0x0a);
     s->code_ptr += 3;
tcg/ia64/tcg-target.c +3 -0
index e2e44f7..8dac7f7 100644
@@ -871,6 +871,9 @@ static void tcg_out_br(TCGContext *s, int label_index)
 {
     TCGLabel *l = &s->labels[label_index];
 
+    /* We pay attention here to not modify the branch target by reading
+       the existing value and using it again. This ensure that caches and
+       memory are kept coherent during retranslation. */
     tcg_out_bundle(s, mmB,
                    tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
                    tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
tcg/mips/tcg-target.c +3 -1
index 4e92a50..e04b0dc 100644
@@ -351,7 +351,9 @@ static inline void tcg_out_opc_imm(TCGContext *s, int opc, int rt, int rs, int i
  */
 static inline void tcg_out_opc_br(TCGContext *s, int opc, int rt, int rs)
 {
-    /* We need to keep the offset unchanged for retranslation */
+    /* We pay attention here to not modify the branch target by reading
+       the existing value and using it again. This ensure that caches and
+       memory are kept coherent during retranslation. */
     uint16_t offset = (uint16_t)(*(uint32_t *) s->code_ptr);
 
     tcg_out_opc_imm(s, opc, rt, rs, offset);
Signature · 1 line
1.7.2.3