1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Note: some of these functions are semantically inlined
6 // by the compiler (in src/cmd/compile/internal/gc/ssa.go).
7
8 #include "textflag.h"
9
10 TEXT ·Loaduintptr(SB), NOSPLIT, $0-16
11 JMP ·Load64(SB)
12
13 TEXT ·Loaduint(SB), NOSPLIT, $0-16
14 JMP ·Load64(SB)
15
16 TEXT ·Loadint32(SB), NOSPLIT, $0-12
17 JMP ·Load(SB)
18
19 TEXT ·Loadint64(SB), NOSPLIT, $0-16
20 JMP ·Load64(SB)
21
22 // bool Cas(int32 *val, int32 old, int32 new)
23 // Atomically:
24 // if(*val == old){
25 // *val = new;
26 // return 1;
27 // } else
28 // return 0;
29 TEXT ·Cas(SB),NOSPLIT,$0-17
30 MOVQ ptr+0(FP), BX
31 MOVL old+8(FP), AX
32 MOVL new+12(FP), CX
33 LOCK
34 CMPXCHGL CX, 0(BX)
35 SETEQ ret+16(FP)
36 RET
37
38 // bool ·Cas64(uint64 *val, uint64 old, uint64 new)
39 // Atomically:
40 // if(*val == old){
41 // *val = new;
42 // return 1;
43 // } else {
44 // return 0;
45 // }
46 TEXT ·Cas64(SB), NOSPLIT, $0-25
47 MOVQ ptr+0(FP), BX
48 MOVQ old+8(FP), AX
49 MOVQ new+16(FP), CX
50 LOCK
51 CMPXCHGQ CX, 0(BX)
52 SETEQ ret+24(FP)
53 RET
54
55 // bool Casp1(void **val, void *old, void *new)
56 // Atomically:
57 // if(*val == old){
58 // *val = new;
59 // return 1;
60 // } else
61 // return 0;
62 TEXT ·Casp1(SB), NOSPLIT, $0-25
63 MOVQ ptr+0(FP), BX
64 MOVQ old+8(FP), AX
65 MOVQ new+16(FP), CX
66 LOCK
67 CMPXCHGQ CX, 0(BX)
68 SETEQ ret+24(FP)
69 RET
70
71 TEXT ·Casint32(SB), NOSPLIT, $0-17
72 JMP ·Cas(SB)
73
74 TEXT ·Casint64(SB), NOSPLIT, $0-25
75 JMP ·Cas64(SB)
76
77 TEXT ·Casuintptr(SB), NOSPLIT, $0-25
78 JMP ·Cas64(SB)
79
80 TEXT ·CasRel(SB), NOSPLIT, $0-17
81 JMP ·Cas(SB)
82
83 // uint32 Xadd(uint32 volatile *val, int32 delta)
84 // Atomically:
85 // *val += delta;
86 // return *val;
87 TEXT ·Xadd(SB), NOSPLIT, $0-20
88 MOVQ ptr+0(FP), BX
89 MOVL delta+8(FP), AX
90 MOVL AX, CX
91 LOCK
92 XADDL AX, 0(BX)
93 ADDL CX, AX
94 MOVL AX, ret+16(FP)
95 RET
96
97 // uint64 Xadd64(uint64 volatile *val, int64 delta)
98 // Atomically:
99 // *val += delta;
100 // return *val;
101 TEXT ·Xadd64(SB), NOSPLIT, $0-24
102 MOVQ ptr+0(FP), BX
103 MOVQ delta+8(FP), AX
104 MOVQ AX, CX
105 LOCK
106 XADDQ AX, 0(BX)
107 ADDQ CX, AX
108 MOVQ AX, ret+16(FP)
109 RET
110
111 TEXT ·Xaddint32(SB), NOSPLIT, $0-20
112 JMP ·Xadd(SB)
113
114 TEXT ·Xaddint64(SB), NOSPLIT, $0-24
115 JMP ·Xadd64(SB)
116
117 TEXT ·Xadduintptr(SB), NOSPLIT, $0-24
118 JMP ·Xadd64(SB)
119
120 // uint32 Xchg(ptr *uint32, new uint32)
121 // Atomically:
122 // old := *ptr;
123 // *ptr = new;
124 // return old;
125 TEXT ·Xchg(SB), NOSPLIT, $0-20
126 MOVQ ptr+0(FP), BX
127 MOVL new+8(FP), AX
128 XCHGL AX, 0(BX)
129 MOVL AX, ret+16(FP)
130 RET
131
132 // uint64 Xchg64(ptr *uint64, new uint64)
133 // Atomically:
134 // old := *ptr;
135 // *ptr = new;
136 // return old;
137 TEXT ·Xchg64(SB), NOSPLIT, $0-24
138 MOVQ ptr+0(FP), BX
139 MOVQ new+8(FP), AX
140 XCHGQ AX, 0(BX)
141 MOVQ AX, ret+16(FP)
142 RET
143
144 TEXT ·Xchgint32(SB), NOSPLIT, $0-20
145 JMP ·Xchg(SB)
146
147 TEXT ·Xchgint64(SB), NOSPLIT, $0-24
148 JMP ·Xchg64(SB)
149
150 TEXT ·Xchguintptr(SB), NOSPLIT, $0-24
151 JMP ·Xchg64(SB)
152
153 TEXT ·StorepNoWB(SB), NOSPLIT, $0-16
154 MOVQ ptr+0(FP), BX
155 MOVQ val+8(FP), AX
156 XCHGQ AX, 0(BX)
157 RET
158
159 TEXT ·Store(SB), NOSPLIT, $0-12
160 MOVQ ptr+0(FP), BX
161 MOVL val+8(FP), AX
162 XCHGL AX, 0(BX)
163 RET
164
165 TEXT ·Store8(SB), NOSPLIT, $0-9
166 MOVQ ptr+0(FP), BX
167 MOVB val+8(FP), AX
168 XCHGB AX, 0(BX)
169 RET
170
171 TEXT ·Store64(SB), NOSPLIT, $0-16
172 MOVQ ptr+0(FP), BX
173 MOVQ val+8(FP), AX
174 XCHGQ AX, 0(BX)
175 RET
176
177 TEXT ·Storeint32(SB), NOSPLIT, $0-12
178 JMP ·Store(SB)
179
180 TEXT ·Storeint64(SB), NOSPLIT, $0-16
181 JMP ·Store64(SB)
182
183 TEXT ·Storeuintptr(SB), NOSPLIT, $0-16
184 JMP ·Store64(SB)
185
186 TEXT ·StoreRel(SB), NOSPLIT, $0-12
187 JMP ·Store(SB)
188
189 TEXT ·StoreRel64(SB), NOSPLIT, $0-16
190 JMP ·Store64(SB)
191
192 TEXT ·StoreReluintptr(SB), NOSPLIT, $0-16
193 JMP ·Store64(SB)
194
195 // void ·Or8(byte volatile*, byte);
196 TEXT ·Or8(SB), NOSPLIT, $0-9
197 MOVQ ptr+0(FP), AX
198 MOVB val+8(FP), BX
199 LOCK
200 ORB BX, (AX)
201 RET
202
203 // void ·And8(byte volatile*, byte);
204 TEXT ·And8(SB), NOSPLIT, $0-9
205 MOVQ ptr+0(FP), AX
206 MOVB val+8(FP), BX
207 LOCK
208 ANDB BX, (AX)
209 RET
210
211 // func Or(addr *uint32, v uint32)
212 TEXT ·Or(SB), NOSPLIT, $0-12
213 MOVQ ptr+0(FP), AX
214 MOVL val+8(FP), BX
215 LOCK
216 ORL BX, (AX)
217 RET
218
219 // func And(addr *uint32, v uint32)
220 TEXT ·And(SB), NOSPLIT, $0-12
221 MOVQ ptr+0(FP), AX
222 MOVL val+8(FP), BX
223 LOCK
224 ANDL BX, (AX)
225 RET
226
View as plain text