From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHboF-0006lI-FY for qemu-devel@nongnu.org; Mon, 27 Jun 2016 15:03:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHboB-0008NA-5o for qemu-devel@nongnu.org; Mon, 27 Jun 2016 15:03:02 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:44733) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHbo8-0008CC-RJ for qemu-devel@nongnu.org; Mon, 27 Jun 2016 15:02:59 -0400 From: "Emilio G. Cota" Date: Mon, 27 Jun 2016 15:02:07 -0400 Message-Id: <1467054136-10430-22-git-send-email-cota@braap.org> In-Reply-To: <1467054136-10430-1-git-send-email-cota@braap.org> References: <1467054136-10430-1-git-send-email-cota@braap.org> Subject: [Qemu-devel] [RFC 21/30] target-arm: add cmpxchg helpers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers , MTTCG Devel Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Richard Henderson , Sergey Fedorov , Alvise Rigo , Peter Maydell Signed-off-by: Emilio G. Cota --- target-arm/helper.c | 35 +++++++++++++++++++++++++++++++++++ target-arm/helper.h | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/target-arm/helper.c b/target-arm/helper.c index 1f9cdac..b38bfbd 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -9409,3 +9409,38 @@ uint32_t HELPER(crc32c)(uint32_t acc, uint32_t val, uint32_t bytes) /* Linux crc32c converts the output to one's complement. */ return crc32c(acc, buf, bytes) ^ 0xffffffff; } + +/* returns 0 on success; 1 otherwise */ +#define GEN_CMPXCHG(NAME) \ +uint32_t \ +HELPER(NAME)(CPUARMState *env, uint32_t addr, uint64_t old64, uint32_t new) \ +{ \ + uint32_t old = old64; \ + uint32_t read; \ + \ + read = glue(glue(cpu_, NAME), _data_ra)(env, addr, old, new, GETPC()); \ + return read != old; \ +} +GEN_CMPXCHG(cmpxchgb) +GEN_CMPXCHG(cmpxchgw) +GEN_CMPXCHG(cmpxchgl) +#undef GEN_CMPXCHG + +/* + * Returns 0 on success; 1 otherwise. + * Bringing in @new_lo and @new_hi is unusual given that @old is 64-bit, + * but we do it to save a few TCG instructions. + */ +uint32_t HELPER(cmpxchgq)(CPUARMState *env, uint32_t addr, uint64_t old, + uint32_t new_lo, uint32_t new_hi) +{ + uint64_t read; + uint64_t new; + + new = new_hi; + new <<= 32; + new |= new_lo; + + read = cpu_cmpxchgq_data_ra(env, addr, old, new, GETPC()); + return read != old; +} diff --git a/target-arm/helper.h b/target-arm/helper.h index 84aa637..f3d6f26 100644 --- a/target-arm/helper.h +++ b/target-arm/helper.h @@ -537,6 +537,11 @@ DEF_HELPER_2(dc_zva, void, env, i64) DEF_HELPER_FLAGS_2(neon_pmull_64_lo, TCG_CALL_NO_RWG_SE, i64, i64, i64) DEF_HELPER_FLAGS_2(neon_pmull_64_hi, TCG_CALL_NO_RWG_SE, i64, i64, i64) +DEF_HELPER_4(cmpxchgb, i32, env, i32, i64, i32) +DEF_HELPER_4(cmpxchgw, i32, env, i32, i64, i32) +DEF_HELPER_4(cmpxchgl, i32, env, i32, i64, i32) +DEF_HELPER_5(cmpxchgq, i32, env, i32, i64, i32, i32) + #ifdef TARGET_AARCH64 #include "helper-a64.h" #endif -- 2.5.0