1 // To apply, at the top of xnu.git:
2 // $ spatch --max-width=120 --use-gitgrep --in-place --include-headers --sp-file tools/cocci/hw_atomic_rewrite.cocci -dir .
4 // coccinelle insists on adding a space for (void) casts which can be fixed with:
5 // $ git grep -l 'os_atomic' | xargs -n1 sed -i '' -e 's/os_atomic/os_atomic/'
7 @@ expression E, F; @@ // hw_atomic_add -> os_atomic_{inc,dec}
10 - hw_atomic_add(E, -1) + 1
11 + os_atomic_dec_orig(E, relaxed)
13 - hw_atomic_add(E, -1)
14 + os_atomic_dec(E, relaxed)
16 - hw_atomic_add(E, -F) + F
17 + os_atomic_sub_orig(E, F, relaxed)
19 - hw_atomic_add(E, -F)
20 + os_atomic_sub(E, F, relaxed)
22 - hw_atomic_add(E, 1) - 1
23 + os_atomic_inc_orig(E, relaxed)
26 + os_atomic_inc(E, relaxed)
28 - hw_atomic_add(E, F) - F
29 + os_atomic_add_orig(E, F, relaxed)
32 + os_atomic_add(E, F, relaxed)
35 @@ expression E, F; @@ // hw_atomic_sub -> os_atomic_{inc,dec}
38 - hw_atomic_sub(E, -1) - 1
39 + os_atomic_inc_orig(E, relaxed)
41 - hw_atomic_sub(E, -1)
42 + os_atomic_inc(E, relaxed)
44 - hw_atomic_sub(E, -F) - F
45 + os_atomic_add_orig(E, F, relaxed)
47 - hw_atomic_sub(E, -F)
48 + os_atomic_add(E, F, relaxed)
50 - hw_atomic_sub(E, 1) + 1
51 + os_atomic_dec_orig(E, relaxed)
54 + os_atomic_dec(E, relaxed)
56 - hw_atomic_sub(E, F) + F
57 + os_atomic_sub_orig(E, F, relaxed)
60 + os_atomic_sub(E, F, relaxed)
63 @@ expression E, F; @@ // hw_atomic_and -> os_atomic_and
66 - hw_atomic_and(E, ~F)
67 + os_atomic_andnot(E, F, relaxed)
70 + os_atomic_and(E, F, relaxed)
72 - hw_atomic_and_noret(E, ~F)
73 + os_atomic_andnot(E, F, relaxed)
75 - hw_atomic_and_noret(E, F)
76 + os_atomic_and(E, F, relaxed)
79 @@ expression E, F; @@ // hw_atomic_or -> os_atomic_or
83 + os_atomic_or(E, F, relaxed)
85 - hw_atomic_or_noret(E, F)
86 + os_atomic_or(E, F, relaxed)
89 @@ expression E, F, A; @@ // hw_compare_and_store
92 - hw_compare_and_store(E, F, A)
93 + os_atomic_cmpxchg(A, E, F, acq_rel)