Skip to content

Commit

Permalink
i#1551 ARM, i#1569 AArch64: Replace atomic_xchg with atomic_swap.
Browse files Browse the repository at this point in the history
In arm.asm, atomic_xchg and atomic_swap were defined identically.

Review-URL: https://codereview.appspot.com/298390043
  • Loading branch information
egrimley-arm committed Jun 10, 2016
1 parent 4f765b3 commit 5a466b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
19 changes: 7 additions & 12 deletions core/arch/aarch64/aarch64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ cat_no_thread:
adrp x26, :got:initstack_mutex
ldr x26, [x26, #:got_lo12:initstack_mutex]
cat_spin:
CALLC2(atomic_xchg, x26, #1)
/* atomic_xchg */
CALLC2(atomic_swap, x26, #1)
cbz w0, cat_have_lock
yield
b cat_spin
Expand Down Expand Up @@ -269,15 +268,6 @@ GLOBAL_LABEL(atomic_add:)
cbnz w3, 1b
ret

/* int atomic_xchg(int *adr, int val) */
DECLARE_FUNC(atomic_xchg)
GLOBAL_LABEL(atomic_xchg:)
1: ldxr w2, [x0]
stxr w3, w1, [x0]
cbnz w3, 1b
mov w0, w2
ret

DECLARE_FUNC(global_do_syscall_int)
GLOBAL_LABEL(global_do_syscall_int:)
/* FIXME i#1569: NYI on AArch64 */
Expand Down Expand Up @@ -413,9 +403,14 @@ GLOBAL_LABEL(dr_longjmp:)
br x30
END_FUNC(dr_longjmp)

/* int atomic_swap(int *adr, int val) */
DECLARE_FUNC(atomic_swap)
GLOBAL_LABEL(atomic_swap:)
bl GLOBAL_REF(unexpected_return) /* FIXME i#1569: NYI */
1: ldxr w2, [x0]
stxr w3, w1, [x0]
cbnz w3, 1b
mov w0, w2
ret
END_FUNC(atomic_swap)

#endif /* CLIENT_INTERFACE */
Expand Down
17 changes: 3 additions & 14 deletions core/arch/arm/arm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ cat_thread_only:
CALLC0(GLOBAL_REF(dynamo_thread_exit))
cat_no_thread:
/* switch to initstack for cleanup of dstack */
/* we use r6, r7, and r8 here so that atomic_xchg doesn't clobber them */
/* we use r6, r7, and r8 here so that atomic_swap doesn't clobber them */
mov REG_R6, #1
ldr REG_R8, .Lgot1
add REG_R8, REG_R8, pc
ldr REG_R7, .Linitstack_mutex
.LPIC1: ldr REG_R7, [REG_R7, REG_R8]
cat_spin:
CALLC2(atomic_xchg, REG_R7, REG_R6)
CALLC2(atomic_swap, REG_R7, REG_R6)
cmp REG_R0, #0
beq cat_have_lock
yield
Expand Down Expand Up @@ -355,17 +355,6 @@ GLOBAL_LABEL(atomic_add:)
bx lr
END_FUNC(atomic_add)

/* Pass in the memory address in ARG1 and register w/ value in ARG2. */
DECLARE_FUNC(atomic_xchg)
GLOBAL_LABEL(atomic_xchg:)
1: ldrex REG_R2, [ARG1]
strex REG_R3, ARG2, [ARG1]
cmp REG_R3, #0
bne 1b
mov REG_R0, REG_R2
bx lr
END_FUNC(atomic_xchg)

DECLARE_FUNC(global_do_syscall_int)
GLOBAL_LABEL(global_do_syscall_int:)
/* FIXME i#1551: NYI on ARM */
Expand Down Expand Up @@ -493,7 +482,7 @@ GLOBAL_LABEL(dr_longjmp:)
bx lr
END_FUNC(dr_longjmp)

/* uint atomic_swap(uint *addr, uint value)
/* int atomic_swap(volatile int *addr, int value)
* return current contents of addr and replace contents with value.
*/
DECLARE_FUNC(atomic_swap)
Expand Down

0 comments on commit 5a466b1

Please sign in to comment.