Skip to content

Commit 6f34ceb

Browse files
committed
cleaning up arithmetic / bitwise ops
1 parent 16cdbfe commit 6f34ceb

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/atomics.jl

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ function __atomic(ex)
2929
error("@atomic macro incomplete!")
3030
end
3131

32-
function atomic_add!(ptr, b)
33-
Core.Intrinsics.atomic_pointermodify(ptr, +, b, :monotonic)
34-
end
35-
36-
function atomic_and!(ptr, b)
37-
Core.Intrinsics.atomic_pointermodify(ptr, &, b, :monotonic)
32+
# arithmetic and bitwise operations
33+
34+
const ops = Dict(
35+
:atomic_add! => +,
36+
:atomic_sub! => -,
37+
:atomic_and! => &,
38+
:atomic_or! => -,
39+
:atomic_xor! => ,
40+
)
41+
42+
for (name, op) in ops
43+
@eval @inline function $name(ptr, b)
44+
Core.Intrinsics.atomic_pointermodify(ptr, $op, b, :monotonic)
45+
end
3846
end
3947

4048
# Not sure what this one is...
@@ -67,24 +75,11 @@ function atomic_op!(ptr, b)
6775
Core.Intrinsics.atomic_pointermodify(ptr, &, b, :monotonic)
6876
end
6977

70-
function atomic_or!(ptr, b)
71-
Core.Intrinsics.atomic_pointermodify(ptr, |, b, :monotonic)
72-
end
73-
74-
function atomic_sub!(ptr, b)
75-
Core.Intrinsics.atomic_pointermodify(ptr, -, b, :monotonic)
76-
end
77-
7878
# TODO
7979
function atomic_xchg!(ptr, b)
8080
Core.Intrinsics.atomic_pointermodify(ptr, &, b, :monotonic)
8181
end
8282

83-
# TODO
84-
function atomic_xor!(ptr, b)
85-
Core.Intrinsics.atomic_pointermodify(ptr, &, b, :monotonic)
86-
end
87-
8883
###
8984
# CPU implementation of atomic macro
9085
###

0 commit comments

Comments
 (0)