[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 21/30] target-arm: add cmpxchg helpers
From: |
Emilio G. Cota |
Subject: |
[Qemu-devel] [RFC 21/30] target-arm: add cmpxchg helpers |
Date: |
Mon, 27 Jun 2016 15:02:07 -0400 |
Signed-off-by: Emilio G. Cota <address@hidden>
---
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
- [Qemu-devel] [RFC 23/30] target-arm: add atomic_xchg helper, (continued)
- [Qemu-devel] [RFC 23/30] target-arm: add atomic_xchg helper, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 22/30] target-arm: emulate LL/SC using cmpxchg helpers, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 29/30] linux-user: remove handling of aarch64's EXCP_STREX, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 20/30] target-i386: remove helper_lock(), Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 26/30] target-arm: add cmpxchg helpers for aarch64, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 17/30] target-i386: emulate LOCK'ed BTX ops using atomic helpers, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 24/30] target-arm: emulate SWP with atomic_xchg helper, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 30/30] target-arm: remove EXCP_STREX + cpu_exclusive_{test, info}, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 18/30] target-i386: emulate XCHG using atomic helper, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 28/30] linux-user: remove handling of ARM's EXCP_STREX, Emilio G. Cota, 2016/06/27
- [Qemu-devel] [RFC 21/30] target-arm: add cmpxchg helpers,
Emilio G. Cota <=
- [Qemu-devel] [RFC 19/30] tests: add atomic_add-bench, Emilio G. Cota, 2016/06/27
- Re: [Qemu-devel] [RFC 00/30] cmpxchg-based emulation of atomics, LluĂs Vilanova, 2016/06/28