Introduce TCGOpcode for fence instruction
RFC PATCH 1/3 Introduce TCGOpcode for fence instruction
In reply to a message not in the archiveThis commit introduces the TCGOpcode for fence instruction.
--- tcg/i386/tcg-target.inc.c | 4 ++++ tcg/tcg-opc.h | 2 ++ tcg/tcg.c | 2 ++ 3 files changed, 8 insertions(+)
tcg/i386/tcg-target.inc.c +4 -0
@@ -2114,6 +2114,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, }break ; +case INDEX_op_fence: +break ;case INDEX_op_mov_i32:/* Always emitted via tcg_out_mov. */ case INDEX_op_mov_i64:case INDEX_op_movi_i32:/* Always emitted via tcg_out_movi. */
@@ -2179,6 +2181,8 @@ static const TCGTargetOpDef x86_op_defs[] = { { INDEX_op_add2_i32, { "r", "r", "0", "1", "ri", "ri" } }, { INDEX_op_sub2_i32, { "r", "r", "0", "1", "ri", "ri" } }, + { INDEX_op_fence, { } }, + #if TCG_TARGET_REG_BITS == 32 { INDEX_op_brcond2_i32, { "r", "r", "ri", "ri" } }, { INDEX_op_setcond2_i32, { "r", "r", "r", "ri", "ri" } },
tcg/tcg-opc.h +2 -0
@@ -42,6 +42,8 @@ DEF(br, 0, 0, 1, TCG_OPF_BB_END)# define IMPL64 TCG_OPF_64BIT#endif +DEF(fence, 0, 0, 0, 0) + DEF(mov_i32, 1, 1, 0, TCG_OPF_NOT_PRESENT) DEF(movi_i32, 1, 0, 1, TCG_OPF_NOT_PRESENT)DEF (setcond_i32,1 ,2 ,1 ,0 )
tcg/tcg.c +2 -0
@@ -2443,6 +2443,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)tcg_reg_alloc_call (s, op->callo, op->calli, args, dead_args, sync_args);break ; +case INDEX_op_fence: +break ;default :/* Sanity check that we've not introduced any unhandled opcodes. */ if (def->flags &TCG_OPF_NOT_PRESENT ) {
Signature · 1 line
2.8.3
RFC PATCH 3/3 tcg: Add frontend support for fence gen in ARMv7
In reply to a message not in the archive--- target-arm/translate.c | 11 +++++++++-- tcg/tcg-op.h | 5 +++++ tcg/tcg-opc.h | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-)
target-arm/translate.c +9 -2
@@ -7980,9 +7980,13 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)gen_clrex (s);return ;case 4 :/* dsb */ +ARCH (7 ); +return ;case 5 :/* dmb */ ARCH (7 ); -/* We don't emulate caches so these are a no-op. */ +if (TCG_TARGET_HAS_fence) { +tcg_gen_fence (); + }return ;case 6 :/* isb */ /* We need to break the TB after this insn to execute
@@ -10330,8 +10334,11 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwgen_clrex (s);break ;case 4 :/* dsb */ +break ;case 5 :/* dmb */ -/* These execute as NOPs. */ +if (TCG_TARGET_HAS_fence) { +tcg_gen_fence (); + }break ;case 6 :/* isb */ /* We need to break the TB after this insn
tcg/tcg-op.h +5 -0
@@ -261,6 +261,11 @@ static inline void tcg_gen_br(TCGLabel *l)tcg_gen_op1 (&tcg_ctx, INDEX_op_br,label_arg (l)); } +static inline void tcg_gen_fence (void ) +{ +tcg_gen_op1 (&tcg_ctx, INDEX_op_fence,0 ); +} +/* Helper calls. */ /* 32 bit ops */
tcg/tcg-opc.h +1 -1
@@ -42,7 +42,7 @@ DEF(br, 0, 0, 1, TCG_OPF_BB_END)# define IMPL64 TCG_OPF_64BIT#endif -DEF(fence, 0, 0, 0, TCG_OPF_SIDE_EFFECTS) +DEF(fence, 0, 0, 0, 0) DEF(mov_i32, 1, 1, 0, TCG_OPF_NOT_PRESENT)DEF (movi_i32,1 ,0 ,1 ,TCG_OPF_NOT_PRESENT )
Signature · 1 line
2.8.3
RFC PATCH 2/3 tcg: Add support for fence generation in x86 backend
In reply to a message not in the archive--- tcg/i386/tcg-target.h | 1 + tcg/i386/tcg-target.inc.c | 9 +++++++++ tcg/tcg-opc.h | 2 +- tcg/tcg.c | 1 + 4 files changed, 12 insertions(+), 1 deletion(-)
tcg/i386/tcg-target.h +1 -0
@@ -100,6 +100,7 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_muls2_i32 1#define TCG_TARGET_HAS_muluh_i32 0#define TCG_TARGET_HAS_mulsh_i32 0 +#define TCG_TARGET_HAS_fence 1#if TCG_TARGET_REG_BITS ==64 #define TCG_TARGET_HAS_extrl_i64_i32 0
tcg/i386/tcg-target.inc.c +9 -0
@@ -347,6 +347,7 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type,#define OPC_SHRX (0xf7 | P_EXT38 | P_SIMDF2)#define OPC_TESTL (0x85)#define OPC_XCHG_ax_r32 (0x90) +#define OPC_MFENCE (0xAE | P_EXT)#define OPC_GRP3_Ev (0xf7)#define OPC_GRP5 (0xff)
@@ -686,6 +687,14 @@ static inline void tcg_out_pushi(TCGContext *s, tcg_target_long val) } } +static inline void tcg_out_fence (TCGContext *s) +{ +/* TODO: Figure out an appropriate place for the encoding */ +tcg_out8 (s,0x0F ); +tcg_out8 (s,0xAE ); +tcg_out8 (s,0xF0 ); +} +static inline void tcg_out_push (TCGContext *s,int reg) {tcg_out_opc (s, OPC_PUSH_r32 +LOWREGMASK (reg),0 , reg,0 );
tcg/tcg-opc.h +1 -1
@@ -42,7 +42,7 @@ DEF(br, 0, 0, 1, TCG_OPF_BB_END)# define IMPL64 TCG_OPF_64BIT#endif -DEF(fence, 0, 0, 0, 0) +DEF(fence, 0, 0, 0, TCG_OPF_SIDE_EFFECTS) DEF(mov_i32, 1, 1, 0, TCG_OPF_NOT_PRESENT)DEF (movi_i32,1 ,0 ,1 ,TCG_OPF_NOT_PRESENT )
tcg/tcg.c +1 -0
@@ -2444,6 +2444,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) dead_args, sync_args);break ;case INDEX_op_fence: +tcg_out_fence (s);break ;default :/* Sanity check that we've not introduced any unhandled opcodes. */
Signature · 1 line
2.8.3
Quoted 8 lines · Pranith Kumar
This commit introduces the TCGOpcode for fence instruction.
Signed-off-by Pranith Kumar <[email protected]>--- tcg/i386/tcg-target.inc.c | 4 ++++ tcg/tcg-opc.h | 2 ++ tcg/tcg.c | 2 ++ 3 files changed, 8 insertions(+)
Since this is a new TCG op, can we have it documented in tcg/README, please? This should describe the semantics of the operation in enough detail that:
* a new TCG backend can implement it correctly
* a TCG frontend knows when it needs to use the op
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Since this is a new TCG op, can we have it documented in tcg/README, please? This should describe the semantics of the operation in enough detail that:
* a new TCG backend can implement it correctly
* a TCG frontend knows when it needs to use the op
Sure, I will add this information.
Thanks!
Signature · 1 line
Pranith
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
In reply to Pranith KumarQuoted 13 lines · Pranith Kumar
Signed-off-by Pranith Kumar <[email protected]>--- tcg/i386/tcg-target.h | 1 + tcg/i386/tcg-target.inc.c | 9 +++++++++ tcg/tcg-opc.h | 2 +- tcg/tcg.c | 1 + 4 files changed, 12 insertions(+), 1 deletion(-)tcg/i386/tcg-target.h +0
-0
tcg/i386/tcg-target.h extern bool have_bmi1; · line 103
Quoted 4 lines
tcg/i386/tcg-target.h +1
-0@@ -100,6 +100,7 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_muls2_i32 1#define TCG_TARGET_HAS_muluh_i32 0#define TCG_TARGET_HAS_mulsh_i32 0 +#define TCG_TARGET_HAS_fence 1
This has to be defined for all hosts.
The default implementation should be a function call into tcg-runtime.c that calls smp_mb().
Quoted 9 lines
tcg/i386/tcg-target.h +1
-0@@ -347,6 +347,7 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type,#define OPC_SHRX (0xf7 | P_EXT38 | P_SIMDF2)#define OPC_TESTL (0x85)#define OPC_XCHG_ax_r32 (0x90) +#define OPC_MFENCE (0xAE | P_EXT)#define OPC_GRP3_Ev (0xf7)#define OPC_GRP5 (0xff)
tcg/i386/tcg-target.h static inline void tcg_out_pushi(TCGContext *s, tcg_target_long val) · line 696
Quoted 10 lines
tcg/i386/tcg-target.h +7
-0@@ -686,6 +687,14 @@ static inline void tcg_out_pushi(TCGContext *s, tcg_target_long val) } } +static inline void tcg_out_fence (TCGContext *s) +{ +/* TODO: Figure out an appropriate place for the encoding */ +tcg_out8 (s,0x0F ); +tcg_out8 (s,0xAE ); +tcg_out8 (s,0xF0 ); +}
Why define OPC_MFENCE if you're not going to use it? Of course, it's not exactly a complete and useful definition, so maybe just delete OPC_MFENCE.
Also, for 32-bit you need to check for sse2 before outputting this. See also the existing cpuid checks in tcg_target_init and the fallback smp_mb definition for pre-gcc-4.4.
r~
Re: [RFC PATCH 3/3] tcg: Add frontend support for fence gen in ARMv7
In reply to Pranith Kumartarget-arm/translate.c static void disas_arm_insn(DisasContext *s, unsigned int insn) · line 7989
Quoted 4 lines · Pranith Kumar
target-arm/translate.c +3
-1-/* We don't emulate caches so these are a no-op. */ +if (TCG_TARGET_HAS_fence) { +tcg_gen_fence (); + }
This should then be unconditional.
r~
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
In reply to Richard HendersonQuoted 21 lines · Richard Henderson
Quoted 13 lines · Pranith Kumar
Signed-off-by Pranith Kumar <[email protected]>--- tcg/i386/tcg-target.h | 1 + tcg/i386/tcg-target.inc.c | 9 +++++++++ tcg/tcg-opc.h | 2 +- tcg/tcg.c | 1 + 4 files changed, 12 insertions(+), 1 deletion(-)tcg/i386/tcg-target.h +0
-0tcg/i386/tcg-target.h extern bool have_bmi1; · line 103
Quoted 4 lines
tcg/i386/tcg-target.h +1
-0@@ -100,6 +100,7 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_muls2_i32 1#define TCG_TARGET_HAS_muluh_i32 0#define TCG_TARGET_HAS_mulsh_i32 0 +#define TCG_TARGET_HAS_fence 1This has to be defined for all hosts.
Quoted 2 lines
The default implementation should be a function call into
tcg-runtime.cthat callssmp_mb().
That would solves the problem of converting the various backends piecemeal - although obviously we should move to all backends having "native" support ASAP. However by introducing expensive substitute functions we will slow down the translations as each front end is expanded to translate the target barrier ops.
Should we make the emitting of the function call/TCGop conditional on MTTCG being enabled? If we are running in round-robin mode there is no need to issue any fence operations.
Quoted 24 lines
Quoted 10 lines
tcg/i386/tcg-target.h +1
-0@@ -347,6 +347,7 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type,#define OPC_SHRX (0xf7 | P_EXT38 | P_SIMDF2)#define OPC_TESTL (0x85)#define OPC_XCHG_ax_r32 (0x90) +#define OPC_MFENCE (0xAE | P_EXT)#define OPC_GRP3_Ev (0xf7)#define OPC_GRP5 (0xff)tcg/i386/tcg-target.h static inline void tcg_out_pushi(TCGContext *s, tcg_target_long val) · line 696
Quoted 10 lines
tcg/i386/tcg-target.h +7
-0@@ -686,6 +687,14 @@ static inline void tcg_out_pushi(TCGContext *s, tcg_target_long val) } } +static inline void tcg_out_fence (TCGContext *s) +{ +/* TODO: Figure out an appropriate place for the encoding */ +tcg_out8 (s,0x0F ); +tcg_out8 (s,0xAE ); +tcg_out8 (s,0xF0 ); +}Why define
OPC_MFENCEif you're not going to use it? Of course, it's not exactly a complete and useful definition, so maybe just deleteOPC_MFENCE.
Quoted 6 lines
Also, for 32-bit you need to check for sse2 before outputting this. See also the existing cpuid checks in
tcg_target_initand the fallbacksmp_mbdefinition for pre-gcc-4.4.r~
--
Alex Bennée
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
Quoted 21 lines · Alex Bennée
Quoted 20 lines · Richard Henderson
Quoted 13 lines · Pranith Kumar
Signed-off-by Pranith Kumar <[email protected]>--- tcg/i386/tcg-target.h | 1 + tcg/i386/tcg-target.inc.c | 9 +++++++++ tcg/tcg-opc.h | 2 +- tcg/tcg.c | 1 + 4 files changed, 12 insertions(+), 1 deletion(-)tcg/i386/tcg-target.h +0
-0tcg/i386/tcg-target.h extern bool have_bmi1; · line 103
Quoted 4 lines
tcg/i386/tcg-target.h +1
-0@@ -100,6 +100,7 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_muls2_i32 1#define TCG_TARGET_HAS_muluh_i32 0#define TCG_TARGET_HAS_mulsh_i32 0 +#define TCG_TARGET_HAS_fence 1This has to be defined for all hosts.
Quoted 7 lines
Quoted 2 lines
The default implementation should be a function call into
tcg-runtime.cthat callssmp_mb().That would solves the problem of converting the various backends piecemeal - although obviously we should move to all backends having "native" support ASAP. However by introducing expensive substitute functions we will slow down the translations as each front end is expanded to translate the target barrier ops.
I think it would better not to defer native support for the operation. It should be relatively simple instruction. Otherwise we could wind up deferring this indefinitely.
Quoted 3 lines
Should we make the emitting of the function call/TCGop conditional on MTTCG being enabled? If we are running in round-robin mode there is no need to issue any fence operations.
Good idea.
Kind regards,
Sergey
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
In reply to Alex BennéeQuoted 5 lines · Alex Bennée
That would solves the problem of converting the various backends piecemeal - although obviously we should move to all backends having "native" support ASAP. However by introducing expensive substitute functions we will slow down the translations as each front end is expanded to translate the target barrier ops.
Obviously. We could in fact do that all up front if desired. It doesn't take long to look up the barrier instructions for each isa.
Quoted 3 lines
Should we make the emitting of the function call/TCGop conditional on MTTCG being enabled? If we are running in round-robin mode there is no need to issue any fence operations.
Probably. But to keep the translators clean we should probably hide that within tcg_gen_fence().
r~
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
In reply to Alex BennéeQuoted 4 lines · Alex Bennée
Should we make the emitting of the function call/TCGop conditional on MTTCG being enabled? If we are running in round-robin mode there is no need to issue any fence operations.
Also, we should check if SMP(> 1 processors) is enabled since fences are not necessary on UP systems.
Signature · 1 line
Pranith
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
In reply to Sergey FedorovQuoted 5 lines · Sergey Fedorov
I think it would better not to defer native support for the operation. It should be relatively simple instruction. Otherwise we could wind up deferring this indefinitely.
Agreed. I will go with the native generation for now.
Thanks,
Signature · 1 line
Pranith
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
Quoted 6 lines · Pranith Kumar
Quoted 4 lines · Sergey Fedorov
I think it would better not to defer native support for the operation. It should be relatively simple instruction. Otherwise we could wind up deferring this indefinitely.
Agreed. I will go with the native generation for now.
I mean we'd better implement native support for all the supported host architectures right away.
Kind regards,
Sergey
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
In reply to Richard HendersonHi Richard,
Thank you for the helpful comments.
Quoted 13 lines · Richard Henderson
tcg/i386/tcg-target.h extern bool have_bmi1; · line 103
Quoted 9 lines · Pranith Kumar
tcg/i386/tcg-target.h +1
-0@@ -100,6 +100,7 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_muls2_i32 1#define TCG_TARGET_HAS_muluh_i32 0#define TCG_TARGET_HAS_mulsh_i32 0 +#define TCG_TARGET_HAS_fence 1This has to be defined for all hosts.
OK. I will add an entry in tcg.h with default 0 and override in individual architecture once it is implemented.
Quoted 9 lines
tcg/i386/tcg-target.h static inline int · line 351
Quoted 6 lines
tcg/i386/tcg-target.h +1
-0@@ -347,6 +347,7 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type, #define OPC_SHRX (0xf7 | P_EXT38 | P_SIMDF2) #define OPC_TESTL (0x85) #define OPC_XCHG_ax_r32 (0x90) +#define OPC_MFENCE (0xAE | P_EXT)Why define
OPC_MFENCEif you're not going to use it? Of course, it's not exactly a complete and useful definition, so maybe just deleteOPC_MFENCE.
I want to use OPC_MFENCE instead of hard-coding the value in tcg_out_fence(), but as you said the definition is not complete(it currently generates only 0x0FAE). I am trying to figure out how to generate 0x0FAEF0 using the definition.
Quoted 4 lines
Also, for 32-bit you need to check for sse2 before outputting this. See also the existing cpuid checks in
tcg_target_initand the fallbacksmp_mbdefinition for pre-gcc-4.4.
OK, I'll check the current code and do something similar.
Thanks,
Signature · 1 line
Pranith
Re: [Qemu-devel] [RFC PATCH 2/3] tcg: Add support for fence generation in x86 backend
Quoted 32 lines · Pranith Kumar
Hi Richard,
Thank you for the helpful comments.
Quoted 13 lines · Richard Henderson
tcg/i386/tcg-target.h extern bool have_bmi1; · line 103
Quoted 9 lines · Pranith Kumar
tcg/i386/tcg-target.h +1
-0@@ -100,6 +100,7 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_muls2_i32 1#define TCG_TARGET_HAS_muluh_i32 0#define TCG_TARGET_HAS_mulsh_i32 0 +#define TCG_TARGET_HAS_fence 1This has to be defined for all hosts.
OK. I will add an entry in
tcg.hwith default 0 and override in individual architecture once it is implemented.Quoted 9 lines
tcg/i386/tcg-target.h static inline int · line 351
Quoted 6 lines
tcg/i386/tcg-target.h +1
-0@@ -347,6 +347,7 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type, #define OPC_SHRX (0xf7 | P_EXT38 | P_SIMDF2) #define OPC_TESTL (0x85) #define OPC_XCHG_ax_r32 (0x90) +#define OPC_MFENCE (0xAE | P_EXT)Why define
OPC_MFENCEif you're not going to use it? Of course, it's not exactly a complete and useful definition, so maybe just deleteOPC_MFENCE.
Quoted 4 lines
I want to use
OPC_MFENCEinstead of hard-coding the value intcg_out_fence(), but as you said the definition is not complete(it currently generates only0x0FAE). I am trying to figure out how to generate0x0FAEF0using the definition.
I think your going to have to just use tcg_out_fence() and the tcg_out_opc() does black magic with extra flag bits and assumes it is encoding rx registers (at least in 64 bit mode).
However I would suggest a comment and maybe breakdown of the different fence types you can emit. Will pre-P4 processors never need mfences?
Quoted 9 lines
Quoted 5 lines
Also, for 32-bit you need to check for sse2 before outputting this. See also the existing cpuid checks in
tcg_target_initand the fallbacksmp_mbdefinition for pre-gcc-4.4.OK, I'll check the current code and do something similar.
Thanks,
--
Alex Bennée