1 /* Prototypes of memory model helper functions.
2 Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_MEMMODEL_H
21 #define GCC_MEMMODEL_H
23 /* Suppose that higher bits are target dependent. */
24 #define MEMMODEL_MASK ((1<<16)-1)
26 /* Legacy sync operations set this upper flag in the memory model. This allows
27 targets that need to do something stronger for sync operations to
28 differentiate with their target patterns and issue a more appropriate insn
29 sequence. See bugzilla 65697 for background. */
30 #define MEMMODEL_SYNC (1<<15)
32 /* Memory model without SYNC bit for targets/operations that do not care. */
33 #define MEMMODEL_BASE_MASK (MEMMODEL_SYNC-1)
35 /* Memory model types for the __atomic* builtins.
36 This must match the order in libstdc++-v3/include/bits/atomic_base.h. */
46 MEMMODEL_SYNC_ACQUIRE
= MEMMODEL_ACQUIRE
| MEMMODEL_SYNC
,
47 MEMMODEL_SYNC_RELEASE
= MEMMODEL_RELEASE
| MEMMODEL_SYNC
,
48 MEMMODEL_SYNC_SEQ_CST
= MEMMODEL_SEQ_CST
| MEMMODEL_SYNC
,
49 /* Say that all the higher bits are valid target extensions. */
50 MEMMODEL_MAX
= INTTYPE_MAXIMUM (int)
53 /* Return the memory model from a host integer. */
55 memmodel_from_int (unsigned HOST_WIDE_INT val
)
57 return (enum memmodel
) (val
& MEMMODEL_MASK
);
60 /* Return the base memory model from a host integer. */
62 memmodel_base (unsigned HOST_WIDE_INT val
)
64 return (enum memmodel
) (val
& MEMMODEL_BASE_MASK
);
67 /* Return TRUE if the memory model is RELAXED. */
69 is_mm_relaxed (enum memmodel model
)
71 return (model
& MEMMODEL_BASE_MASK
) == MEMMODEL_RELAXED
;
74 /* Return TRUE if the memory model is CONSUME. */
76 is_mm_consume (enum memmodel model
)
78 return (model
& MEMMODEL_BASE_MASK
) == MEMMODEL_CONSUME
;
81 /* Return TRUE if the memory model is ACQUIRE. */
83 is_mm_acquire (enum memmodel model
)
85 return (model
& MEMMODEL_BASE_MASK
) == MEMMODEL_ACQUIRE
;
88 /* Return TRUE if the memory model is RELEASE. */
90 is_mm_release (enum memmodel model
)
92 return (model
& MEMMODEL_BASE_MASK
) == MEMMODEL_RELEASE
;
95 /* Return TRUE if the memory model is ACQ_REL. */
97 is_mm_acq_rel (enum memmodel model
)
99 return (model
& MEMMODEL_BASE_MASK
) == MEMMODEL_ACQ_REL
;
102 /* Return TRUE if the memory model is SEQ_CST. */
104 is_mm_seq_cst (enum memmodel model
)
106 return (model
& MEMMODEL_BASE_MASK
) == MEMMODEL_SEQ_CST
;
109 /* Return TRUE if the memory model is a SYNC variant. */
111 is_mm_sync (enum memmodel model
)
113 return (model
& MEMMODEL_SYNC
);
116 #endif /* GCC_MEMMODEL_H */