]> git.saurik.com Git - apple/xnu.git/blob - tools/cocci/hw_atomic_rewrite.cocci
xnu-7195.60.75.tar.gz
[apple/xnu.git] / tools / cocci / hw_atomic_rewrite.cocci
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 .
3 //
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/'
6
7 @@ expression E, F; @@ // hw_atomic_add -> os_atomic_{inc,dec}
8
9 (
10 - hw_atomic_add(E, -1) + 1
11 + os_atomic_dec_orig(E, relaxed)
12 |
13 - hw_atomic_add(E, -1)
14 + os_atomic_dec(E, relaxed)
15 |
16 - hw_atomic_add(E, -F) + F
17 + os_atomic_sub_orig(E, F, relaxed)
18 |
19 - hw_atomic_add(E, -F)
20 + os_atomic_sub(E, F, relaxed)
21 |
22 - hw_atomic_add(E, 1) - 1
23 + os_atomic_inc_orig(E, relaxed)
24 |
25 - hw_atomic_add(E, 1)
26 + os_atomic_inc(E, relaxed)
27 |
28 - hw_atomic_add(E, F) - F
29 + os_atomic_add_orig(E, F, relaxed)
30 |
31 - hw_atomic_add(E, F)
32 + os_atomic_add(E, F, relaxed)
33 )
34
35 @@ expression E, F; @@ // hw_atomic_sub -> os_atomic_{inc,dec}
36
37 (
38 - hw_atomic_sub(E, -1) - 1
39 + os_atomic_inc_orig(E, relaxed)
40 |
41 - hw_atomic_sub(E, -1)
42 + os_atomic_inc(E, relaxed)
43 |
44 - hw_atomic_sub(E, -F) - F
45 + os_atomic_add_orig(E, F, relaxed)
46 |
47 - hw_atomic_sub(E, -F)
48 + os_atomic_add(E, F, relaxed)
49 |
50 - hw_atomic_sub(E, 1) + 1
51 + os_atomic_dec_orig(E, relaxed)
52 |
53 - hw_atomic_sub(E, 1)
54 + os_atomic_dec(E, relaxed)
55 |
56 - hw_atomic_sub(E, F) + F
57 + os_atomic_sub_orig(E, F, relaxed)
58 |
59 - hw_atomic_sub(E, F)
60 + os_atomic_sub(E, F, relaxed)
61 )
62
63 @@ expression E, F; @@ // hw_atomic_and -> os_atomic_and
64
65 (
66 - hw_atomic_and(E, ~F)
67 + os_atomic_andnot(E, F, relaxed)
68 |
69 - hw_atomic_and(E, F)
70 + os_atomic_and(E, F, relaxed)
71 |
72 - hw_atomic_and_noret(E, ~F)
73 + os_atomic_andnot(E, F, relaxed)
74 |
75 - hw_atomic_and_noret(E, F)
76 + os_atomic_and(E, F, relaxed)
77 )
78
79 @@ expression E, F; @@ // hw_atomic_or -> os_atomic_or
80
81 (
82 - hw_atomic_or(E, F)
83 + os_atomic_or(E, F, relaxed)
84 |
85 - hw_atomic_or_noret(E, F)
86 + os_atomic_or(E, F, relaxed)
87 )
88
89 @@ expression E, F, A; @@ // hw_compare_and_store
90
91 (
92 - hw_compare_and_store(E, F, A)
93 + os_atomic_cmpxchg(A, E, F, acq_rel)
94 )
95
96 // vim:ft=diff: