David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | |
| 4 | ATOMICDIR=$(dirname $0) |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5 | ARCH=$2 |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6 | |
| 7 | . ${ATOMICDIR}/atomic-tbl.sh |
| 8 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9 | #gen_template_fallback(template, meta, pfx, name, sfx, order, arch, atomic, int, args...) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10 | gen_template_fallback() |
| 11 | { |
| 12 | local template="$1"; shift |
| 13 | local meta="$1"; shift |
| 14 | local pfx="$1"; shift |
| 15 | local name="$1"; shift |
| 16 | local sfx="$1"; shift |
| 17 | local order="$1"; shift |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 18 | local arch="$1"; shift |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 19 | local atomic="$1"; shift |
| 20 | local int="$1"; shift |
| 21 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 22 | local atomicname="${arch}${atomic}_${pfx}${name}${sfx}${order}" |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 23 | |
| 24 | local ret="$(gen_ret_type "${meta}" "${int}")" |
| 25 | local retstmt="$(gen_ret_stmt "${meta}")" |
| 26 | local params="$(gen_params "${int}" "${atomic}" "$@")" |
| 27 | local args="$(gen_args "$@")" |
| 28 | |
| 29 | if [ ! -z "${template}" ]; then |
| 30 | printf "#ifndef ${atomicname}\n" |
| 31 | . ${template} |
| 32 | printf "#define ${atomicname} ${atomicname}\n" |
| 33 | printf "#endif\n\n" |
| 34 | fi |
| 35 | } |
| 36 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 37 | #gen_proto_fallback(meta, pfx, name, sfx, order, arch, atomic, int, args...) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 38 | gen_proto_fallback() |
| 39 | { |
| 40 | local meta="$1"; shift |
| 41 | local pfx="$1"; shift |
| 42 | local name="$1"; shift |
| 43 | local sfx="$1"; shift |
| 44 | local order="$1"; shift |
| 45 | |
| 46 | local tmpl="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")" |
| 47 | gen_template_fallback "${tmpl}" "${meta}" "${pfx}" "${name}" "${sfx}" "${order}" "$@" |
| 48 | } |
| 49 | |
| 50 | #gen_basic_fallbacks(basename) |
| 51 | gen_basic_fallbacks() |
| 52 | { |
| 53 | local basename="$1"; shift |
| 54 | cat << EOF |
| 55 | #define ${basename}_acquire ${basename} |
| 56 | #define ${basename}_release ${basename} |
| 57 | #define ${basename}_relaxed ${basename} |
| 58 | EOF |
| 59 | } |
| 60 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 61 | gen_proto_order_variant() |
| 62 | { |
| 63 | local meta="$1"; shift |
| 64 | local pfx="$1"; shift |
| 65 | local name="$1"; shift |
| 66 | local sfx="$1"; shift |
| 67 | local order="$1"; shift |
| 68 | local arch="$1" |
| 69 | local atomic="$2" |
| 70 | |
| 71 | local basename="${arch}${atomic}_${pfx}${name}${sfx}" |
| 72 | |
| 73 | printf "#define arch_${basename}${order} ${basename}${order}\n" |
| 74 | } |
| 75 | |
| 76 | #gen_proto_order_variants(meta, pfx, name, sfx, arch, atomic, int, args...) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 77 | gen_proto_order_variants() |
| 78 | { |
| 79 | local meta="$1"; shift |
| 80 | local pfx="$1"; shift |
| 81 | local name="$1"; shift |
| 82 | local sfx="$1"; shift |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 83 | local arch="$1" |
| 84 | local atomic="$2" |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 85 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 86 | local basename="${arch}${atomic}_${pfx}${name}${sfx}" |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 87 | |
| 88 | local template="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")" |
| 89 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 90 | if [ -z "$arch" ]; then |
| 91 | gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@" |
| 92 | |
| 93 | if meta_has_acquire "${meta}"; then |
| 94 | gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@" |
| 95 | fi |
| 96 | if meta_has_release "${meta}"; then |
| 97 | gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@" |
| 98 | fi |
| 99 | if meta_has_relaxed "${meta}"; then |
| 100 | gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@" |
| 101 | fi |
| 102 | |
| 103 | echo "" |
| 104 | fi |
| 105 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 106 | # If we don't have relaxed atomics, then we don't bother with ordering fallbacks |
| 107 | # read_acquire and set_release need to be templated, though |
| 108 | if ! meta_has_relaxed "${meta}"; then |
| 109 | gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@" |
| 110 | |
| 111 | if meta_has_acquire "${meta}"; then |
| 112 | gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@" |
| 113 | fi |
| 114 | |
| 115 | if meta_has_release "${meta}"; then |
| 116 | gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@" |
| 117 | fi |
| 118 | |
| 119 | return |
| 120 | fi |
| 121 | |
| 122 | printf "#ifndef ${basename}_relaxed\n" |
| 123 | |
| 124 | if [ ! -z "${template}" ]; then |
| 125 | printf "#ifdef ${basename}\n" |
| 126 | fi |
| 127 | |
| 128 | gen_basic_fallbacks "${basename}" |
| 129 | |
| 130 | if [ ! -z "${template}" ]; then |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 131 | printf "#endif /* ${arch}${atomic}_${pfx}${name}${sfx} */\n\n" |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 132 | gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@" |
| 133 | gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@" |
| 134 | gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@" |
| 135 | gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@" |
| 136 | fi |
| 137 | |
| 138 | printf "#else /* ${basename}_relaxed */\n\n" |
| 139 | |
| 140 | gen_template_fallback "${ATOMICDIR}/fallbacks/acquire" "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@" |
| 141 | gen_template_fallback "${ATOMICDIR}/fallbacks/release" "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@" |
| 142 | gen_template_fallback "${ATOMICDIR}/fallbacks/fence" "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@" |
| 143 | |
| 144 | printf "#endif /* ${basename}_relaxed */\n\n" |
| 145 | } |
| 146 | |
| 147 | gen_xchg_fallbacks() |
| 148 | { |
| 149 | local xchg="$1"; shift |
| 150 | cat <<EOF |
| 151 | #ifndef ${xchg}_relaxed |
| 152 | #define ${xchg}_relaxed ${xchg} |
| 153 | #define ${xchg}_acquire ${xchg} |
| 154 | #define ${xchg}_release ${xchg} |
| 155 | #else /* ${xchg}_relaxed */ |
| 156 | |
| 157 | #ifndef ${xchg}_acquire |
| 158 | #define ${xchg}_acquire(...) \\ |
| 159 | __atomic_op_acquire(${xchg}, __VA_ARGS__) |
| 160 | #endif |
| 161 | |
| 162 | #ifndef ${xchg}_release |
| 163 | #define ${xchg}_release(...) \\ |
| 164 | __atomic_op_release(${xchg}, __VA_ARGS__) |
| 165 | #endif |
| 166 | |
| 167 | #ifndef ${xchg} |
| 168 | #define ${xchg}(...) \\ |
| 169 | __atomic_op_fence(${xchg}, __VA_ARGS__) |
| 170 | #endif |
| 171 | |
| 172 | #endif /* ${xchg}_relaxed */ |
| 173 | |
| 174 | EOF |
| 175 | } |
| 176 | |
| 177 | cat << EOF |
| 178 | // SPDX-License-Identifier: GPL-2.0 |
| 179 | |
| 180 | // Generated by $0 |
| 181 | // DO NOT MODIFY THIS FILE DIRECTLY |
| 182 | |
| 183 | #ifndef _LINUX_ATOMIC_FALLBACK_H |
| 184 | #define _LINUX_ATOMIC_FALLBACK_H |
| 185 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 186 | #include <linux/compiler.h> |
| 187 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 188 | EOF |
| 189 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 190 | for xchg in "${ARCH}xchg" "${ARCH}cmpxchg" "${ARCH}cmpxchg64"; do |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 191 | gen_xchg_fallbacks "${xchg}" |
| 192 | done |
| 193 | |
| 194 | grep '^[a-z]' "$1" | while read name meta args; do |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 195 | gen_proto "${meta}" "${name}" "${ARCH}" "atomic" "int" ${args} |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 196 | done |
| 197 | |
| 198 | cat <<EOF |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 199 | #ifdef CONFIG_GENERIC_ATOMIC64 |
| 200 | #include <asm-generic/atomic64.h> |
| 201 | #endif |
| 202 | |
| 203 | EOF |
| 204 | |
| 205 | grep '^[a-z]' "$1" | while read name meta args; do |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 206 | gen_proto "${meta}" "${name}" "${ARCH}" "atomic64" "s64" ${args} |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 207 | done |
| 208 | |
| 209 | cat <<EOF |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 210 | #endif /* _LINUX_ATOMIC_FALLBACK_H */ |
| 211 | EOF |