1# -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2#
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#
8# Based on the programming examples in The PowerPC Architecture:
9# A Specification for A New Family of RISC Processors, 2nd Ed.,
10# Book I, Section E.1, "Synchronization," pp. 249-256, May 1994.
11#
12
13.text
14
15#
16# PRInt32 __PR_DarwinPPC_AtomicIncrement(PRInt32 *val);
17#
18        .align  2
19        .globl  __PR_DarwinPPC_AtomicIncrement
20        .private_extern __PR_DarwinPPC_AtomicIncrement
21__PR_DarwinPPC_AtomicIncrement:
22        lwarx   r4,0,r3
23        addi    r0,r4,1
24        stwcx.  r0,0,r3
25        bne-    __PR_DarwinPPC_AtomicIncrement
26        mr      r3,r0
27        blr
28
29#
30# PRInt32 __PR_DarwinPPC_AtomicDecrement(PRInt32 *val);
31#
32        .align  2
33        .globl  __PR_DarwinPPC_AtomicDecrement
34        .private_extern __PR_DarwinPPC_AtomicDecrement
35__PR_DarwinPPC_AtomicDecrement:
36        lwarx   r4,0,r3
37        addi    r0,r4,-1
38        stwcx.  r0,0,r3
39        bne-    __PR_DarwinPPC_AtomicDecrement
40        mr      r3,r0
41        blr
42
43#
44# PRInt32 __PR_DarwinPPC_AtomicSet(PRInt32 *val, PRInt32 newval);
45#
46        .align  2
47        .globl  __PR_DarwinPPC_AtomicSet
48        .private_extern __PR_DarwinPPC_AtomicSet
49__PR_DarwinPPC_AtomicSet:
50        lwarx   r5,0,r3
51        stwcx.  r4,0,r3
52        bne-    __PR_DarwinPPC_AtomicSet
53        mr      r3,r5
54        blr
55
56#
57# PRInt32 __PR_DarwinPPC_AtomicAdd(PRInt32 *ptr, PRInt32 val);
58#
59        .align  2
60        .globl  __PR_DarwinPPC_AtomicAdd
61        .private_extern __PR_DarwinPPC_AtomicAdd
62__PR_DarwinPPC_AtomicAdd:
63        lwarx   r5,0,r3
64        add     r0,r4,r5
65        stwcx.  r0,0,r3
66        bne-    __PR_DarwinPPC_AtomicAdd
67        mr      r3,r0
68        blr
69