about summary refs log tree commit diff stats
path: root/tests/test29.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-12-03 18:26:11 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-12-03 18:26:11 +0100
commitb67975a820d481577f8ea7515858b2f35450b0d0 (patch)
tree4b9e322c9e2fa04267dbe2046539b12b2af7af6d /tests/test29.c
parentfa175e7d2405d0b521cfd98d549a94252b697bf6 (diff)
downloadbox64-b67975a820d481577f8ea7515858b2f35450b0d0.tar.gz
box64-b67975a820d481577f8ea7515858b2f35450b0d0.zip
[ARM64_DYNAREC] More work on LOCK prefixed opcodes (Atomic still disabled)
Diffstat (limited to 'tests/test29.c')
-rw-r--r--tests/test29.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test29.c b/tests/test29.c
new file mode 100644
index 00000000..96384251
--- /dev/null
+++ b/tests/test29.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <string.h>
+#include <stddef.h>
+#include <stdint.h>
+// Build with `gcc -march=core2 -O0 test29.c -o test29`
+
+uint64_t lock_xadd(uint64_t Gd, uint64_t volatile* Ed) {
+uint64_t Res;
+asm(
+"lock xadd %[_Gd], (%[_Ed])\n"
+"movq %[_Gd], %[_Res]\n"
+: [_Res] "+r"(Res)
+: [_Gd] "r"(Gd)
+, [_Ed] "r"(Ed)
+);
+return Res;
+}
+
+uint64_t lock_xchg(uint64_t Gd, uint64_t volatile* Ed) {
+uint64_t Res;
+asm(
+"lock xchg %[_Gd], (%[_Ed])\n"
+"movq %[_Gd], %[_Res]\n"
+: [_Res] "+r"(Res)
+: [_Gd] "r"(Gd)
+, [_Ed] "r"(Ed)
+);
+return Res;
+}
+
+int main() {
+uint64_t Gd = 0x123;
+uint64_t volatile Ed = 0x456;
+uint64_t Res = lock_xadd(Gd, &Ed);
+printf("Lock XADD: Res = 0x%lx, Ed = 0x%lx\n", Res, Ed);
+Gd = 0x123;
+Res = lock_xchg(Gd, &Ed);
+printf("Lock XCHG: Res = 0x%lx, Ed = 0x%lx\n", Res, Ed);
+return 0;
+}