memmodel.h revision 1.1.1.2 1 1.1 mrg /* Prototypes of memory model helper functions.
2 1.1.1.2 mrg Copyright (C) 2011-2018 Free Software Foundation, Inc.
3 1.1 mrg
4 1.1 mrg This file is part of GCC.
5 1.1 mrg
6 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
7 1.1 mrg the terms of the GNU General Public License as published by the Free
8 1.1 mrg Software Foundation; either version 3, or (at your option) any later
9 1.1 mrg version.
10 1.1 mrg
11 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 1.1 mrg for more details.
15 1.1 mrg
16 1.1 mrg You should have received a copy of the GNU General Public License
17 1.1 mrg along with GCC; see the file COPYING3. If not see
18 1.1 mrg <http://www.gnu.org/licenses/>. */
19 1.1 mrg
20 1.1 mrg #ifndef GCC_MEMMODEL_H
21 1.1 mrg #define GCC_MEMMODEL_H
22 1.1 mrg
23 1.1 mrg /* Suppose that higher bits are target dependent. */
24 1.1 mrg #define MEMMODEL_MASK ((1<<16)-1)
25 1.1 mrg
26 1.1 mrg /* Legacy sync operations set this upper flag in the memory model. This allows
27 1.1 mrg targets that need to do something stronger for sync operations to
28 1.1 mrg differentiate with their target patterns and issue a more appropriate insn
29 1.1 mrg sequence. See bugzilla 65697 for background. */
30 1.1 mrg #define MEMMODEL_SYNC (1<<15)
31 1.1 mrg
32 1.1 mrg /* Memory model without SYNC bit for targets/operations that do not care. */
33 1.1 mrg #define MEMMODEL_BASE_MASK (MEMMODEL_SYNC-1)
34 1.1 mrg
35 1.1 mrg /* Memory model types for the __atomic* builtins.
36 1.1 mrg This must match the order in libstdc++-v3/include/bits/atomic_base.h. */
37 1.1 mrg enum memmodel
38 1.1 mrg {
39 1.1 mrg MEMMODEL_RELAXED = 0,
40 1.1 mrg MEMMODEL_CONSUME = 1,
41 1.1 mrg MEMMODEL_ACQUIRE = 2,
42 1.1 mrg MEMMODEL_RELEASE = 3,
43 1.1 mrg MEMMODEL_ACQ_REL = 4,
44 1.1 mrg MEMMODEL_SEQ_CST = 5,
45 1.1 mrg MEMMODEL_LAST = 6,
46 1.1 mrg MEMMODEL_SYNC_ACQUIRE = MEMMODEL_ACQUIRE | MEMMODEL_SYNC,
47 1.1 mrg MEMMODEL_SYNC_RELEASE = MEMMODEL_RELEASE | MEMMODEL_SYNC,
48 1.1.1.2 mrg MEMMODEL_SYNC_SEQ_CST = MEMMODEL_SEQ_CST | MEMMODEL_SYNC,
49 1.1.1.2 mrg /* Say that all the higher bits are valid target extensions. */
50 1.1.1.2 mrg MEMMODEL_MAX = INTTYPE_MAXIMUM (int)
51 1.1 mrg };
52 1.1 mrg
53 1.1 mrg /* Return the memory model from a host integer. */
54 1.1 mrg static inline enum memmodel
55 1.1 mrg memmodel_from_int (unsigned HOST_WIDE_INT val)
56 1.1 mrg {
57 1.1 mrg return (enum memmodel) (val & MEMMODEL_MASK);
58 1.1 mrg }
59 1.1 mrg
60 1.1 mrg /* Return the base memory model from a host integer. */
61 1.1 mrg static inline enum memmodel
62 1.1 mrg memmodel_base (unsigned HOST_WIDE_INT val)
63 1.1 mrg {
64 1.1 mrg return (enum memmodel) (val & MEMMODEL_BASE_MASK);
65 1.1 mrg }
66 1.1 mrg
67 1.1 mrg /* Return TRUE if the memory model is RELAXED. */
68 1.1 mrg static inline bool
69 1.1 mrg is_mm_relaxed (enum memmodel model)
70 1.1 mrg {
71 1.1 mrg return (model & MEMMODEL_BASE_MASK) == MEMMODEL_RELAXED;
72 1.1 mrg }
73 1.1 mrg
74 1.1 mrg /* Return TRUE if the memory model is CONSUME. */
75 1.1 mrg static inline bool
76 1.1 mrg is_mm_consume (enum memmodel model)
77 1.1 mrg {
78 1.1 mrg return (model & MEMMODEL_BASE_MASK) == MEMMODEL_CONSUME;
79 1.1 mrg }
80 1.1 mrg
81 1.1 mrg /* Return TRUE if the memory model is ACQUIRE. */
82 1.1 mrg static inline bool
83 1.1 mrg is_mm_acquire (enum memmodel model)
84 1.1 mrg {
85 1.1 mrg return (model & MEMMODEL_BASE_MASK) == MEMMODEL_ACQUIRE;
86 1.1 mrg }
87 1.1 mrg
88 1.1 mrg /* Return TRUE if the memory model is RELEASE. */
89 1.1 mrg static inline bool
90 1.1 mrg is_mm_release (enum memmodel model)
91 1.1 mrg {
92 1.1 mrg return (model & MEMMODEL_BASE_MASK) == MEMMODEL_RELEASE;
93 1.1 mrg }
94 1.1 mrg
95 1.1 mrg /* Return TRUE if the memory model is ACQ_REL. */
96 1.1 mrg static inline bool
97 1.1 mrg is_mm_acq_rel (enum memmodel model)
98 1.1 mrg {
99 1.1 mrg return (model & MEMMODEL_BASE_MASK) == MEMMODEL_ACQ_REL;
100 1.1 mrg }
101 1.1 mrg
102 1.1 mrg /* Return TRUE if the memory model is SEQ_CST. */
103 1.1 mrg static inline bool
104 1.1 mrg is_mm_seq_cst (enum memmodel model)
105 1.1 mrg {
106 1.1 mrg return (model & MEMMODEL_BASE_MASK) == MEMMODEL_SEQ_CST;
107 1.1 mrg }
108 1.1 mrg
109 1.1 mrg /* Return TRUE if the memory model is a SYNC variant. */
110 1.1 mrg static inline bool
111 1.1 mrg is_mm_sync (enum memmodel model)
112 1.1 mrg {
113 1.1 mrg return (model & MEMMODEL_SYNC);
114 1.1 mrg }
115 1.1 mrg
116 1.1 mrg #endif /* GCC_MEMMODEL_H */
117