Skip to content

Commit 4dc85d6

Browse files
authored
Simplify fallback cas! (#13)
1 parent 41ba733 commit 4dc85d6

File tree

1 file changed

+9
-48
lines changed

1 file changed

+9
-48
lines changed

src/core.jl

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -207,52 +207,13 @@ function UnsafeAtomics.cas!(
207207
success_ordering,
208208
failure_ordering,
209209
) where {T}
210-
if sizeof(T) == 1
211-
(old, success) = UnsafeAtomics.cas!(
212-
Ptr{UInt8}(x),
213-
bitcast(UInt8, cmp),
214-
bitcast(UInt8, new),
215-
success_ordering,
216-
failure_ordering,
217-
)
218-
return (old = bitcast(T, old), success = success)
219-
elseif sizeof(T) == 2
220-
(old, success) = UnsafeAtomics.cas!(
221-
Ptr{UInt16}(x),
222-
bitcast(UInt16, cmp),
223-
bitcast(UInt16, new),
224-
success_ordering,
225-
failure_ordering,
226-
)
227-
return (old = bitcast(T, old), success = success)
228-
elseif sizeof(T) == 4
229-
(old, success) = UnsafeAtomics.cas!(
230-
Ptr{UInt32}(x),
231-
bitcast(UInt32, cmp),
232-
bitcast(UInt32, new),
233-
success_ordering,
234-
failure_ordering,
235-
)
236-
return (old = bitcast(T, old), success = success)
237-
elseif sizeof(T) == 8
238-
(old, success) = UnsafeAtomics.cas!(
239-
Ptr{UInt64}(x),
240-
bitcast(UInt64, cmp),
241-
bitcast(UInt64, new),
242-
success_ordering,
243-
failure_ordering,
244-
)
245-
return (old = bitcast(T, old), success = success)
246-
elseif sizeof(T) == 16
247-
(old, success) = UnsafeAtomics.cas!(
248-
Ptr{UInt128}(x),
249-
bitcast(UInt128, cmp),
250-
bitcast(UInt128, new),
251-
success_ordering,
252-
failure_ordering,
253-
)
254-
return (old = bitcast(T, old), success = success)
255-
else
256-
error(LazyString("unsupported size: ", sizeof(T)))
257-
end
210+
UI = as_native_uint(T)
211+
(old, success) = UnsafeAtomics.cas!(
212+
Ptr{UI}(x),
213+
bitcast(UI, cmp),
214+
bitcast(UI, new),
215+
success_ordering,
216+
failure_ordering,
217+
)
218+
return (old = bitcast(T, old), success = success)
258219
end

0 commit comments

Comments
 (0)