Skip to content

Commit

Permalink
TYoungSL: fixed atomic.h for arm64
Browse files Browse the repository at this point in the history
Rjs: upgraded myst to fix attr

Co-authored-by: Robert J Spencer <rj@game.net.au>
  • Loading branch information
TYoungSL and Rjvs committed May 9, 2022
1 parent 45a9ea3 commit 0e1b472
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
4 changes: 3 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
62 changes: 31 additions & 31 deletions src/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -225,7 +226,6 @@ intptr2_t cas_read(intptr2_t * target) {
#endif
}

#endif
#endif

#define intptr2_sub(name, i) \
Expand Down

0 comments on commit 0e1b472

Please sign in to comment.