xref: /dragonfly/test/cocci/useful_macros.cocci (revision 8b123e35)
1//
2// Find cases where our macros can be used.
3//
4// Applies to userland and kernel code.
5//
6// Order matters in this file because some macros contain other macros.
7//
8
9@@
10expression A, I;
11@@
12(
13-A[I/NBBY] |= 1<<(I%NBBY)
14+setbit(A, I)
15|
16-A[I/8] |= 1<<(I%8)
17+setbit(A, I)
18|
19-A[I/NBBY] &= ~(1<<(I%NBBY))
20+clrbit(A, I)
21|
22-A[I/8] &= ~(1<<(I%8))
23+clrbit(A, I)
24|
25-(A[I/NBBY] & (1<<(I%NBBY))) == 0
26+isclr(A, I)
27|
28-(A[I/8] & (1<<(I%8))) == 0
29+isclr(A, I)
30|
31-A[I/NBBY] & (1<<(I%NBBY))
32+isset(A, I)
33|
34-A[I/8] & (1<<(I%8))
35+isset(A, I)
36)
37
38@@
39type E;
40E[] T;
41@@
42(
43-sizeof(T)/sizeof(E)
44+NELEM(T)
45|
46-sizeof(T)/sizeof(*T)
47+NELEM(T)
48|
49-sizeof(T)/sizeof(T[...])
50+NELEM(T)
51)
52
53@@
54expression X;
55@@
56-((X-1)&X) == 0
57+powerof2(X)
58
59@@
60expression X, Y;
61@@
62(
63-((X+Y-1)/Y)*Y
64+roundup(X, Y)
65|
66-((X+(Y-1))/Y)*Y
67+roundup(X, Y)
68|
69-(X+(Y-1))/Y
70+howmany(X, Y)
71|
72-(X+Y-1)&(~(Y-1))
73+roundup2(X, Y)
74|
75-(X+(Y-1))&(~(Y-1))
76+roundup2(X, Y)
77|
78-X&(~(Y-1))
79+rounddown2(X, Y)
80|
81-(X/Y)*Y
82+rounddown(X, Y)
83)
84