From 0e1b4722736e5dfa86dddd7aae5cf5751c2a7011 Mon Sep 17 00:00:00 2001 From: Tyler Young Date: Mon, 9 May 2022 12:01:11 -0400 Subject: [PATCH] TYoungSL: fixed atomic.h for arm64 Rjs: upgraded myst to fix attr Co-authored-by: Robert J Spencer --- docs/requirements.txt | 4 ++- src/atomic.h | 62 +++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 2d372e7..ffd0c33 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,8 @@ clang==10.0.1 furo==2022.3.4 hawkmoth==0.10.0 -myst-parser==0.17.0 +myst-parser==0.17.2 Sphinx==4.4.0 sphinx-multiversion==0.2.4 +sphinxext-opengraph==0.6.2 +sphinx-version-warning==1.1.2 diff --git a/src/atomic.h b/src/atomic.h index b81e2b9..d4d2c78 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -97,38 +97,38 @@ bool cas(intptr2_t *target, intptr2_t *comparand, intptr2_t *exchange) { // based on atomic.cc from Google's Fuchsia under MIT // this is an implementation with the strongest semantics - volatile intptr2_t* ptr = (volatile intptr2_t*)target; - intptr2_t* expected = (intptr2_t*)comparand; + volatile intptr2_t *ptr = (volatile intptr2_t *) target; + intptr2_t *expected = (intptr2_t *) comparand; int result; do { - uint64_t temp_lo; - uint64_t temp_hi; - __asm__ volatile( - "ldaxp %[lo], %[hi], %[src]" - : [ lo ] "=r"(temp_lo) - , [ hi ] "=r"(temp_hi) - : [ src ] "Q"(*ptr) - : "memory" - ); - intptr2_t temp = ((intptr2_t)temp_hi) << 64 | temp_lo; - - if (temp != *expected) { - // No reason to leave the monitor in Exclusive so clear it. - __asm__ volatile("clrex"); - *expected = temp; - return false; - } - - intptr_t desired_lo = (intptr_t)(*exchange); - intptr_t desired_hi = (intptr_t)(*exchange >> 64); - __asm__ volatile( - "stlxp %w[result], %[lo], %[hi], %[ptr]" - : [ result ] "=&r"(result) - , [ ptr ] "=Q"(*ptr) - : [ lo ] "r"(desired_lo) - , [ hi ] "r"(desired_hi) - : "memory" - ); + uint64_t temp_lo; + uint64_t temp_hi; + __asm__ volatile( + "ldaxp %[lo], %[hi], %[src]" + : [ lo ] "=r"(temp_lo) + , [ hi ] "=r"(temp_hi) + : [ src ] "Q"(*ptr) + : "memory" + ); + intptr2_t temp = ((intptr2_t) temp_hi) << 64 | temp_lo; + + if (temp != *expected) { + // No reason to leave the monitor in Exclusive so clear it. + __asm__ volatile("clrex"); + *expected = temp; + return false; + } + + intptr_t desired_lo = (intptr_t) (*exchange); + intptr_t desired_hi = (intptr_t) (*exchange >> 64); + __asm__ volatile( + "stlxp %w[result], %[lo], %[hi], %[ptr]" + : [ result ] "=&r"(result) + , [ ptr ] "=Q"(*ptr) + : [ lo ] "r"(desired_lo) + , [ hi ] "r"(desired_hi) + : "memory" + ); } while (result); return true; #else @@ -168,6 +168,7 @@ bool cas(intptr2_t *target, intptr2_t *comparand, intptr2_t *exchange) { p2_t desired = *comparand; return atomic_compare_exchange_strong((_Atomic intptr2_t*)target, &desired, *exchange); #endif +#endif } __attribute__((always_inline, flatten)) inline @@ -225,7 +226,6 @@ intptr2_t cas_read(intptr2_t * target) { #endif } -#endif #endif #define intptr2_sub(name, i) \