diff mbox

[RFC,21/30] target-arm: add cmpxchg helpers

Message ID 1467054136-10430-22-git-send-email-cota@braap.org (mailing list archive)
State New, archived
Headers show

Commit Message

Emilio Cota June 27, 2016, 7:02 p.m. UTC
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 target-arm/helper.c | 35 +++++++++++++++++++++++++++++++++++
 target-arm/helper.h |  5 +++++
 2 files changed, 40 insertions(+)
diff mbox

Patch

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