tcg: Reorg 128-bit atomic operations
v3 cover tcg: Reorg 128-bit atomic operations
For v2, and history, see
http://lists.nongnu.org/archive/html/qemu-devel/2018-08/msg04533.html
Changes since v2:
* Fixed a typo noticed by Emilio.
* Brought the target/s390x changes back, as the patches with which they conflicted are now in mainline.
r~
Richard Henderson (9):
tcg: Split CONFIG_ATOMIC128
target/i386: Convert to HAVE_CMPXCHG128
target/arm: Convert to HAVE_CMPXCHG128
target/arm: Check HAVE_CMPXCHG128 at translate time target/ppc: Convert to HAVE_CMPXCHG128 and HAVE_ATOMIC128 target/s390x: Convert to HAVE_CMPXCHG128 and HAVE_ATOMIC128 target/s390x: Split do_cdsg, do_lpq, do_stpq target/s390x: Skip wout, cout helpers if op helper does not return target/s390x: Check HAVE_ATOMIC128 and HAVE_CMPXCHG128 at translate
accel/tcg/atomic_template.h | 20 ++- include/qemu/atomic128.h | 155 ++++++++++++++++++++++ target/ppc/helper.h | 2 +- tcg/tcg.h | 16 ++- accel/tcg/cputlb.c | 3 +- accel/tcg/user-exec.c | 5 +- target/arm/helper-a64.c | 251 ++++++++++++++++++------------------ target/arm/translate-a64.c | 38 +++--- target/i386/mem_helper.c | 9 +- target/ppc/mem_helper.c | 33 ++++- target/ppc/translate.c | 115 +++++++++-------- target/s390x/mem_helper.c | 202 +++++++++++++---------------- target/s390x/translate.c | 37 ++++-- configure | 19 +++ 14 files changed, 561 insertions(+), 344 deletions(-) create mode 100644 include/qemu/atomic128.h
Signature · 1 line
2.17.1
PATCH v3 1/9 tcg: Split CONFIG_ATOMIC128
GCC7+ will no longer advertise support for 16-byte __atomic operations if only cmpxchg is supported, as for x86_64. Fortunately, x86_64 still has support for __sync_compare_and_swap_16 and we can make use of that. AArch64 does not have, nor ever has had such support, so open-code it.
--- accel/tcg/atomic_template.h | 20 ++++- include/qemu/atomic128.h | 155 ++++++++++++++++++++++++++++++++++++ tcg/tcg.h | 16 ++-- accel/tcg/cputlb.c | 3 +- accel/tcg/user-exec.c | 5 +- configure | 19 +++++ 6 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 include/qemu/atomic128.h
accel/tcg/atomic_template.h +16 -4
@@ -100,19 +100,24 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,DATA_TYPE ret;ATOMIC_TRACE_RMW ; +#if DATA_SIZE ==16 + ret =atomic16_cmpxchg (haddr, cmpv, newv); +#else ret =atomic_cmpxchg__nocheck (haddr, cmpv, newv); +#endif ATOMIC_MMU_CLEANUP ;return ret; }#if DATA_SIZE >=16 +#if HAVE_ATOMIC128 ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS) {ATOMIC_MMU_DECLS ;DATA_TYPE val, *haddr =ATOMIC_MMU_LOOKUP ;ATOMIC_TRACE_LD ; -__atomic_load (haddr, &val, __ATOMIC_RELAXED); + val =atomic16_read (haddr);ATOMIC_MMU_CLEANUP ;return val; }
@@ -124,9 +129,10 @@ void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr,DATA_TYPE *haddr =ATOMIC_MMU_LOOKUP ;ATOMIC_TRACE_ST ; -__atomic_store (haddr, &val, __ATOMIC_RELAXED); +atomic16_set (haddr, val);ATOMIC_MMU_CLEANUP ; } +#endif #else ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr, ABI_TYPE val EXTRA_ARGS)
@@ -228,19 +234,24 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,DATA_TYPE ret;ATOMIC_TRACE_RMW ; +#if DATA_SIZE ==16 + ret =atomic16_cmpxchg (haddr,BSWAP (cmpv),BSWAP (newv)); +#else ret =atomic_cmpxchg__nocheck (haddr,BSWAP (cmpv),BSWAP (newv)); +#endif ATOMIC_MMU_CLEANUP ;return BSWAP (ret); }#if DATA_SIZE >=16 +#if HAVE_ATOMIC128 ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS) {ATOMIC_MMU_DECLS ;DATA_TYPE val, *haddr =ATOMIC_MMU_LOOKUP ;ATOMIC_TRACE_LD ; -__atomic_load (haddr, &val, __ATOMIC_RELAXED); + val =atomic16_read (haddr);ATOMIC_MMU_CLEANUP ;return BSWAP (val); }
@@ -253,9 +264,10 @@ void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr,ATOMIC_TRACE_ST ; val =BSWAP (val); -__atomic_store (haddr, &val, __ATOMIC_RELAXED); +atomic16_set (haddr, val);ATOMIC_MMU_CLEANUP ; } +#endif #else ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr, ABI_TYPE val EXTRA_ARGS)
include/qemu/atomic128.h new file +155 -0
155 lines not on this page · raw message
tcg/tcg.h +9 -7
@@ -32,6 +32,7 @@#include "qemu/queue.h" #include "tcg-mo.h" #include "tcg-target.h" +#include "qemu/int128.h" /* XXX: make safe guess about sizes */ #define MAX_OP_PER_INSTR 266
@@ -1454,11 +1455,14 @@ GEN_ATOMIC_HELPER_ALL(xchg)#undef GEN_ATOMIC_HELPER#endif /* CONFIG_SOFTMMU */ -#ifdef CONFIG_ATOMIC128 -#include "qemu/int128.h" - -/* These aren't really a "proper" helpers because TCG cannot manage Int128. -However, use the same format as the others, for use by the backends. */ +/* +* These aren't really a "proper" helpers because TCG cannot manage Int128. +* However, use the same format as the others, for use by the backends. +* +* The cmpxchg functions are only defined if HAVE_CMPXCHG128; +* the ld/st functions are only defined if HAVE_ATOMIC128, +* as defined by <qemu/atomic128.h>. +*/ Int128 helper_atomic_cmpxchgo_le_mmu (CPUArchState *env,target_ulong addr,Int128 cmpv,Int128 newv,TCGMemOpIdx oi,uintptr_t retaddr);
@@ -1475,6 +1479,4 @@ void helper_atomic_sto_le_mmu(CPUArchState *env, target_ulong addr, Int128 val,void helper_atomic_sto_be_mmu (CPUArchState *env,target_ulong addr,Int128 val,TCGMemOpIdx oi,uintptr_t retaddr); -#endif /* CONFIG_ATOMIC128 */ -#endif /* TCG_H */
accel/tcg/cputlb.c +2 -1
@@ -32,6 +32,7 @@#include "exec/log.h" #include "exec/helper-proto.h" #include "qemu/atomic.h" +#include "qemu/atomic128.h" /* DEBUG defines, enable DEBUG_TLB_LOG to log to the CPU_LOG_MMU target */ /* #define DEBUG_TLB */
@@ -1101,7 +1102,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,#include "atomic_template.h" #endif -#ifdef CONFIG_ATOMIC128 +#if HAVE_CMPXCHG128 ||HAVE_ATOMIC128 #define DATA_SIZE 16#include "atomic_template.h" #endif
accel/tcg/user-exec.c +3 -2
@@ -25,6 +25,7 @@#include "exec/cpu_ldst.h" #include "translate-all.h" #include "exec/helper-proto.h" +#include "qemu/atomic128.h" #undef EAX#undef ECX
@@ -615,7 +616,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,/* The following is only callable from other helpers, and matches up with the softmmu version. */ -#ifdef CONFIG_ATOMIC128 +#if HAVE_ATOMIC128 ||HAVE_CMPXCHG128 #undef EXTRA_ARGS#undef ATOMIC_NAME
@@ -628,4 +629,4 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,#define DATA_SIZE 16#include "atomic_template.h" -#endif /* CONFIG_ATOMIC128 */ +#endif
configure +19 -0
@@ -5186,6 +5186,21 @@ EOF fi fi +cmpxchg128=no +if test "$int128" = yes -a "$atomic128" = no; then + cat > $TMPC << EOF +int main(void) +{ + unsigned __int128 x = 0, y = 0; + __sync_val_compare_and_swap_16(&x, y, x); + return 0; +} +EOF + if compile_prog "" "" ; then + cmpxchg128=yes + fi +fi + ######################################### # See if 64-bit atomic operations are supported. # Note that without __atomic builtins, we can only
@@ -6702,6 +6717,10 @@ if test "$atomic128" = "yes" ; then echo "CONFIG_ATOMIC128=y" >> $config_host_mak fi +if test "$cmpxchg128" = "yes" ; then + echo "CONFIG_CMPXCHG128=y" >> $config_host_mak +fi + if test "$atomic64" = "yes" ; then echo "CONFIG_ATOMIC64=y" >> $config_host_mak fi
Signature · 1 line
2.17.1
PATCH v3 2/9 target/i386: Convert to HAVE_CMPXCHG128
In reply to Richard Henderson--- target/i386/mem_helper.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
target/i386/mem_helper.c +4 -5
@@ -23,6 +23,7 @@#include "exec/exec-all.h" #include "exec/cpu_ldst.h" #include "qemu/int128.h" +#include "qemu/atomic128.h" #include "tcg.h" void helper_cmpxchg8b_unlocked (CPUX86State *env,target_ulong a0)
@@ -137,10 +138,7 @@ void helper_cmpxchg16b(CPUX86State *env, target_ulong a0)if ((a0 &0xf ) !=0 ) {raise_exception_ra (env,EXCP0D_GPF , ra); - }else { -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else + }else if (HAVE_CMPXCHG128 ) {int eflags =cpu_cc_compute_all (env,CC_OP );Int128 cmpv =int128_make128 (env->regs[R_EAX ], env->regs[R_EDX ]);
@@ -159,7 +157,8 @@ void helper_cmpxchg16b(CPUX86State *env, target_ulong a0) eflags &= ~CC_Z; }CC_SRC = eflags; -#endif + }else { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } }#endif
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v3 2/9] target/i386: Convert to HAVE_CMPXCHG128
Quoted 2 lines · Richard Henderson
Reviewed-by Emilio G. Cota <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Quoted 39 lines
--- target/i386/mem_helper.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)target/i386/mem_helper.c +4
-5@@ -23,6 +23,7 @@#include "exec/exec-all.h" #include "exec/cpu_ldst.h" #include "qemu/int128.h" +#include "qemu/atomic128.h" #include "tcg.h" void helper_cmpxchg8b_unlocked (CPUX86State *env,target_ulong a0)@@ -137,10 +138,7 @@ void helper_cmpxchg16b(CPUX86State *env, target_ulong a0)if ((a0 &0xf ) !=0 ) {raise_exception_ra (env,EXCP0D_GPF , ra); - }else { -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else + }else if (HAVE_CMPXCHG128 ) {int eflags =cpu_cc_compute_all (env,CC_OP );Int128 cmpv =int128_make128 (env->regs[R_EAX ], env->regs[R_EDX ]);@@ -159,7 +157,8 @@ void helper_cmpxchg16b(CPUX86State *env, target_ulong a0) eflags &= ~CC_Z; }CC_SRC = eflags; -#endif + }else { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } }#endif
PATCH v3 3/9 target/arm: Convert to HAVE_CMPXCHG128
In reply to Richard Henderson--- target/arm/helper-a64.c | 259 +++++++++++++++++++++------------------- 1 file changed, 133 insertions(+), 126 deletions(-)
target/arm/helper-a64.c +133 -126
@@ -30,6 +30,7 @@#include "exec/exec-all.h" #include "exec/cpu_ldst.h" #include "qemu/int128.h" +#include "qemu/atomic128.h" #include "tcg.h" #include "fpu/softfloat.h" #include <zlib.h> /* For crc32 */
@@ -509,189 +510,195 @@ uint64_t HELPER(crc32c_64)(uint64_t acc, uint64_t val, uint32_t bytes)return crc32c (acc, buf, bytes) ^0xffffffff ; } -/* Returns 0 on success; 1 otherwise. */ -static uint64_t do_paired_cmpxchg64_le (CPUARMState *env,uint64_t addr, -uint64_t new_lo,uint64_t new_hi, -bool parallel,uintptr_t ra) +uint64_t HELPER (paired_cmpxchg64_le )(CPUARMState *env,uint64_t addr, +uint64_t new_lo,uint64_t new_hi) { -Int128 oldv, cmpv, newv; +Int128 cmpv =int128_make128 (env->exclusive_val, env->exclusive_high); +Int128 newv =int128_make128 (new_lo, new_hi); +Int128 oldv; +uintptr_t ra =GETPC (); +uint64_t o0, o1;bool success; - cmpv =int128_make128 (env->exclusive_val, env->exclusive_high); - newv =int128_make128 (new_lo, new_hi); - -if (parallel) { -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); - oldv =helper_atomic_cmpxchgo_le_mmu (env, addr, cmpv, newv, oi, ra); - success =int128_eq (oldv, cmpv); -#endif - }else { -uint64_t o0, o1; -#ifdef CONFIG_USER_ONLY -/* ??? Enforce alignment. */ -uint64_t *haddr =g2h (addr); +/* ??? Enforce alignment. */ +uint64_t *haddr =g2h (addr); - helper_retaddr = ra; - o0 =ldq_le_p (haddr +0 ); - o1 =ldq_le_p (haddr +1 ); - oldv =int128_make128 (o0, o1); + helper_retaddr = ra; + o0 =ldq_le_p (haddr +0 ); + o1 =ldq_le_p (haddr +1 ); + oldv =int128_make128 (o0, o1); - success =int128_eq (oldv, cmpv); -if (success) { -stq_le_p (haddr +0 ,int128_getlo (newv)); -stq_le_p (haddr +1 ,int128_gethi (newv)); - } - helper_retaddr =0 ; -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi0 =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); -TCGMemOpIdx oi1 =make_memop_idx (MO_LEQ , mem_idx); - - o0 =helper_le_ldq_mmu (env, addr +0 , oi0, ra); - o1 =helper_le_ldq_mmu (env, addr +8 , oi1, ra); - oldv =int128_make128 (o0, o1); - - success =int128_eq (oldv, cmpv); -if (success) { -helper_le_stq_mmu (env, addr +0 ,int128_getlo (newv), oi1, ra); -helper_le_stq_mmu (env, addr +8 ,int128_gethi (newv), oi1, ra); - } -#endif + success =int128_eq (oldv, cmpv); +if (success) { +stq_le_p (haddr +0 ,int128_getlo (newv)); +stq_le_p (haddr +1 ,int128_gethi (newv)); } + helper_retaddr =0 ; +#else +int mem_idx =cpu_mmu_index (env, false); +TCGMemOpIdx oi0 =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); +TCGMemOpIdx oi1 =make_memop_idx (MO_LEQ , mem_idx); + + o0 =helper_le_ldq_mmu (env, addr +0 , oi0, ra); + o1 =helper_le_ldq_mmu (env, addr +8 , oi1, ra); + oldv =int128_make128 (o0, o1); + + success =int128_eq (oldv, cmpv); +if (success) { +helper_le_stq_mmu (env, addr +0 ,int128_getlo (newv), oi1, ra); +helper_le_stq_mmu (env, addr +8 ,int128_gethi (newv), oi1, ra); + } +#endif return !success; } -uint64_t HELPER (paired_cmpxchg64_le )(CPUARMState *env,uint64_t addr, -uint64_t new_lo,uint64_t new_hi) -{ -return do_paired_cmpxchg64_le (env, addr, new_lo, new_hi, false,GETPC ()); -} -uint64_t HELPER (paired_cmpxchg64_le_parallel )(CPUARMState *env,uint64_t addr,uint64_t new_lo,uint64_t new_hi) -{ -return do_paired_cmpxchg64_le (env, addr, new_lo, new_hi, true,GETPC ()); -} - -static uint64_t do_paired_cmpxchg64_be (CPUARMState *env,uint64_t addr, -uint64_t new_lo,uint64_t new_hi, -bool parallel,uintptr_t ra) {Int128 oldv, cmpv, newv; +uintptr_t ra =GETPC ();bool success; +int mem_idx; +TCGMemOpIdx oi; -/* high and low need to be switched here because this is not actually a -* 128bit store but two doublewords stored consecutively -*/ - cmpv =int128_make128 (env->exclusive_high, env->exclusive_val); - newv =int128_make128 (new_hi, new_lo); - -if (parallel) { -#ifndef CONFIG_ATOMIC128 +if (!HAVE_CMPXCHG128 ) {cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_BEQ |MO_ALIGN_16 , mem_idx); - oldv =helper_atomic_cmpxchgo_be_mmu (env, addr, cmpv, newv, oi, ra); - success =int128_eq (oldv, cmpv); -#endif - }else { -uint64_t o0, o1; - -#ifdef CONFIG_USER_ONLY -/* ??? Enforce alignment. */ -uint64_t *haddr =g2h (addr); - - helper_retaddr = ra; - o1 =ldq_be_p (haddr +0 ); - o0 =ldq_be_p (haddr +1 ); - oldv =int128_make128 (o0, o1); - - success =int128_eq (oldv, cmpv); -if (success) { -stq_be_p (haddr +0 ,int128_gethi (newv)); -stq_be_p (haddr +1 ,int128_getlo (newv)); - } - helper_retaddr =0 ; -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi0 =make_memop_idx (MO_BEQ |MO_ALIGN_16 , mem_idx); -TCGMemOpIdx oi1 =make_memop_idx (MO_BEQ , mem_idx); - - o1 =helper_be_ldq_mmu (env, addr +0 , oi0, ra); - o0 =helper_be_ldq_mmu (env, addr +8 , oi1, ra); - oldv =int128_make128 (o0, o1); - - success =int128_eq (oldv, cmpv); -if (success) { -helper_be_stq_mmu (env, addr +0 ,int128_gethi (newv), oi1, ra); -helper_be_stq_mmu (env, addr +8 ,int128_getlo (newv), oi1, ra); - } -#endif } + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); + + cmpv =int128_make128 (env->exclusive_val, env->exclusive_high); + newv =int128_make128 (new_lo, new_hi); + oldv =helper_atomic_cmpxchgo_le_mmu (env, addr, cmpv, newv, oi, ra); + + success =int128_eq (oldv, cmpv);return !success; }uint64_t HELPER (paired_cmpxchg64_be )(CPUARMState *env,uint64_t addr,uint64_t new_lo,uint64_t new_hi) { -return do_paired_cmpxchg64_be (env, addr, new_lo, new_hi, false,GETPC ()); +/* +* High and low need to be switched here because this is not actually a +* 128bit store but two doublewords stored consecutively +*/ +Int128 cmpv =int128_make128 (env->exclusive_val, env->exclusive_high); +Int128 newv =int128_make128 (new_lo, new_hi); +Int128 oldv; +uintptr_t ra =GETPC (); +uint64_t o0, o1; +bool success; + +#ifdef CONFIG_USER_ONLY +/* ??? Enforce alignment. */ +uint64_t *haddr =g2h (addr); + + helper_retaddr = ra; + o1 =ldq_be_p (haddr +0 ); + o0 =ldq_be_p (haddr +1 ); + oldv =int128_make128 (o0, o1); + + success =int128_eq (oldv, cmpv); +if (success) { +stq_be_p (haddr +0 ,int128_gethi (newv)); +stq_be_p (haddr +1 ,int128_getlo (newv)); + } + helper_retaddr =0 ; +#else +int mem_idx =cpu_mmu_index (env, false); +TCGMemOpIdx oi0 =make_memop_idx (MO_BEQ |MO_ALIGN_16 , mem_idx); +TCGMemOpIdx oi1 =make_memop_idx (MO_BEQ , mem_idx); + + o1 =helper_be_ldq_mmu (env, addr +0 , oi0, ra); + o0 =helper_be_ldq_mmu (env, addr +8 , oi1, ra); + oldv =int128_make128 (o0, o1); + + success =int128_eq (oldv, cmpv); +if (success) { +helper_be_stq_mmu (env, addr +0 ,int128_gethi (newv), oi1, ra); +helper_be_stq_mmu (env, addr +8 ,int128_getlo (newv), oi1, ra); + } +#endif + +return !success; }uint64_t HELPER (paired_cmpxchg64_be_parallel )(CPUARMState *env,uint64_t addr, -uint64_t new_lo,uint64_t new_hi) +uint64_t new_lo,uint64_t new_hi) { -return do_paired_cmpxchg64_be (env, addr, new_lo, new_hi, true,GETPC ()); +Int128 oldv, cmpv, newv; +uintptr_t ra =GETPC (); +bool success; +int mem_idx; +TCGMemOpIdx oi; + +if (!HAVE_CMPXCHG128 ) { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); + } + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_BEQ |MO_ALIGN_16 , mem_idx); + +/* +* High and low need to be switched here because this is not actually a +* 128bit store but two doublewords stored consecutively +*/ + cmpv =int128_make128 (env->exclusive_high, env->exclusive_val); + newv =int128_make128 (new_hi, new_lo); + oldv =helper_atomic_cmpxchgo_be_mmu (env, addr, cmpv, newv, oi, ra); + + success =int128_eq (oldv, cmpv); +return !success; }/* Writes back the old data into Rs. */ void HELPER (casp_le_parallel )(CPUARMState *env,uint32_t rs,uint64_t addr,uint64_t new_lo,uint64_t new_hi) { -uintptr_t ra =GETPC (); -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else Int128 oldv, cmpv, newv; +uintptr_t ra =GETPC (); +int mem_idx; +TCGMemOpIdx oi; + +if (!HAVE_CMPXCHG128 ) { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); + } + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); cmpv =int128_make128 (env->xregs[rs], env->xregs[rs +1 ]); newv =int128_make128 (new_lo, new_hi); - -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); oldv =helper_atomic_cmpxchgo_le_mmu (env, addr, cmpv, newv, oi, ra); env->xregs[rs] =int128_getlo (oldv); env->xregs[rs +1 ] =int128_gethi (oldv); -#endif }void HELPER (casp_be_parallel )(CPUARMState *env,uint32_t rs,uint64_t addr,uint64_t new_hi,uint64_t new_lo) { -uintptr_t ra =GETPC (); -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else Int128 oldv, cmpv, newv; +uintptr_t ra =GETPC (); +int mem_idx; +TCGMemOpIdx oi; + +if (!HAVE_CMPXCHG128 ) { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); + } + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); cmpv =int128_make128 (env->xregs[rs +1 ], env->xregs[rs]); newv =int128_make128 (new_lo, new_hi); - -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx); oldv =helper_atomic_cmpxchgo_be_mmu (env, addr, cmpv, newv, oi, ra); env->xregs[rs +1 ] =int128_getlo (oldv); env->xregs[rs] =int128_gethi (oldv); -#endif }/*
Signature · 1 line
2.17.1
PATCH v3 4/9 target/arm: Check HAVE_CMPXCHG128 at translate time
In reply to Richard Henderson--- target/arm/helper-a64.c | 16 ++++------------ target/arm/translate-a64.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 28 deletions(-)
target/arm/helper-a64.c +4 -12
@@ -563,9 +563,7 @@ uint64_t HELPER(paired_cmpxchg64_le_parallel)(CPUARMState *env, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx);
@@ -635,9 +633,7 @@ uint64_t HELPER(paired_cmpxchg64_be_parallel)(CPUARMState *env, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_BEQ |MO_ALIGN_16 , mem_idx);
@@ -663,9 +659,7 @@ void HELPER(casp_le_parallel)(CPUARMState *env, uint32_t rs, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx);
@@ -686,9 +680,7 @@ void HELPER(casp_be_parallel)(CPUARMState *env, uint32_t rs, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx);
target/arm/translate-a64.c +22 -16
@@ -37,6 +37,7 @@#include "trace-tcg.h" #include "translate-a64.h" +#include "qemu/atomic128.h" static TCGv_i64 cpu_X[32 ];static TCGv_i64 cpu_pc;
@@ -2082,26 +2083,27 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,get_mem_index (s), MO_64 | MO_ALIGN | s->be_data);tcg_gen_setcond_i64 (TCG_COND_NE , tmp, tmp, cpu_exclusive_val); - }else if (s->be_data ==MO_LE ) { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { + }else if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!HAVE_CMPXCHG128 ) { +gen_helper_exit_atomic (cpu_env); + s->base.is_jmp =DISAS_NORETURN ; + }else if (s->be_data ==MO_LE ) {gen_helper_paired_cmpxchg64_le_parallel (tmp, cpu_env, cpu_exclusive_addr,cpu_reg (s, rt),cpu_reg (s, rt2)); }else { -gen_helper_paired_cmpxchg64_le (tmp, cpu_env, cpu_exclusive_addr, -cpu_reg (s, rt),cpu_reg (s, rt2)); - } - }else { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) {gen_helper_paired_cmpxchg64_be_parallel (tmp, cpu_env, cpu_exclusive_addr,cpu_reg (s, rt),cpu_reg (s, rt2)); - }else { -gen_helper_paired_cmpxchg64_be (tmp, cpu_env, cpu_exclusive_addr, -cpu_reg (s, rt),cpu_reg (s, rt2)); } + }else if (s->be_data ==MO_LE ) { +gen_helper_paired_cmpxchg64_le (tmp, cpu_env, cpu_exclusive_addr, +cpu_reg (s, rt),cpu_reg (s, rt2)); + }else { +gen_helper_paired_cmpxchg64_be (tmp, cpu_env, cpu_exclusive_addr, +cpu_reg (s, rt),cpu_reg (s, rt2)); } }else { tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr, cpu_exclusive_val,
@@ -2171,14 +2173,18 @@ static void gen_compare_and_swap_pair(DisasContext *s, int rs, int rt, }tcg_temp_free_i64 (cmp); }else if (tb_cflags (s->base.tb) &CF_PARALLEL ) { -TCGv_i32 tcg_rs =tcg_const_i32 (rs); - -if (s->be_data ==MO_LE ) { -gen_helper_casp_le_parallel (cpu_env, tcg_rs, addr, t1, t2); +if (HAVE_CMPXCHG128 ) { +TCGv_i32 tcg_rs =tcg_const_i32 (rs); +if (s->be_data ==MO_LE ) { +gen_helper_casp_le_parallel (cpu_env, tcg_rs, addr, t1, t2); + }else { +gen_helper_casp_be_parallel (cpu_env, tcg_rs, addr, t1, t2); + } +tcg_temp_free_i32 (tcg_rs); }else { -gen_helper_casp_be_parallel (cpu_env, tcg_rs, addr, t1, t2); +gen_helper_exit_atomic (cpu_env); + s->base.is_jmp =DISAS_NORETURN ; } -tcg_temp_free_i32 (tcg_rs); }else {TCGv_i64 d1 =tcg_temp_new_i64 ();TCGv_i64 d2 =tcg_temp_new_i64 ();
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v3 4/9] target/arm: Check HAVE_CMPXCHG128 at translate time
Quoted 2 lines · Richard Henderson
Reviewed-by Emilio G. Cota <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Quoted 129 lines
--- target/arm/helper-a64.c | 16 ++++------------ target/arm/translate-a64.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 28 deletions(-)target/arm/helper-a64.c +4
-12@@ -563,9 +563,7 @@ uint64_t HELPER(paired_cmpxchg64_le_parallel)(CPUARMState *env, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx);@@ -635,9 +633,7 @@ uint64_t HELPER(paired_cmpxchg64_be_parallel)(CPUARMState *env, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_BEQ |MO_ALIGN_16 , mem_idx);@@ -663,9 +659,7 @@ void HELPER(casp_le_parallel)(CPUARMState *env, uint32_t rs, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx);@@ -686,9 +680,7 @@ void HELPER(casp_be_parallel)(CPUARMState *env, uint32_t rs, uint64_t addr,int mem_idx;TCGMemOpIdx oi; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_LEQ |MO_ALIGN_16 , mem_idx);target/arm/translate-a64.c +22
-16@@ -37,6 +37,7 @@#include "trace-tcg.h" #include "translate-a64.h" +#include "qemu/atomic128.h" static TCGv_i64 cpu_X[32 ];static TCGv_i64 cpu_pc;@@ -2082,26 +2083,27 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,get_mem_index (s), MO_64 | MO_ALIGN | s->be_data);tcg_gen_setcond_i64 (TCG_COND_NE , tmp, tmp, cpu_exclusive_val); - }else if (s->be_data ==MO_LE ) { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { + }else if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!HAVE_CMPXCHG128 ) { +gen_helper_exit_atomic (cpu_env); + s->base.is_jmp =DISAS_NORETURN ; + }else if (s->be_data ==MO_LE ) {gen_helper_paired_cmpxchg64_le_parallel (tmp, cpu_env, cpu_exclusive_addr,cpu_reg (s, rt),cpu_reg (s, rt2)); }else { -gen_helper_paired_cmpxchg64_le (tmp, cpu_env, cpu_exclusive_addr, -cpu_reg (s, rt),cpu_reg (s, rt2)); - } - }else { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) {gen_helper_paired_cmpxchg64_be_parallel (tmp, cpu_env, cpu_exclusive_addr,cpu_reg (s, rt),cpu_reg (s, rt2)); - }else { -gen_helper_paired_cmpxchg64_be (tmp, cpu_env, cpu_exclusive_addr, -cpu_reg (s, rt),cpu_reg (s, rt2)); } + }else if (s->be_data ==MO_LE ) { +gen_helper_paired_cmpxchg64_le (tmp, cpu_env, cpu_exclusive_addr, +cpu_reg (s, rt),cpu_reg (s, rt2)); + }else { +gen_helper_paired_cmpxchg64_be (tmp, cpu_env, cpu_exclusive_addr, +cpu_reg (s, rt),cpu_reg (s, rt2)); } }else { tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr, cpu_exclusive_val,@@ -2171,14 +2173,18 @@ static void gen_compare_and_swap_pair(DisasContext *s, int rs, int rt, }tcg_temp_free_i64 (cmp); }else if (tb_cflags (s->base.tb) &CF_PARALLEL ) { -TCGv_i32 tcg_rs =tcg_const_i32 (rs); - -if (s->be_data ==MO_LE ) { -gen_helper_casp_le_parallel (cpu_env, tcg_rs, addr, t1, t2); +if (HAVE_CMPXCHG128 ) { +TCGv_i32 tcg_rs =tcg_const_i32 (rs); +if (s->be_data ==MO_LE ) { +gen_helper_casp_le_parallel (cpu_env, tcg_rs, addr, t1, t2); + }else { +gen_helper_casp_be_parallel (cpu_env, tcg_rs, addr, t1, t2); + } +tcg_temp_free_i32 (tcg_rs); }else { -gen_helper_casp_be_parallel (cpu_env, tcg_rs, addr, t1, t2); +gen_helper_exit_atomic (cpu_env); + s->base.is_jmp =DISAS_NORETURN ; } -tcg_temp_free_i32 (tcg_rs); }else {TCGv_i64 d1 =tcg_temp_new_i64 ();TCGv_i64 d2 =tcg_temp_new_i64 ();
PATCH v3 5/9 target/ppc: Convert to HAVE_CMPXCHG128 and HAVE_ATOMIC128
In reply to Richard Henderson--- target/ppc/helper.h | 2 +- target/ppc/mem_helper.c | 33 ++++++++++-- target/ppc/translate.c | 115 +++++++++++++++++++++------------------- 3 files changed, 88 insertions(+), 62 deletions(-)
target/ppc/helper.h +1 -1
@@ -800,7 +800,7 @@ DEF_HELPER_4(dscliq, void, env, fprp, fprp, i32) DEF_HELPER_1(tbegin, void, env) DEF_HELPER_FLAGS_1(fixup_thrm, TCG_CALL_NO_RWG, void, env) -#if defined(TARGET_PPC64 ) && defined(CONFIG_ATOMIC128 ) +#ifdef TARGET_PPC64 DEF_HELPER_FLAGS_3(lq_le_parallel, TCG_CALL_NO_WG, i64, env, tl, i32) DEF_HELPER_FLAGS_3(lq_be_parallel, TCG_CALL_NO_WG, i64, env, tl, i32) DEF_HELPER_FLAGS_5(stq_le_parallel, TCG_CALL_NO_WG,
target/ppc/mem_helper.c +28 -5
@@ -25,6 +25,7 @@#include "exec/cpu_ldst.h" #include "tcg.h" #include "internal.h" +#include "qemu/atomic128.h" //#define DEBUG_OP
@@ -215,11 +216,15 @@ target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg,return i; } -#if defined(TARGET_PPC64 ) && defined(CONFIG_ATOMIC128 ) +#ifdef TARGET_PPC64 uint64_t helper_lq_le_parallel (CPUPPCState *env,target_ulong addr,uint32_t opidx) { -Int128 ret =helper_atomic_ldo_le_mmu (env, addr, opidx,GETPC ()); +Int128 ret; + +/* We will have raised EXCP_ATOMIC from the translator. */ +assert (HAVE_ATOMIC128 ); + ret =helper_atomic_ldo_le_mmu (env, addr, opidx,GETPC ()); env->retxh =int128_gethi (ret);return int128_getlo (ret); }
@@ -227,7 +232,11 @@ uint64_t helper_lq_le_parallel(CPUPPCState *env, target_ulong addr,uint64_t helper_lq_be_parallel (CPUPPCState *env,target_ulong addr,uint32_t opidx) { -Int128 ret =helper_atomic_ldo_be_mmu (env, addr, opidx,GETPC ()); +Int128 ret; + +/* We will have raised EXCP_ATOMIC from the translator. */ +assert (HAVE_ATOMIC128 ); + ret =helper_atomic_ldo_be_mmu (env, addr, opidx,GETPC ()); env->retxh =int128_gethi (ret);return int128_getlo (ret); }
@@ -235,14 +244,22 @@ uint64_t helper_lq_be_parallel(CPUPPCState *env, target_ulong addr,void helper_stq_le_parallel (CPUPPCState *env,target_ulong addr,uint64_t lo,uint64_t hi,uint32_t opidx) { -Int128 val =int128_make128 (lo, hi); +Int128 val; + +/* We will have raised EXCP_ATOMIC from the translator. */ +assert (HAVE_ATOMIC128 ); + val =int128_make128 (lo, hi);helper_atomic_sto_le_mmu (env, addr, val, opidx,GETPC ()); }void helper_stq_be_parallel (CPUPPCState *env,target_ulong addr,uint64_t lo,uint64_t hi,uint32_t opidx) { -Int128 val =int128_make128 (lo, hi); +Int128 val; + +/* We will have raised EXCP_ATOMIC from the translator. */ +assert (HAVE_ATOMIC128 ); + val =int128_make128 (lo, hi);helper_atomic_sto_be_mmu (env, addr, val, opidx,GETPC ()); }
@@ -252,6 +269,9 @@ uint32_t helper_stqcx_le_parallel(CPUPPCState *env, target_ulong addr, {bool success = false; +/* We will have raised EXCP_ATOMIC from the translator. */ +assert (HAVE_CMPXCHG128 ); +if (likely (addr == env->reserve_addr)) {Int128 oldv, cmpv, newv;
@@ -271,6 +291,9 @@ uint32_t helper_stqcx_be_parallel(CPUPPCState *env, target_ulong addr, {bool success = false; +/* We will have raised EXCP_ATOMIC from the translator. */ +assert (HAVE_CMPXCHG128 ); +if (likely (addr == env->reserve_addr)) {Int128 oldv, cmpv, newv;
target/ppc/translate.c +59 -56
154 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 6/9 target/s390x: Convert to HAVE_CMPXCHG128 and HAVE_ATOMIC128
In reply to Richard Henderson--- target/s390x/mem_helper.c | 92 +++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 51 deletions(-)
target/s390x/mem_helper.c +41 -51
@@ -25,6 +25,7 @@#include "exec/exec-all.h" #include "exec/cpu_ldst.h" #include "qemu/int128.h" +#include "qemu/atomic128.h" #if !defined(CONFIG_USER_ONLY )#include "hw/s390x/storage-keys.h"
@@ -1389,7 +1390,7 @@ static void do_cdsg(CPUS390XState *env, uint64_t addr,bool fail;if (parallel) { -#ifndef CONFIG_ATOMIC128 +#if !HAVE_CMPXCHG128 cpu_loop_exit_atomic (ENV_GET_CPU (env), ra);#else int mem_idx =cpu_mmu_index (env, false);
@@ -1435,9 +1436,7 @@ void HELPER(cdsg_parallel)(CPUS390XState *env, uint64_t addr,static uint32_t do_csst (CPUS390XState *env,uint32_t r3,uint64_t a1,uint64_t a2,bool parallel) { -#if !defined(CONFIG_USER_ONLY ) || defined(CONFIG_ATOMIC128 )uint32_t mem_idx =cpu_mmu_index (env, false); -#endif uintptr_t ra =GETPC ();uint32_t fc =extract32 (env->regs[0 ],0 ,8 );uint32_t sc =extract32 (env->regs[0 ],8 ,8 );
@@ -1465,18 +1464,20 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,probe_write (env, a2,0 , mem_idx, ra);#endif -/* Note that the compare-and-swap is atomic, and the store is atomic, but -the complete operation is not. Therefore we do not need to assert serial -context in order to implement this. That said, restart early if we can't -support either operation that is supposed to be atomic. */ +/* +* Note that the compare-and-swap is atomic, and the store is atomic, +* but the complete operation is not. Therefore we do not need to +* assert serial context in order to implement this. That said, +* restart early if we can't support either operation that is supposed +* to be atomic. +*/ if (parallel) { -int mask =0 ; -#if !defined(CONFIG_ATOMIC64 ) - mask =-8 ; -#elif !defined(CONFIG_ATOMIC128 ) - mask =-16 ; +uint32_t max =2 ; +#ifdef CONFIG_ATOMIC64 + max =3 ;#endif -if (((4 << fc) | (1 << sc)) & mask) { +if ((HAVE_CMPXCHG128 ?0 : fc +2 > max) || + (HAVE_ATOMIC128 ?0 : sc > max)) {cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } }
@@ -1546,16 +1547,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,Int128 cv =int128_make128 (env->regs[r3 +1 ], env->regs[r3]);Int128 ov; -if (parallel) { -#ifdef CONFIG_ATOMIC128 -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); - ov =helper_atomic_cmpxchgo_be_mmu (env, a1, cv, nv, oi, ra); - cc = !int128_eq (ov, cv); -#else -/* Note that we asserted !parallel above. */ -g_assert_not_reached (); -#endif - }else { +if (!parallel) {uint64_t oh =cpu_ldq_data_ra (env, a1 +0 , ra);uint64_t ol =cpu_ldq_data_ra (env, a1 +8 , ra);
@@ -1567,6 +1559,13 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,cpu_stq_data_ra (env, a1 +0 ,int128_gethi (nv), ra);cpu_stq_data_ra (env, a1 +8 ,int128_getlo (nv), ra); + }else if (HAVE_CMPXCHG128 ) { +TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + ov =helper_atomic_cmpxchgo_be_mmu (env, a1, cv, nv, oi, ra); + cc = !int128_eq (ov, cv); + }else { +/* Note that we asserted !parallel above. */ +g_assert_not_reached (); } env->regs[r3 +0 ] =int128_gethi (ov);
@@ -1596,18 +1595,16 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,cpu_stq_data_ra (env, a2, svh, ra);break ;case 4 : -if (parallel) { -#ifdef CONFIG_ATOMIC128 +if (!parallel) { +cpu_stq_data_ra (env, a2 +0 , svh, ra); +cpu_stq_data_ra (env, a2 +8 , svl, ra); + }else if (HAVE_ATOMIC128 ) {TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 sv =int128_make128 (svl, svh);helper_atomic_sto_be_mmu (env, a2, sv, oi, ra); -#else + }else {/* Note that we asserted !parallel above. */ g_assert_not_reached (); -#endif - }else { -cpu_stq_data_ra (env, a2 +0 , svh, ra); -cpu_stq_data_ra (env, a2 +8 , svl, ra); }break ;default :
@@ -2105,21 +2102,18 @@ static uint64_t do_lpq(CPUS390XState *env, uint64_t addr, bool parallel)uintptr_t ra =GETPC ();uint64_t hi, lo; -if (parallel) { -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else +if (!parallel) { +check_alignment (env, addr,16 , ra); + hi =cpu_ldq_data_ra (env, addr +0 , ra); + lo =cpu_ldq_data_ra (env, addr +8 , ra); + }else if (HAVE_ATOMIC128 ) {int mem_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 v =helper_atomic_ldo_be_mmu (env, addr, oi, ra); hi =int128_gethi (v); lo =int128_getlo (v); -#endif }else { -check_alignment (env, addr,16 , ra); - - hi =cpu_ldq_data_ra (env, addr +0 , ra); - lo =cpu_ldq_data_ra (env, addr +8 , ra); +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } env->retxl = lo;
@@ -2142,21 +2136,17 @@ static void do_stpq(CPUS390XState *env, uint64_t addr, {uintptr_t ra =GETPC (); -if (parallel) { -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); - -Int128 v =int128_make128 (low, high); -helper_atomic_sto_be_mmu (env, addr, v, oi, ra); -#endif - }else { +if (!parallel) {check_alignment (env, addr,16 , ra); -cpu_stq_data_ra (env, addr +0 , high, ra);cpu_stq_data_ra (env, addr +8 , low, ra); + }else if (HAVE_ATOMIC128 ) { +int mem_idx =cpu_mmu_index (env, false); +TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); +Int128 v =int128_make128 (low, high); +helper_atomic_sto_be_mmu (env, addr, v, oi, ra); + }else { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } }
Signature · 1 line
2.17.1
Re: [Qemu-devel] [qemu-s390x] [PATCH v3 6/9] target/s390x: Convert to HAVE_CMPXCHG128 and HAVE_ATOMIC128
Quoted 173 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/s390x/mem_helper.c | 92 +++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 51 deletions(-)target/s390x/mem_helper.c +34
-51@@ -25,6 +25,7 @@#include "exec/exec-all.h" #include "exec/cpu_ldst.h" #include "qemu/int128.h" +#include "qemu/atomic128.h" #if !defined(CONFIG_USER_ONLY )#include "hw/s390x/storage-keys.h" @@ -1389,7 +1390,7 @@ static void do_cdsg(CPUS390XState *env, uint64_t addr,bool fail;if (parallel) { -#ifndef CONFIG_ATOMIC128 +#if !HAVE_CMPXCHG128 cpu_loop_exit_atomic (ENV_GET_CPU (env), ra);#else int mem_idx =cpu_mmu_index (env, false);@@ -1435,9 +1436,7 @@ void HELPER(cdsg_parallel)(CPUS390XState *env, uint64_t addr,static uint32_t do_csst (CPUS390XState *env,uint32_t r3,uint64_t a1,uint64_t a2,bool parallel) { -#if !defined(CONFIG_USER_ONLY ) || defined(CONFIG_ATOMIC128 )uint32_t mem_idx =cpu_mmu_index (env, false); -#endif uintptr_t ra =GETPC ();uint32_t fc =extract32 (env->regs[0 ],0 ,8 );uint32_t sc =extract32 (env->regs[0 ],8 ,8 );@@ -1465,18 +1464,20 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,probe_write (env, a2,0 , mem_idx, ra);#endif -/* Note that the compare-and-swap is atomic, and the store is atomic, but -the complete operation is not. Therefore we do not need to assert serial -context in order to implement this. That said, restart early if we can't -support either operation that is supposed to be atomic. */ +/* +* Note that the compare-and-swap is atomic, and the store is atomic, +* but the complete operation is not. Therefore we do not need to +* assert serial context in order to implement this. That said, +* restart early if we can't support either operation that is supposed +* to be atomic. +*/ if (parallel) { -int mask =0 ; -#if !defined(CONFIG_ATOMIC64 ) - mask =-8 ; -#elif !defined(CONFIG_ATOMIC128 ) - mask =-16 ; +uint32_t max =2 ; +#ifdef CONFIG_ATOMIC64 + max =3 ;#endif -if (((4 << fc) | (1 << sc)) & mask) { +if ((HAVE_CMPXCHG128 ?0 : fc +2 > max) || + (HAVE_ATOMIC128 ?0 : sc > max)) {cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } }@@ -1546,16 +1547,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,Int128 cv =int128_make128 (env->regs[r3 +1 ], env->regs[r3]);Int128 ov; -if (parallel) { -#ifdef CONFIG_ATOMIC128 -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); - ov =helper_atomic_cmpxchgo_be_mmu (env, a1, cv, nv, oi, ra); - cc = !int128_eq (ov, cv); -#else -/* Note that we asserted !parallel above. */ -g_assert_not_reached (); -#endif - }else { +if (!parallel) {uint64_t oh =cpu_ldq_data_ra (env, a1 +0 , ra);uint64_t ol =cpu_ldq_data_ra (env, a1 +8 , ra);@@ -1567,6 +1559,13 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,cpu_stq_data_ra (env, a1 +0 ,int128_gethi (nv), ra);cpu_stq_data_ra (env, a1 +8 ,int128_getlo (nv), ra); + }else if (HAVE_CMPXCHG128 ) { +TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + ov =helper_atomic_cmpxchgo_be_mmu (env, a1, cv, nv, oi, ra); + cc = !int128_eq (ov, cv); + }else { +/* Note that we asserted !parallel above. */ +g_assert_not_reached (); } env->regs[r3 +0 ] =int128_gethi (ov);@@ -1596,18 +1595,16 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,cpu_stq_data_ra (env, a2, svh, ra);break ;case 4 : -if (parallel) { -#ifdef CONFIG_ATOMIC128 +if (!parallel) { +cpu_stq_data_ra (env, a2 +0 , svh, ra); +cpu_stq_data_ra (env, a2 +8 , svl, ra); + }else if (HAVE_ATOMIC128 ) {TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 sv =int128_make128 (svl, svh);helper_atomic_sto_be_mmu (env, a2, sv, oi, ra); -#else + }else {/* Note that we asserted !parallel above. */ g_assert_not_reached (); -#endif - }else { -cpu_stq_data_ra (env, a2 +0 , svh, ra); -cpu_stq_data_ra (env, a2 +8 , svl, ra); }break ;default :@@ -2105,21 +2102,18 @@ static uint64_t do_lpq(CPUS390XState *env, uint64_t addr, bool parallel)uintptr_t ra =GETPC ();uint64_t hi, lo; -if (parallel) { -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else +if (!parallel) { +check_alignment (env, addr,16 , ra); + hi =cpu_ldq_data_ra (env, addr +0 , ra); + lo =cpu_ldq_data_ra (env, addr +8 , ra); + }else if (HAVE_ATOMIC128 ) {int mem_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 v =helper_atomic_ldo_be_mmu (env, addr, oi, ra); hi =int128_gethi (v); lo =int128_getlo (v); -#endif }else { -check_alignment (env, addr,16 , ra); - - hi =cpu_ldq_data_ra (env, addr +0 , ra); - lo =cpu_ldq_data_ra (env, addr +8 , ra); +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } env->retxl = lo;@@ -2142,21 +2136,17 @@ static void do_stpq(CPUS390XState *env, uint64_t addr, {uintptr_t ra =GETPC (); -if (parallel) { -#ifndef CONFIG_ATOMIC128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); - -Int128 v =int128_make128 (low, high); -helper_atomic_sto_be_mmu (env, addr, v, oi, ra); -#endif - }else { +if (!parallel) {check_alignment (env, addr,16 , ra); -cpu_stq_data_ra (env, addr +0 , high, ra);cpu_stq_data_ra (env, addr +8 , low, ra);
target/s390x/mem_helper.c static void do_stpq(CPUS390XState *env, uint64_t addr, · line 2152
Quoted 10 lines
target/s390x/mem_helper.c +7
-0+ }else if (HAVE_ATOMIC128 ) { +int mem_idx =cpu_mmu_index (env, false); +TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); +Int128 v =int128_make128 (low, high); +helper_atomic_sto_be_mmu (env, addr, v, oi, ra); + }else { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); } }
Only case 1 still looks fairly ugly with the ifdefs.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 7/9 target/s390x: Split do_cdsg, do_lpq, do_stpq
In reply to Richard Henderson--- target/s390x/mem_helper.c | 128 ++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 67 deletions(-)
target/s390x/mem_helper.c +61 -67
@@ -1380,57 +1380,58 @@ uint32_t HELPER(trXX)(CPUS390XState *env, uint32_t r1, uint32_t r2,return cc; } -static void do_cdsg (CPUS390XState *env,uint64_t addr, -uint32_t r1,uint32_t r3,bool parallel) +void HELPER (cdsg )(CPUS390XState *env,uint64_t addr, +uint32_t r1,uint32_t r3) {uintptr_t ra =GETPC ();Int128 cmpv =int128_make128 (env->regs[r1 +1 ], env->regs[r1]);Int128 newv =int128_make128 (env->regs[r3 +1 ], env->regs[r3]);Int128 oldv; +uint64_t oldh, oldl;bool fail; -if (parallel) { -#if !HAVE_CMPXCHG128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); - oldv =helper_atomic_cmpxchgo_be_mmu (env, addr, cmpv, newv, oi, ra); - fail = !int128_eq (oldv, cmpv); -#endif - }else { -uint64_t oldh, oldl; +check_alignment (env, addr,16 , ra); -check_alignment (env, addr,16 , ra); + oldh =cpu_ldq_data_ra (env, addr +0 , ra); + oldl =cpu_ldq_data_ra (env, addr +8 , ra); - oldh =cpu_ldq_data_ra (env, addr +0 , ra); - oldl =cpu_ldq_data_ra (env, addr +8 , ra); - - oldv =int128_make128 (oldl, oldh); - fail = !int128_eq (oldv, cmpv); -if (fail) { - newv = oldv; - } - -cpu_stq_data_ra (env, addr +0 ,int128_gethi (newv), ra); -cpu_stq_data_ra (env, addr +8 ,int128_getlo (newv), ra); + oldv =int128_make128 (oldl, oldh); + fail = !int128_eq (oldv, cmpv); +if (fail) { + newv = oldv; } +cpu_stq_data_ra (env, addr +0 ,int128_gethi (newv), ra); +cpu_stq_data_ra (env, addr +8 ,int128_getlo (newv), ra); + env->cc_op = fail; env->regs[r1] =int128_gethi (oldv); env->regs[r1 +1 ] =int128_getlo (oldv); } -void HELPER (cdsg )(CPUS390XState *env,uint64_t addr, -uint32_t r1,uint32_t r3) -{ -do_cdsg (env, addr, r1, r3, false); -} -void HELPER (cdsg_parallel )(CPUS390XState *env,uint64_t addr,uint32_t r1,uint32_t r3) { -do_cdsg (env, addr, r1, r3, true); +uintptr_t ra =GETPC (); +Int128 cmpv =int128_make128 (env->regs[r1 +1 ], env->regs[r1]); +Int128 newv =int128_make128 (env->regs[r3 +1 ], env->regs[r3]); +int mem_idx; +TCGMemOpIdx oi; +Int128 oldv; +bool fail; + +if (!HAVE_CMPXCHG128 ) { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); + } + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + oldv =helper_atomic_cmpxchgo_be_mmu (env, addr, cmpv, newv, oi, ra); + fail = !int128_eq (oldv, cmpv); + + env->cc_op = fail; + env->regs[r1] =int128_gethi (oldv); + env->regs[r1 +1 ] =int128_getlo (oldv); } static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,
@@ -2097,16 +2098,25 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr)#endif /* load pair from quadword */ -static uint64_t do_lpq (CPUS390XState *env,uint64_t addr,bool parallel) +uint64_t HELPER (lpq )(CPUS390XState *env,uint64_t addr) {uintptr_t ra =GETPC ();uint64_t hi, lo; -if (!parallel) { -check_alignment (env, addr,16 , ra); - hi =cpu_ldq_data_ra (env, addr +0 , ra); - lo =cpu_ldq_data_ra (env, addr +8 , ra); - }else if (HAVE_ATOMIC128 ) { +check_alignment (env, addr,16 , ra); + hi =cpu_ldq_data_ra (env, addr +0 , ra); + lo =cpu_ldq_data_ra (env, addr +8 , ra); + + env->retxl = lo; +return hi; +} + +uint64_t HELPER (lpq_parallel )(CPUS390XState *env,uint64_t addr) +{ +uintptr_t ra =GETPC (); +uint64_t hi, lo; + +if (HAVE_ATOMIC128 ) {int mem_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 v =helper_atomic_ldo_be_mmu (env, addr, oi, ra);
@@ -2120,27 +2130,23 @@ static uint64_t do_lpq(CPUS390XState *env, uint64_t addr, bool parallel)return hi; } -uint64_t HELPER (lpq )(CPUS390XState *env,uint64_t addr) -{ -return do_lpq (env, addr, false); -} - -uint64_t HELPER (lpq_parallel )(CPUS390XState *env,uint64_t addr) -{ -return do_lpq (env, addr, true); -} -/* store pair to quadword */ -static void do_stpq (CPUS390XState *env,uint64_t addr, -uint64_t low,uint64_t high,bool parallel) +void HELPER (stpq )(CPUS390XState *env,uint64_t addr, +uint64_t low,uint64_t high) {uintptr_t ra =GETPC (); -if (!parallel) { -check_alignment (env, addr,16 , ra); -cpu_stq_data_ra (env, addr +0 , high, ra); -cpu_stq_data_ra (env, addr +8 , low, ra); - }else if (HAVE_ATOMIC128 ) { +check_alignment (env, addr,16 , ra); +cpu_stq_data_ra (env, addr +0 , high, ra); +cpu_stq_data_ra (env, addr +8 , low, ra); +} + +void HELPER (stpq_parallel )(CPUS390XState *env,uint64_t addr, +uint64_t low,uint64_t high) +{ +uintptr_t ra =GETPC (); + +if (HAVE_ATOMIC128 ) {int mem_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 v =int128_make128 (low, high);
@@ -2150,18 +2156,6 @@ static void do_stpq(CPUS390XState *env, uint64_t addr, } } -void HELPER (stpq )(CPUS390XState *env,uint64_t addr, -uint64_t low,uint64_t high) -{ -do_stpq (env, addr, low, high, false); -} - -void HELPER (stpq_parallel )(CPUS390XState *env,uint64_t addr, -uint64_t low,uint64_t high) -{ -do_stpq (env, addr, low, high, true); -} -/* Execute instruction. This instruction executes an insn modified with the contents of r1. It does not change the executed instruction in memory; it does not change the program counter.
Signature · 1 line
2.17.1
Re: [Qemu-devel] [qemu-s390x] [PATCH v3 7/9] target/s390x: Split do_cdsg, do_lpq, do_stpq
Quoted 184 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/s390x/mem_helper.c | 128 ++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 67 deletions(-)target/s390x/mem_helper.c +61
-60@@ -1380,57 +1380,58 @@ uint32_t HELPER(trXX)(CPUS390XState *env, uint32_t r1, uint32_t r2,return cc; } -static void do_cdsg (CPUS390XState *env,uint64_t addr, -uint32_t r1,uint32_t r3,bool parallel) +void HELPER (cdsg )(CPUS390XState *env,uint64_t addr, +uint32_t r1,uint32_t r3) {uintptr_t ra =GETPC ();Int128 cmpv =int128_make128 (env->regs[r1 +1 ], env->regs[r1]);Int128 newv =int128_make128 (env->regs[r3 +1 ], env->regs[r3]);Int128 oldv; +uint64_t oldh, oldl;bool fail; -if (parallel) { -#if !HAVE_CMPXCHG128 -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); -#else -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); - oldv =helper_atomic_cmpxchgo_be_mmu (env, addr, cmpv, newv, oi, ra); - fail = !int128_eq (oldv, cmpv); -#endif - }else { -uint64_t oldh, oldl; +check_alignment (env, addr,16 , ra); -check_alignment (env, addr,16 , ra); + oldh =cpu_ldq_data_ra (env, addr +0 , ra); + oldl =cpu_ldq_data_ra (env, addr +8 , ra); - oldh =cpu_ldq_data_ra (env, addr +0 , ra); - oldl =cpu_ldq_data_ra (env, addr +8 , ra); - - oldv =int128_make128 (oldl, oldh); - fail = !int128_eq (oldv, cmpv); -if (fail) { - newv = oldv; - } - -cpu_stq_data_ra (env, addr +0 ,int128_gethi (newv), ra); -cpu_stq_data_ra (env, addr +8 ,int128_getlo (newv), ra); + oldv =int128_make128 (oldl, oldh); + fail = !int128_eq (oldv, cmpv); +if (fail) { + newv = oldv; } +cpu_stq_data_ra (env, addr +0 ,int128_gethi (newv), ra); +cpu_stq_data_ra (env, addr +8 ,int128_getlo (newv), ra); + env->cc_op = fail; env->regs[r1] =int128_gethi (oldv); env->regs[r1 +1 ] =int128_getlo (oldv); } -void HELPER (cdsg )(CPUS390XState *env,uint64_t addr, -uint32_t r1,uint32_t r3) -{ -do_cdsg (env, addr, r1, r3, false); -} -void HELPER (cdsg_parallel )(CPUS390XState *env,uint64_t addr,uint32_t r1,uint32_t r3) { -do_cdsg (env, addr, r1, r3, true); +uintptr_t ra =GETPC (); +Int128 cmpv =int128_make128 (env->regs[r1 +1 ], env->regs[r1]); +Int128 newv =int128_make128 (env->regs[r3 +1 ], env->regs[r3]); +int mem_idx; +TCGMemOpIdx oi; +Int128 oldv; +bool fail; + +if (!HAVE_CMPXCHG128 ) { +cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); + } + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + oldv =helper_atomic_cmpxchgo_be_mmu (env, addr, cmpv, newv, oi, ra); + fail = !int128_eq (oldv, cmpv); + + env->cc_op = fail; + env->regs[r1] =int128_gethi (oldv); + env->regs[r1 +1 ] =int128_getlo (oldv); } static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,@@ -2097,16 +2098,25 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr)#endif /* load pair from quadword */ -static uint64_t do_lpq (CPUS390XState *env,uint64_t addr,bool parallel) +uint64_t HELPER (lpq )(CPUS390XState *env,uint64_t addr) {uintptr_t ra =GETPC ();uint64_t hi, lo; -if (!parallel) { -check_alignment (env, addr,16 , ra); - hi =cpu_ldq_data_ra (env, addr +0 , ra); - lo =cpu_ldq_data_ra (env, addr +8 , ra); - }else if (HAVE_ATOMIC128 ) { +check_alignment (env, addr,16 , ra); + hi =cpu_ldq_data_ra (env, addr +0 , ra); + lo =cpu_ldq_data_ra (env, addr +8 , ra); + + env->retxl = lo; +return hi; +} + +uint64_t HELPER (lpq_parallel )(CPUS390XState *env,uint64_t addr) +{ +uintptr_t ra =GETPC (); +uint64_t hi, lo; + +if (HAVE_ATOMIC128 ) {int mem_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 v =helper_atomic_ldo_be_mmu (env, addr, oi, ra);@@ -2120,27 +2130,23 @@ static uint64_t do_lpq(CPUS390XState *env, uint64_t addr, bool parallel)return hi; } -uint64_t HELPER (lpq )(CPUS390XState *env,uint64_t addr) -{ -return do_lpq (env, addr, false); -} - -uint64_t HELPER (lpq_parallel )(CPUS390XState *env,uint64_t addr) -{ -return do_lpq (env, addr, true); -} -/* store pair to quadword */ -static void do_stpq (CPUS390XState *env,uint64_t addr, -uint64_t low,uint64_t high,bool parallel) +void HELPER (stpq )(CPUS390XState *env,uint64_t addr, +uint64_t low,uint64_t high) {uintptr_t ra =GETPC (); -if (!parallel) { -check_alignment (env, addr,16 , ra); -cpu_stq_data_ra (env, addr +0 , high, ra); -cpu_stq_data_ra (env, addr +8 , low, ra); - }else if (HAVE_ATOMIC128 ) { +check_alignment (env, addr,16 , ra); +cpu_stq_data_ra (env, addr +0 , high, ra); +cpu_stq_data_ra (env, addr +8 , low, ra); +} + +void HELPER (stpq_parallel )(CPUS390XState *env,uint64_t addr, +uint64_t low,uint64_t high) +{ +uintptr_t ra =GETPC (); + +if (HAVE_ATOMIC128 ) {int mem_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);Int128 v =int128_make128 (low, high);@@ -2150,18 +2156,6 @@ static void do_stpq(CPUS390XState *env, uint64_t addr, } } -void HELPER (stpq )(CPUS390XState *env,uint64_t addr, -uint64_t low,uint64_t high) -{ -do_stpq (env, addr, low, high, false); -}
target/s390x/mem_helper.c static void do_stpq(CPUS390XState *env, uint64_t addr, · line 2161
Quoted 10 lines
target/s390x/mem_helper.c +0
-7- -void HELPER (stpq_parallel )(CPUS390XState *env,uint64_t addr, -uint64_t low,uint64_t high) -{ -do_stpq (env, addr, low, high, true); -} -/* Execute instruction. This instruction executes an insn modified with the contents of r1. It does not change the executed instruction in memory; it does not change the program counter.
Way easier to read.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 8/9 target/s390x: Skip wout, cout helpers if op helper does not return
In reply to Richard HendersonWhen op raises an exception, it may not have initialized the output temps that would be written back by wout or cout.
--- target/s390x/translate.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
target/s390x/translate.c +7 -5
@@ -6164,11 +6164,13 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)if (insn->help_op) { ret = insn->help_op (s, &o); } -if (insn->help_wout) { - insn->help_wout (s, &f, &o); - } -if (insn->help_cout) { - insn->help_cout (s, &o); +if (ret !=DISAS_NORETURN ) { +if (insn->help_wout) { + insn->help_wout (s, &f, &o); + } +if (insn->help_cout) { + insn->help_cout (s, &o); + } }/* Free any temporaries created by the helpers. */
Signature · 1 line
2.17.1
Re: [Qemu-devel] [qemu-s390x] [PATCH v3 8/9] target/s390x: Skip wout, cout helpers if op helper does not return
Quoted 23 lines · Richard Henderson
When op raises an exception, it may not have initialized the output temps that would be written back by wout or cout.
Signed-off-by Richard Henderson <[email protected]>--- target/s390x/translate.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)target/s390x/translate.c +0
-5@@ -6164,11 +6164,13 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)if (insn->help_op) { ret = insn->help_op (s, &o); } -if (insn->help_wout) { - insn->help_wout (s, &f, &o); - } -if (insn->help_cout) { - insn->help_cout (s, &o);
target/s390x/translate.c static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s) · line 6176
Quoted 10 lines
target/s390x/translate.c +7
-0+if (ret !=DISAS_NORETURN ) { +if (insn->help_wout) { + insn->help_wout (s, &f, &o); + } +if (insn->help_cout) { + insn->help_cout (s, &o); + } }/* Free any temporaries created by the helpers. */
What about things like LPSW/LPWSE ? They certainly don't imply that we had an exception.
(these two don't use wout/cout, so it is still fine, but I would prefer a comment somewhere because otherwise it is really easy to miss that DISAS_NORETURN makes us skip these handlers)
Apart from that
Signature · 3 lines
Thanks, David / dhildenb
Re: [Qemu-devel] [qemu-s390x] [PATCH v3 8/9] target/s390x: Skip wout, cout helpers if op helper does not return
Quoted 32 lines · David Hildenbrand
Quoted 31 lines · Richard Henderson
When op raises an exception, it may not have initialized the output temps that would be written back by wout or cout.
Signed-off-by Richard Henderson <[email protected]>--- target/s390x/translate.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)target/s390x/translate.c +7
-5@@ -6164,11 +6164,13 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)if (insn->help_op) { ret = insn->help_op (s, &o); } -if (insn->help_wout) { - insn->help_wout (s, &f, &o); - } -if (insn->help_cout) { - insn->help_cout (s, &o); +if (ret !=DISAS_NORETURN ) { +if (insn->help_wout) { + insn->help_wout (s, &f, &o); + } +if (insn->help_cout) { + insn->help_cout (s, &o); + } }
Quoted 5 lines
target/s390x/translate.c static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s) · line 6176
Quoted 2 lines
target/s390x/translate.c +0
-0/* Free any temporaries created by the helpers. */ What about things like LPSW/LPWSE ? They certainly don't imply that we had an exception.
Exception in the tcg sense, not the guest architectural sense, in that we call cpu_loop_exit from the helper, which performs a longjmp. (Incidentally, there's no reason to do that for load_psw -- we could just exit the tb normally.)
Quoted 3 lines
(these two don't use wout/cout, so it is still fine, but I would prefer a comment somewhere because otherwise it is really easy to miss that
DISAS_NORETURNmakes us skip these handlers)
Where would you like me to place that comment? In the DisasInsn definition?
r~
Re: [Qemu-devel] [qemu-s390x] [PATCH v3 8/9] target/s390x: Skip wout, cout helpers if op helper does not return
Quoted 43 lines · Richard Henderson
Quoted 32 lines · David Hildenbrand
Quoted 31 lines · Richard Henderson
When op raises an exception, it may not have initialized the output temps that would be written back by wout or cout.
Signed-off-by Richard Henderson <[email protected]>--- target/s390x/translate.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)target/s390x/translate.c +7
-5@@ -6164,11 +6164,13 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)if (insn->help_op) { ret = insn->help_op (s, &o); } -if (insn->help_wout) { - insn->help_wout (s, &f, &o); - } -if (insn->help_cout) { - insn->help_cout (s, &o); +if (ret !=DISAS_NORETURN ) { +if (insn->help_wout) { + insn->help_wout (s, &f, &o); + } +if (insn->help_cout) { + insn->help_cout (s, &o); + } }Quoted 5 lines
target/s390x/translate.c static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s) · line 6176
Quoted 2 lines
target/s390x/translate.c +0
-0/* Free any temporaries created by the helpers. */ What about things like LPSW/LPWSE ? They certainly don't imply that we had an exception.
Exception in the tcg sense, not the guest architectural sense, in that we call
cpu_loop_exitfrom the helper, which performs a longjmp. (Incidentally, there's no reason to do that forload_psw-- we could just exit the tb normally.)
Quoted 5 lines
Quoted 3 lines
(these two don't use wout/cout, so it is still fine, but I would prefer a comment somewhere because otherwise it is really easy to miss that
DISAS_NORETURNmakes us skip these handlers)Where would you like me to place that comment? In the DisasInsn definition?
That probably makes sense!
Quoted 4 lines
r~
Signature · 3 lines
Thanks, David / dhildenb
PATCH v3 9/9 target/s390x: Check HAVE_ATOMIC128 and HAVE_CMPXCHG128 at translate
In reply to Richard Henderson--- target/s390x/mem_helper.c | 40 +++++++++++++++++++-------------------- target/s390x/translate.c | 25 +++++++++++++++++------- 2 files changed, 38 insertions(+), 27 deletions(-)
target/s390x/mem_helper.c +20 -20
@@ -1420,9 +1420,7 @@ void HELPER(cdsg_parallel)(CPUS390XState *env, uint64_t addr,Int128 oldv;bool fail; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);
@@ -2115,16 +2113,17 @@ uint64_t HELPER(lpq_parallel)(CPUS390XState *env, uint64_t addr) {uintptr_t ra =GETPC ();uint64_t hi, lo; +int mem_idx; +TCGMemOpIdx oi; +Int128 v; -if (HAVE_ATOMIC128 ) { -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); -Int128 v =helper_atomic_ldo_be_mmu (env, addr, oi, ra); - hi =int128_gethi (v); - lo =int128_getlo (v); - }else { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_ATOMIC128 ); + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + v =helper_atomic_ldo_be_mmu (env, addr, oi, ra); + hi =int128_gethi (v); + lo =int128_getlo (v); env->retxl = lo;return hi;
@@ -2145,15 +2144,16 @@ void HELPER(stpq_parallel)(CPUS390XState *env, uint64_t addr, uint64_t low, uint64_t high) { uintptr_t ra = GETPC(); +int mem_idx; +TCGMemOpIdx oi; +Int128 v; -if (HAVE_ATOMIC128 ) { -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); -Int128 v =int128_make128 (low, high); -helper_atomic_sto_be_mmu (env, addr, v, oi, ra); - }else { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_ATOMIC128 ); + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + v =int128_make128 (low, high); +helper_atomic_sto_be_mmu (env, addr, v, oi, ra); }/* Execute instruction. This instruction executes an insn modified with
target/s390x/translate.c +18 -7
@@ -44,6 +44,7 @@#include "trace-tcg.h" #include "exec/translator.h" #include "exec/log.h" +#include "qemu/atomic128.h" /* Information that (most) every instruction needs to manipulate. */
@@ -2032,6 +2033,7 @@ static DisasJumpType op_cdsg(DisasContext *s, DisasOps *o)int r3 =get_field (s->fields, r3);int d2 =get_field (s->fields, d2);int b2 =get_field (s->fields, b2); +DisasJumpType ret =DISAS_NEXT ;TCGv_i64 addr;TCGv_i32 t_r1, t_r3;
@@ -2039,17 +2041,20 @@ static DisasJumpType op_cdsg(DisasContext *s, DisasOps *o) addr =get_address (s,0 , b2, d2); t_r1 =tcg_const_i32 (r1); t_r3 =tcg_const_i32 (r3); -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { +gen_helper_cdsg (cpu_env, addr, t_r1, t_r3); + }else if (HAVE_CMPXCHG128 ) {gen_helper_cdsg_parallel (cpu_env, addr, t_r1, t_r3); }else { -gen_helper_cdsg (cpu_env, addr, t_r1, t_r3); +gen_helper_exit_atomic (cpu_env); + ret =DISAS_NORETURN ; }tcg_temp_free_i64 (addr);tcg_temp_free_i32 (t_r1);tcg_temp_free_i32 (t_r3);set_cc_static (s); -return DISAS_NEXT ; +return ret; }static DisasJumpType op_csst (DisasContext *s,DisasOps *o)
@@ -3036,10 +3041,13 @@ static DisasJumpType op_lpd(DisasContext *s, DisasOps *o)static DisasJumpType op_lpq (DisasContext *s,DisasOps *o) { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { +gen_helper_lpq (o->out, cpu_env, o->in2); + }else if (HAVE_ATOMIC128 ) {gen_helper_lpq_parallel (o->out, cpu_env, o->in2); }else { -gen_helper_lpq (o->out, cpu_env, o->in2); +gen_helper_exit_atomic (cpu_env); +return DISAS_NORETURN ; }return_low128 (o->out2);return DISAS_NEXT ;
@@ -4462,10 +4470,13 @@ static DisasJumpType op_stmh(DisasContext *s, DisasOps *o)static DisasJumpType op_stpq (DisasContext *s,DisasOps *o) { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { +gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); + }else if (HAVE_ATOMIC128 ) {gen_helper_stpq_parallel (cpu_env, o->in2, o->out2, o->out); }else { -gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); +gen_helper_exit_atomic (cpu_env); +return DISAS_NORETURN ; }return DISAS_NEXT ; }
Signature · 1 line
2.17.1
Re: [Qemu-devel] [qemu-s390x] [PATCH v3 9/9] target/s390x: Check HAVE_ATOMIC128 and HAVE_CMPXCHG128 at translate
Quoted 141 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/s390x/mem_helper.c | 40 +++++++++++++++++++-------------------- target/s390x/translate.c | 25 +++++++++++++++++------- 2 files changed, 38 insertions(+), 27 deletions(-)target/s390x/mem_helper.c +20
-20@@ -1420,9 +1420,7 @@ void HELPER(cdsg_parallel)(CPUS390XState *env, uint64_t addr,Int128 oldv;bool fail; -if (!HAVE_CMPXCHG128 ) { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_CMPXCHG128 ); mem_idx =cpu_mmu_index (env, false); oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx);@@ -2115,16 +2113,17 @@ uint64_t HELPER(lpq_parallel)(CPUS390XState *env, uint64_t addr) {uintptr_t ra =GETPC ();uint64_t hi, lo; +int mem_idx; +TCGMemOpIdx oi; +Int128 v; -if (HAVE_ATOMIC128 ) { -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); -Int128 v =helper_atomic_ldo_be_mmu (env, addr, oi, ra); - hi =int128_gethi (v); - lo =int128_getlo (v); - }else { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_ATOMIC128 ); + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + v =helper_atomic_ldo_be_mmu (env, addr, oi, ra); + hi =int128_gethi (v); + lo =int128_getlo (v); env->retxl = lo;return hi;@@ -2145,15 +2144,16 @@ void HELPER(stpq_parallel)(CPUS390XState *env, uint64_t addr, uint64_t low, uint64_t high) { uintptr_t ra = GETPC(); +int mem_idx; +TCGMemOpIdx oi; +Int128 v; -if (HAVE_ATOMIC128 ) { -int mem_idx =cpu_mmu_index (env, false); -TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); -Int128 v =int128_make128 (low, high); -helper_atomic_sto_be_mmu (env, addr, v, oi, ra); - }else { -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - } +assert (HAVE_ATOMIC128 ); + + mem_idx =cpu_mmu_index (env, false); + oi =make_memop_idx (MO_TEQ |MO_ALIGN_16 , mem_idx); + v =int128_make128 (low, high); +helper_atomic_sto_be_mmu (env, addr, v, oi, ra); }/* Execute instruction. This instruction executes an insn modified with target/s390x/translate.c +14
-6@@ -44,6 +44,7 @@#include "trace-tcg.h" #include "exec/translator.h" #include "exec/log.h" +#include "qemu/atomic128.h" /* Information that (most) every instruction needs to manipulate. */ @@ -2032,6 +2033,7 @@ static DisasJumpType op_cdsg(DisasContext *s, DisasOps *o)int r3 =get_field (s->fields, r3);int d2 =get_field (s->fields, d2);int b2 =get_field (s->fields, b2); +DisasJumpType ret =DISAS_NEXT ;TCGv_i64 addr;TCGv_i32 t_r1, t_r3;@@ -2039,17 +2041,20 @@ static DisasJumpType op_cdsg(DisasContext *s, DisasOps *o) addr =get_address (s,0 , b2, d2); t_r1 =tcg_const_i32 (r1); t_r3 =tcg_const_i32 (r3); -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { +gen_helper_cdsg (cpu_env, addr, t_r1, t_r3); + }else if (HAVE_CMPXCHG128 ) {gen_helper_cdsg_parallel (cpu_env, addr, t_r1, t_r3); }else { -gen_helper_cdsg (cpu_env, addr, t_r1, t_r3); +gen_helper_exit_atomic (cpu_env); + ret =DISAS_NORETURN ; }tcg_temp_free_i64 (addr);tcg_temp_free_i32 (t_r1);tcg_temp_free_i32 (t_r3);set_cc_static (s); -return DISAS_NEXT ; +return ret; }static DisasJumpType op_csst (DisasContext *s,DisasOps *o)@@ -3036,10 +3041,13 @@ static DisasJumpType op_lpd(DisasContext *s, DisasOps *o)static DisasJumpType op_lpq (DisasContext *s,DisasOps *o) { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { +gen_helper_lpq (o->out, cpu_env, o->in2); + }else if (HAVE_ATOMIC128 ) {gen_helper_lpq_parallel (o->out, cpu_env, o->in2); }else { -gen_helper_lpq (o->out, cpu_env, o->in2); +gen_helper_exit_atomic (cpu_env); +return DISAS_NORETURN ; }return_low128 (o->out2);return DISAS_NEXT ;@@ -4462,10 +4470,13 @@ static DisasJumpType op_stmh(DisasContext *s, DisasOps *o)static DisasJumpType op_stpq (DisasContext *s,DisasOps *o) { -if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) {
target/s390x/translate.c static DisasJumpType op_stmh(DisasContext *s, DisasOps *o) · line 4482
Quoted 10 lines
target/s390x/translate.c +4
-1+gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); + }else if (HAVE_ATOMIC128 ) {gen_helper_stpq_parallel (cpu_env, o->in2, o->out2, o->out); }else { -gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); +gen_helper_exit_atomic (cpu_env); +return DISAS_NORETURN ; }return DISAS_NEXT ; }
Signature · 3 lines
Thanks, David / dhildenb
On Wed, Oct 03, 2018 at 14:39:22 -0500, Richard Henderson wrote:
(snip)
Quoted 10 lines
Richard Henderson (9):
tcg: SplitCONFIG_ATOMIC128
target/i386: Convert toHAVE_CMPXCHG128
target/arm: Convert toHAVE_CMPXCHG128
target/arm: CheckHAVE_CMPXCHG128at translate time target/ppc: Convert toHAVE_CMPXCHG128andHAVE_ATOMIC128target/s390x: Convert toHAVE_CMPXCHG128andHAVE_ATOMIC128target/s390x: Splitdo_cdsg,do_lpq,do_stpqtarget/s390x: Skip wout, cout helpers if op helper does not return target/s390x: CheckHAVE_ATOMIC128andHAVE_CMPXCHG128at translate
Cc'ing ppc/s390x maintainers -- I'm not sure they've seen this series. Link to this thread (v3):
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg00598.html
I'm eager to get this merged, particularly for i386 where it is fixing unnecessary exits via exec_atomic for cmpxchg16 emulation.
Thanks,
Emilio
Quoted 17 lines · Emilio G. Cota
On Wed, Oct 03, 2018 at 14:39:22 -0500, Richard Henderson wrote:
(snip)Quoted 10 lines
Richard Henderson (9):
tcg: SplitCONFIG_ATOMIC128
target/i386: Convert toHAVE_CMPXCHG128
target/arm: Convert toHAVE_CMPXCHG128
target/arm: CheckHAVE_CMPXCHG128at translate time target/ppc: Convert toHAVE_CMPXCHG128andHAVE_ATOMIC128target/s390x: Convert toHAVE_CMPXCHG128andHAVE_ATOMIC128target/s390x: Splitdo_cdsg,do_lpq,do_stpqtarget/s390x: Skip wout, cout helpers if op helper does not return target/s390x: CheckHAVE_ATOMIC128andHAVE_CMPXCHG128at translateCc'ing ppc/s390x maintainers -- I'm not sure they've seen this series. Link to this thread (v3):
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg00598.html
Quoted 7 lines
I'm eager to get this merged, particularly for i386 where it is fixing unnecessary exits via
exec_atomicfor cmpxchg16 emulation.Thanks,
Emilio
Thanks for the CC, I indeed haven't seen it.
Signature · 3 lines
Thanks, David / dhildenb