2 # SPDX-License-Identifier: GPL-2.0
3 # helpers for dealing with atomics.tbl
18 meta_in "$1" "bBiIfFlR"
21 #meta_has_acquire(meta)
27 #meta_has_release(meta)
33 #meta_has_relaxed(meta)
39 #find_fallback_template(pfx, name, sfx, order)
40 find_fallback_template()
43 local name="$1"; shift
45 local order="$1"; shift
50 # We may have fallbacks for a specific case (e.g. read_acquire()), or
51 # an entire class, e.g. *inc*().
53 # Start at the most specific, and fall back to the most general. Once
54 # we find a specific fallback, don't bother looking for more.
55 for base in "${pfx}${name}${sfx}${order}" "${name}"; do
56 file="${ATOMICDIR}/fallbacks/${base}"
58 if [ -f "${file}" ]; then
65 #gen_ret_type(meta, int)
67 local meta="$1"; shift
73 [aiIfFlR]) printf "${int}";;
80 if meta_has_ret "${meta}"; then
88 # strip off the leading 'c' for 'cv'
93 # gen_param_type(arg, int, atomic)
96 local type="${1%%:*}"; shift
98 local atomic="$1"; shift
103 v) type="${atomic}_t *";;
104 cv) type="const ${atomic}_t *";;
110 #gen_param(arg, int, atomic)
113 local arg="$1"; shift
114 local int="$1"; shift
115 local atomic="$1"; shift
116 local name="$(gen_param_name "${arg}")"
117 local type="$(gen_param_type "${arg}" "${int}" "${atomic}")"
119 printf "${type}${name}"
122 #gen_params(int, atomic, arg...)
125 local int="$1"; shift
126 local atomic="$1"; shift
128 while [ "$#" -gt 0 ]; do
129 gen_param "$1" "${int}" "${atomic}"
130 [ "$#" -gt 1 ] && printf ", "
138 while [ "$#" -gt 0 ]; do
139 printf "$(gen_param_name "$1")"
140 [ "$#" -gt 1 ] && printf ", "
145 #gen_proto_order_variants(meta, pfx, name, sfx, ...)
146 gen_proto_order_variants()
148 local meta="$1"; shift
149 local pfx="$1"; shift
150 local name="$1"; shift
151 local sfx="$1"; shift
153 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
155 if meta_has_acquire "${meta}"; then
156 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
158 if meta_has_release "${meta}"; then
159 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
161 if meta_has_relaxed "${meta}"; then
162 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@"
166 #gen_proto_variants(meta, name, ...)
169 local meta="$1"; shift
170 local name="$1"; shift
174 meta_in "${meta}" "fF" && pfx="fetch_"
175 meta_in "${meta}" "R" && sfx="_return"
177 gen_proto_order_variants "${meta}" "${pfx}" "${name}" "${sfx}" "$@"
180 #gen_proto(meta, ...)
182 local meta="$1"; shift
183 for m in $(echo "${meta}" | grep -o .); do
184 gen_proto_variants "${m}" "$@"