From baeed85dd8d1c7ef54a72bf2db2381d03de05cb6 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Thu, 11 Apr 2019 17:07:24 +0200 Subject: builtin acswapd --- runtime/include/ccomp_k1c_fixes.h | 7 ++++++- runtime/mppa_k1c/vararg.S | 11 ++++++++++- test/monniaux/int128/test_swap.c | 13 +++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/monniaux/int128/test_swap.c diff --git a/runtime/include/ccomp_k1c_fixes.h b/runtime/include/ccomp_k1c_fixes.h index 679ab1ac..b42323b8 100644 --- a/runtime/include/ccomp_k1c_fixes.h +++ b/runtime/include/ccomp_k1c_fixes.h @@ -1,11 +1,16 @@ #ifndef __CCOMP_KIC_FIXES_H #define __CCOMP_KIC_FIXES_H +#if ! (defined(__COMPCERT__) && defined (__K1C__)) +#error This header is solely for CompCert on K1C +#endif + #undef __GNUC__ #define __thread struct __int128_ccomp { long __int128_ccomp_low; long __int128_ccomp_high; }; #define __int128 struct __int128_ccomp - +#define __builtin_k1_acswapd __compcert_acswapd +extern __int128 __compcert_acswapd(unsigned long long *address, unsigned long long new_value, unsigned long long old_value); #endif diff --git a/runtime/mppa_k1c/vararg.S b/runtime/mppa_k1c/vararg.S index 8054068b..dbd7b96d 100644 --- a/runtime/mppa_k1c/vararg.S +++ b/runtime/mppa_k1c/vararg.S @@ -74,4 +74,13 @@ __compcert_va_composite: addd $r12 = $r12, 16 ;; ret -;; + ;; + +# FIXME this assumes pass-by-reference + .globl __compcert_acswapd +__compcert_acswapd: + acswapd 0[$r1] = $r2r3 + ;; + sq 0[$r0] = $r2r3 + ret + ;; diff --git a/test/monniaux/int128/test_swap.c b/test/monniaux/int128/test_swap.c new file mode 100644 index 00000000..4841f040 --- /dev/null +++ b/test/monniaux/int128/test_swap.c @@ -0,0 +1,13 @@ +#include + +int main() { + unsigned long long loc=10, next=12, current=11; + union { + __int128 i128; + struct { + unsigned long low, high; + } i64_2; + } ret; + ret.i128 = __builtin_k1_acswapd(&loc, next, current); + printf("%lx %lx\n", ret.i64_2.low, ret.i64_2.high); +} -- cgit