portable_atomic/
cfgs.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2
3#![allow(missing_docs)]
4
5#[cfg(not(all(
6    portable_atomic_no_atomic_load_store,
7    not(any(
8        target_arch = "avr",
9        target_arch = "msp430",
10        target_arch = "riscv32",
11        target_arch = "riscv64",
12        feature = "critical-section",
13        portable_atomic_unsafe_assume_single_core,
14    )),
15)))]
16#[macro_use]
17mod atomic_8_16_macros {
18    #[macro_export]
19    macro_rules! cfg_has_atomic_8 {
20        ($($tt:tt)*) => {
21            $($tt)*
22        };
23    }
24    #[macro_export]
25    macro_rules! cfg_no_atomic_8 {
26        ($($tt:tt)*) => {};
27    }
28    #[macro_export]
29    macro_rules! cfg_has_atomic_16 {
30        ($($tt:tt)*) => {
31            $($tt)*
32        };
33    }
34    #[macro_export]
35    macro_rules! cfg_no_atomic_16 {
36        ($($tt:tt)*) => {};
37    }
38}
39#[cfg(all(
40    portable_atomic_no_atomic_load_store,
41    not(any(
42        target_arch = "avr",
43        target_arch = "msp430",
44        target_arch = "riscv32",
45        target_arch = "riscv64",
46        feature = "critical-section",
47        portable_atomic_unsafe_assume_single_core,
48    )),
49))]
50#[macro_use]
51mod atomic_8_16_macros {
52    #[macro_export]
53    macro_rules! cfg_has_atomic_8 {
54        ($($tt:tt)*) => {};
55    }
56    #[macro_export]
57    macro_rules! cfg_no_atomic_8 {
58        ($($tt:tt)*) => {
59            $($tt)*
60        };
61    }
62    #[macro_export]
63    macro_rules! cfg_has_atomic_16 {
64        ($($tt:tt)*) => {};
65    }
66    #[macro_export]
67    macro_rules! cfg_no_atomic_16 {
68        ($($tt:tt)*) => {
69            $($tt)*
70        };
71    }
72}
73
74#[cfg(all(
75    any(not(target_pointer_width = "16"), feature = "fallback"),
76    not(all(
77        portable_atomic_no_atomic_load_store,
78        not(any(
79            target_arch = "avr",
80            target_arch = "msp430",
81            target_arch = "riscv32",
82            target_arch = "riscv64",
83            feature = "critical-section",
84            portable_atomic_unsafe_assume_single_core,
85        )),
86    )),
87))]
88#[macro_use]
89mod atomic_32_macros {
90    #[macro_export]
91    macro_rules! cfg_has_atomic_32 {
92        ($($tt:tt)*) => {
93            $($tt)*
94        };
95    }
96    #[macro_export]
97    macro_rules! cfg_no_atomic_32 {
98        ($($tt:tt)*) => {};
99    }
100}
101#[cfg(not(all(
102    any(not(target_pointer_width = "16"), feature = "fallback"),
103    not(all(
104        portable_atomic_no_atomic_load_store,
105        not(any(
106            target_arch = "avr",
107            target_arch = "msp430",
108            target_arch = "riscv32",
109            target_arch = "riscv64",
110            feature = "critical-section",
111            portable_atomic_unsafe_assume_single_core,
112        )),
113    )),
114)))]
115#[macro_use]
116mod atomic_32_macros {
117    #[macro_export]
118    macro_rules! cfg_has_atomic_32 {
119        ($($tt:tt)*) => {};
120    }
121    #[macro_export]
122    macro_rules! cfg_no_atomic_32 {
123        ($($tt:tt)*) => {
124            $($tt)*
125        };
126    }
127}
128
129#[cfg_attr(
130    portable_atomic_no_cfg_target_has_atomic,
131    cfg(any(
132        all(
133            feature = "fallback",
134            any(
135                not(portable_atomic_no_atomic_cas),
136                target_arch = "avr",
137                target_arch = "msp430",
138                feature = "critical-section",
139                portable_atomic_unsafe_assume_single_core,
140            ),
141        ),
142        not(portable_atomic_no_atomic_64),
143        not(any(target_pointer_width = "16", target_pointer_width = "32")),
144        all(
145            target_arch = "riscv32",
146            not(any(miri, portable_atomic_sanitize_thread)),
147            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
148            any(target_feature = "zacas", portable_atomic_target_feature = "zacas"),
149        ),
150    ))
151)]
152#[cfg_attr(
153    not(portable_atomic_no_cfg_target_has_atomic),
154    cfg(any(
155        all(
156            feature = "fallback",
157            any(
158                target_has_atomic = "ptr",
159                target_arch = "avr",
160                target_arch = "msp430",
161                feature = "critical-section",
162                portable_atomic_unsafe_assume_single_core,
163            ),
164        ),
165        target_has_atomic = "64",
166        not(any(target_pointer_width = "16", target_pointer_width = "32")),
167        all(
168            target_arch = "riscv32",
169            not(any(miri, portable_atomic_sanitize_thread)),
170            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
171            any(target_feature = "zacas", portable_atomic_target_feature = "zacas"),
172        ),
173    ))
174)]
175#[macro_use]
176mod atomic_64_macros {
177    #[macro_export]
178    macro_rules! cfg_has_atomic_64 {
179        ($($tt:tt)*) => {
180            $($tt)*
181        };
182    }
183    #[macro_export]
184    macro_rules! cfg_no_atomic_64 {
185        ($($tt:tt)*) => {};
186    }
187}
188#[cfg_attr(
189    portable_atomic_no_cfg_target_has_atomic,
190    cfg(not(any(
191        all(
192            feature = "fallback",
193            any(
194                not(portable_atomic_no_atomic_cas),
195                target_arch = "avr",
196                target_arch = "msp430",
197                feature = "critical-section",
198                portable_atomic_unsafe_assume_single_core,
199            ),
200        ),
201        not(portable_atomic_no_atomic_64),
202        not(any(target_pointer_width = "16", target_pointer_width = "32")),
203        all(
204            target_arch = "riscv32",
205            not(any(miri, portable_atomic_sanitize_thread)),
206            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
207            any(target_feature = "zacas", portable_atomic_target_feature = "zacas"),
208        ),
209    )))
210)]
211#[cfg_attr(
212    not(portable_atomic_no_cfg_target_has_atomic),
213    cfg(not(any(
214        all(
215            feature = "fallback",
216            any(
217                target_has_atomic = "ptr",
218                target_arch = "avr",
219                target_arch = "msp430",
220                feature = "critical-section",
221                portable_atomic_unsafe_assume_single_core,
222            ),
223        ),
224        target_has_atomic = "64",
225        not(any(target_pointer_width = "16", target_pointer_width = "32")),
226        all(
227            target_arch = "riscv32",
228            not(any(miri, portable_atomic_sanitize_thread)),
229            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
230            any(target_feature = "zacas", portable_atomic_target_feature = "zacas"),
231        ),
232    )))
233)]
234#[macro_use]
235mod atomic_64_macros {
236    #[macro_export]
237    macro_rules! cfg_has_atomic_64 {
238        ($($tt:tt)*) => {};
239    }
240    #[macro_export]
241    macro_rules! cfg_no_atomic_64 {
242        ($($tt:tt)*) => {
243            $($tt)*
244        };
245    }
246}
247
248#[cfg_attr(
249    not(feature = "fallback"),
250    cfg(any(
251        all(
252            target_arch = "aarch64",
253            not(all(
254                any(miri, portable_atomic_sanitize_thread),
255                not(portable_atomic_atomic_intrinsics),
256            )),
257            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
258        ),
259        all(
260            target_arch = "arm64ec",
261            not(all(
262                any(miri, portable_atomic_sanitize_thread),
263                not(portable_atomic_atomic_intrinsics),
264            )),
265            not(portable_atomic_no_asm),
266        ),
267        all(
268            target_arch = "x86_64",
269            not(all(
270                any(miri, portable_atomic_sanitize_thread),
271                portable_atomic_no_cmpxchg16b_intrinsic,
272            )),
273            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
274            any(target_feature = "cmpxchg16b", portable_atomic_target_feature = "cmpxchg16b"),
275        ),
276        all(
277            target_arch = "riscv64",
278            not(any(miri, portable_atomic_sanitize_thread)),
279            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
280            any(target_feature = "zacas", portable_atomic_target_feature = "zacas"),
281        ),
282        all(
283            target_arch = "powerpc64",
284            not(all(
285                any(miri, portable_atomic_sanitize_thread),
286                not(portable_atomic_atomic_intrinsics),
287            )),
288            portable_atomic_unstable_asm_experimental_arch,
289            any(
290                target_feature = "quadword-atomics",
291                portable_atomic_target_feature = "quadword-atomics",
292            ),
293        ),
294        all(
295            target_arch = "s390x",
296            not(all(
297                any(miri, portable_atomic_sanitize_thread),
298                not(portable_atomic_atomic_intrinsics),
299            )),
300            not(portable_atomic_no_asm),
301        ),
302    ))
303)]
304#[cfg_attr(
305    all(feature = "fallback", portable_atomic_no_cfg_target_has_atomic),
306    cfg(any(
307        not(portable_atomic_no_atomic_cas),
308        target_arch = "avr",
309        target_arch = "msp430",
310        feature = "critical-section",
311        portable_atomic_unsafe_assume_single_core,
312    ))
313)]
314#[cfg_attr(
315    all(feature = "fallback", not(portable_atomic_no_cfg_target_has_atomic)),
316    cfg(any(
317        target_has_atomic = "ptr",
318        target_arch = "avr",
319        target_arch = "msp430",
320        feature = "critical-section",
321        portable_atomic_unsafe_assume_single_core,
322    ))
323)]
324#[macro_use]
325mod atomic_128_macros {
326    #[macro_export]
327    macro_rules! cfg_has_atomic_128 {
328        ($($tt:tt)*) => {
329            $($tt)*
330        };
331    }
332    #[macro_export]
333    macro_rules! cfg_no_atomic_128 {
334        ($($tt:tt)*) => {};
335    }
336}
337#[cfg_attr(
338    not(feature = "fallback"),
339    cfg(not(any(
340        all(
341            target_arch = "aarch64",
342            not(all(
343                any(miri, portable_atomic_sanitize_thread),
344                not(portable_atomic_atomic_intrinsics),
345            )),
346            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
347        ),
348        all(
349            target_arch = "arm64ec",
350            not(all(
351                any(miri, portable_atomic_sanitize_thread),
352                not(portable_atomic_atomic_intrinsics),
353            )),
354            not(portable_atomic_no_asm),
355        ),
356        all(
357            target_arch = "x86_64",
358            not(all(
359                any(miri, portable_atomic_sanitize_thread),
360                portable_atomic_no_cmpxchg16b_intrinsic,
361            )),
362            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
363            any(target_feature = "cmpxchg16b", portable_atomic_target_feature = "cmpxchg16b"),
364        ),
365        all(
366            target_arch = "riscv64",
367            not(any(miri, portable_atomic_sanitize_thread)),
368            any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
369            any(target_feature = "zacas", portable_atomic_target_feature = "zacas"),
370        ),
371        all(
372            target_arch = "powerpc64",
373            not(all(
374                any(miri, portable_atomic_sanitize_thread),
375                not(portable_atomic_atomic_intrinsics),
376            )),
377            portable_atomic_unstable_asm_experimental_arch,
378            any(
379                target_feature = "quadword-atomics",
380                portable_atomic_target_feature = "quadword-atomics",
381            ),
382        ),
383        all(
384            target_arch = "s390x",
385            not(all(
386                any(miri, portable_atomic_sanitize_thread),
387                not(portable_atomic_atomic_intrinsics),
388            )),
389            not(portable_atomic_no_asm),
390        ),
391    )))
392)]
393#[cfg_attr(
394    all(feature = "fallback", portable_atomic_no_cfg_target_has_atomic),
395    cfg(not(any(
396        not(portable_atomic_no_atomic_cas),
397        target_arch = "avr",
398        target_arch = "msp430",
399        feature = "critical-section",
400        portable_atomic_unsafe_assume_single_core,
401    )))
402)]
403#[cfg_attr(
404    all(feature = "fallback", not(portable_atomic_no_cfg_target_has_atomic)),
405    cfg(not(any(
406        target_has_atomic = "ptr",
407        target_arch = "avr",
408        target_arch = "msp430",
409        feature = "critical-section",
410        portable_atomic_unsafe_assume_single_core,
411    )))
412)]
413#[macro_use]
414mod atomic_128_macros {
415    #[macro_export]
416    macro_rules! cfg_has_atomic_128 {
417        ($($tt:tt)*) => {};
418    }
419    #[macro_export]
420    macro_rules! cfg_no_atomic_128 {
421        ($($tt:tt)*) => {
422            $($tt)*
423        };
424    }
425}
426
427#[cfg_attr(
428    portable_atomic_no_cfg_target_has_atomic,
429    cfg(any(
430        not(portable_atomic_no_atomic_cas),
431        target_arch = "avr",
432        target_arch = "msp430",
433        feature = "critical-section",
434        portable_atomic_unsafe_assume_single_core,
435    ))
436)]
437#[cfg_attr(
438    not(portable_atomic_no_cfg_target_has_atomic),
439    cfg(any(
440        target_has_atomic = "ptr",
441        target_arch = "avr",
442        target_arch = "msp430",
443        feature = "critical-section",
444        portable_atomic_unsafe_assume_single_core,
445    ))
446)]
447#[macro_use]
448mod atomic_cas_macros {
449    #[macro_export]
450    macro_rules! cfg_has_atomic_cas {
451        ($($tt:tt)*) => {
452            $($tt)*
453        };
454    }
455    #[macro_export]
456    macro_rules! cfg_no_atomic_cas {
457        ($($tt:tt)*) => {};
458    }
459    // private
460    macro_rules! cfg_has_atomic_cas_or_amo32 {
461        ($($tt:tt)*) => {
462            $($tt)*
463        };
464    }
465    macro_rules! cfg_has_atomic_cas_or_amo8 {
466        ($($tt:tt)*) => {
467            $($tt)*
468        };
469    }
470}
471#[cfg_attr(
472    portable_atomic_no_cfg_target_has_atomic,
473    cfg(not(any(
474        not(portable_atomic_no_atomic_cas),
475        target_arch = "avr",
476        target_arch = "msp430",
477        feature = "critical-section",
478        portable_atomic_unsafe_assume_single_core,
479    )))
480)]
481#[cfg_attr(
482    not(portable_atomic_no_cfg_target_has_atomic),
483    cfg(not(any(
484        target_has_atomic = "ptr",
485        target_arch = "avr",
486        target_arch = "msp430",
487        feature = "critical-section",
488        portable_atomic_unsafe_assume_single_core,
489    )))
490)]
491#[macro_use]
492mod atomic_cas_macros {
493    #[macro_export]
494    macro_rules! cfg_has_atomic_cas {
495        ($($tt:tt)*) => {};
496    }
497    #[macro_export]
498    macro_rules! cfg_no_atomic_cas {
499        ($($tt:tt)*) => {
500            $($tt)*
501        };
502    }
503    // private
504    #[cfg_attr(
505        any(target_arch = "riscv32", target_arch = "riscv64"),
506        cfg(not(any(target_feature = "zaamo", portable_atomic_target_feature = "zaamo")))
507    )]
508    macro_rules! cfg_has_atomic_cas_or_amo32 {
509        ($($tt:tt)*) => {};
510    }
511    #[cfg_attr(
512        any(target_arch = "riscv32", target_arch = "riscv64"),
513        cfg(not(any(target_feature = "zaamo", portable_atomic_target_feature = "zaamo")))
514    )]
515    macro_rules! cfg_no_atomic_cas_or_amo32 {
516        ($($tt:tt)*) => {
517            $($tt)*
518        };
519    }
520    #[cfg(all(
521        any(target_arch = "riscv32", target_arch = "riscv64"),
522        any(target_feature = "zaamo", portable_atomic_target_feature = "zaamo"),
523    ))]
524    macro_rules! cfg_has_atomic_cas_or_amo32 {
525        ($($tt:tt)*) => {
526            $($tt)*
527        };
528    }
529    #[cfg(all(
530        any(target_arch = "riscv32", target_arch = "riscv64"),
531        any(target_feature = "zaamo", portable_atomic_target_feature = "zaamo"),
532    ))]
533    macro_rules! cfg_no_atomic_cas_or_amo32 {
534        ($($tt:tt)*) => {};
535    }
536    #[cfg_attr(
537        any(target_arch = "riscv32", target_arch = "riscv64"),
538        cfg(not(any(target_feature = "zabha", portable_atomic_target_feature = "zabha")))
539    )]
540    #[allow(unused_macros)]
541    macro_rules! cfg_has_atomic_cas_or_amo8 {
542        ($($tt:tt)*) => {};
543    }
544    #[cfg_attr(
545        any(target_arch = "riscv32", target_arch = "riscv64"),
546        cfg(not(any(target_feature = "zabha", portable_atomic_target_feature = "zabha")))
547    )]
548    #[cfg_attr(target_arch = "bpf", allow(unused_macros))]
549    macro_rules! cfg_no_atomic_cas_or_amo8 {
550        ($($tt:tt)*) => {
551            $($tt)*
552        };
553    }
554    #[cfg(all(
555        any(target_arch = "riscv32", target_arch = "riscv64"),
556        any(target_feature = "zabha", portable_atomic_target_feature = "zabha"),
557    ))]
558    macro_rules! cfg_has_atomic_cas_or_amo8 {
559        ($($tt:tt)*) => {
560            $($tt)*
561        };
562    }
563    #[cfg(all(
564        any(target_arch = "riscv32", target_arch = "riscv64"),
565        any(target_feature = "zabha", portable_atomic_target_feature = "zabha"),
566    ))]
567    macro_rules! cfg_no_atomic_cas_or_amo8 {
568        ($($tt:tt)*) => {};
569    }
570}
571
572// Check that all cfg_ macros work.
573mod check {
574    crate::cfg_has_atomic_8! { type _Atomic8 = (); }
575    crate::cfg_no_atomic_8! { type _Atomic8 = (); }
576    crate::cfg_has_atomic_16! { type _Atomic16 = (); }
577    crate::cfg_no_atomic_16! { type _Atomic16 = (); }
578    crate::cfg_has_atomic_32! { type _Atomic32 = (); }
579    crate::cfg_no_atomic_32! { type _Atomic32 = (); }
580    crate::cfg_has_atomic_64! { type _Atomic64 = (); }
581    crate::cfg_no_atomic_64! { type _Atomic64 = (); }
582    crate::cfg_has_atomic_128! { type _Atomic128 = (); }
583    crate::cfg_no_atomic_128! { type _Atomic128 = (); }
584    crate::cfg_has_atomic_ptr! { type _AtomicPtr = (); }
585    crate::cfg_no_atomic_ptr! { type _AtomicPtr = (); }
586    crate::cfg_has_atomic_cas! { type __AtomicPtr = (); }
587    crate::cfg_no_atomic_cas! { type __AtomicPtr = (); }
588    #[allow(unused_imports)]
589    use self::{
590        __AtomicPtr as _, _Atomic8 as _, _Atomic16 as _, _Atomic32 as _, _Atomic64 as _,
591        _Atomic128 as _, _AtomicPtr as _,
592    };
593}