gen-atomic-fallback.sh (47401d94947d507ff9f33fccf490baf47638fb69) | gen-atomic-fallback.sh (f3e615b4db1fb7034f1d76dc307b77cc848f040e) |
---|---|
1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3 4ATOMICDIR=$(dirname $0) | 1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3 4ATOMICDIR=$(dirname $0) |
5ARCH=$2 | |
6 7. ${ATOMICDIR}/atomic-tbl.sh 8 | 5 6. ${ATOMICDIR}/atomic-tbl.sh 7 |
9#gen_template_fallback(template, meta, pfx, name, sfx, order, arch, atomic, int, args...) | 8#gen_template_fallback(template, meta, pfx, name, sfx, order, atomic, int, args...) |
10gen_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 | 9gen_template_fallback() 10{ 11 local template="$1"; shift 12 local meta="$1"; shift 13 local pfx="$1"; shift 14 local name="$1"; shift 15 local sfx="$1"; shift 16 local order="$1"; shift |
18 local arch="$1"; shift | |
19 local atomic="$1"; shift 20 local int="$1"; shift 21 | 17 local atomic="$1"; shift 18 local int="$1"; shift 19 |
22 local atomicname="${arch}${atomic}_${pfx}${name}${sfx}${order}" | 20 local atomicname="arch_${atomic}_${pfx}${name}${sfx}${order}" |
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 | 21 22 local ret="$(gen_ret_type "${meta}" "${int}")" 23 local retstmt="$(gen_ret_stmt "${meta}")" 24 local params="$(gen_params "${int}" "${atomic}" "$@")" 25 local args="$(gen_args "$@")" 26 27 if [ ! -z "${template}" ]; then 28 printf "#ifndef ${atomicname}\n" 29 . ${template} 30 printf "#define ${atomicname} ${atomicname}\n" 31 printf "#endif\n\n" 32 fi 33} 34 |
37#gen_proto_fallback(meta, pfx, name, sfx, order, arch, atomic, int, args...) | 35#gen_proto_fallback(meta, pfx, name, sfx, order, atomic, int, args...) |
38gen_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 --- 14 unchanged lines hidden (view full) --- 60 61gen_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 | 36gen_proto_fallback() 37{ 38 local meta="$1"; shift 39 local pfx="$1"; shift 40 local name="$1"; shift 41 local sfx="$1"; shift 42 local order="$1"; shift 43 --- 14 unchanged lines hidden (view full) --- 58 59gen_proto_order_variant() 60{ 61 local meta="$1"; shift 62 local pfx="$1"; shift 63 local name="$1"; shift 64 local sfx="$1"; shift 65 local order="$1"; shift |
68 local arch="$1" 69 local atomic="$2" | 66 local atomic="$1" |
70 | 67 |
71 local basename="${arch}${atomic}_${pfx}${name}${sfx}" | 68 local basename="arch_${atomic}_${pfx}${name}${sfx}" |
72 | 69 |
73 printf "#define arch_${basename}${order} ${basename}${order}\n" | 70 printf "#define ${basename}${order} ${basename}${order}\n" |
74} 75 | 71} 72 |
76#gen_proto_order_variants(meta, pfx, name, sfx, arch, atomic, int, args...) | 73#gen_proto_order_variants(meta, pfx, name, sfx, atomic, int, args...) |
77gen_proto_order_variants() 78{ 79 local meta="$1"; shift 80 local pfx="$1"; shift 81 local name="$1"; shift 82 local sfx="$1"; shift | 74gen_proto_order_variants() 75{ 76 local meta="$1"; shift 77 local pfx="$1"; shift 78 local name="$1"; shift 79 local sfx="$1"; shift |
83 local arch="$1" 84 local atomic="$2" | 80 local atomic="$1" |
85 | 81 |
86 local basename="${arch}${atomic}_${pfx}${name}${sfx}" | 82 local basename="arch_${atomic}_${pfx}${name}${sfx}" |
87 88 local template="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")" 89 | 83 84 local template="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")" 85 |
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 | |
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 --- 68 unchanged lines hidden (view full) --- 182 printf "#endif /* ${xchg}_relaxed */\n\n" 183} 184 185gen_try_cmpxchg_fallback() 186{ 187 local order="$1"; shift; 188 189cat <<EOF | 86 # If we don't have relaxed atomics, then we don't bother with ordering fallbacks 87 # read_acquire and set_release need to be templated, though 88 if ! meta_has_relaxed "${meta}"; then 89 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@" 90 91 if meta_has_acquire "${meta}"; then 92 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@" 93 fi --- 68 unchanged lines hidden (view full) --- 162 printf "#endif /* ${xchg}_relaxed */\n\n" 163} 164 165gen_try_cmpxchg_fallback() 166{ 167 local order="$1"; shift; 168 169cat <<EOF |
190#ifndef ${ARCH}try_cmpxchg${order} 191#define ${ARCH}try_cmpxchg${order}(_ptr, _oldp, _new) \\ | 170#ifndef arch_try_cmpxchg${order} 171#define arch_try_cmpxchg${order}(_ptr, _oldp, _new) \\ |
192({ \\ 193 typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \\ | 172({ \\ 173 typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \\ |
194 ___r = ${ARCH}cmpxchg${order}((_ptr), ___o, (_new)); \\ | 174 ___r = arch_cmpxchg${order}((_ptr), ___o, (_new)); \\ |
195 if (unlikely(___r != ___o)) \\ 196 *___op = ___r; \\ 197 likely(___r == ___o); \\ 198}) | 175 if (unlikely(___r != ___o)) \\ 176 *___op = ___r; \\ 177 likely(___r == ___o); \\ 178}) |
199#endif /* ${ARCH}try_cmpxchg${order} */ | 179#endif /* arch_try_cmpxchg${order} */ |
200 201EOF 202} 203 204gen_try_cmpxchg_fallbacks() 205{ | 180 181EOF 182} 183 184gen_try_cmpxchg_fallbacks() 185{ |
206 printf "#ifndef ${ARCH}try_cmpxchg_relaxed\n" 207 printf "#ifdef ${ARCH}try_cmpxchg\n" | 186 printf "#ifndef arch_try_cmpxchg_relaxed\n" 187 printf "#ifdef arch_try_cmpxchg\n" |
208 | 188 |
209 gen_basic_fallbacks "${ARCH}try_cmpxchg" | 189 gen_basic_fallbacks "arch_try_cmpxchg" |
210 | 190 |
211 printf "#endif /* ${ARCH}try_cmpxchg */\n\n" | 191 printf "#endif /* arch_try_cmpxchg */\n\n" |
212 213 for order in "" "_acquire" "_release" "_relaxed"; do 214 gen_try_cmpxchg_fallback "${order}" 215 done 216 | 192 193 for order in "" "_acquire" "_release" "_relaxed"; do 194 gen_try_cmpxchg_fallback "${order}" 195 done 196 |
217 printf "#else /* ${ARCH}try_cmpxchg_relaxed */\n" | 197 printf "#else /* arch_try_cmpxchg_relaxed */\n" |
218 | 198 |
219 gen_order_fallbacks "${ARCH}try_cmpxchg" | 199 gen_order_fallbacks "arch_try_cmpxchg" |
220 | 200 |
221 printf "#endif /* ${ARCH}try_cmpxchg_relaxed */\n\n" | 201 printf "#endif /* arch_try_cmpxchg_relaxed */\n\n" |
222} 223 224cat << EOF 225// SPDX-License-Identifier: GPL-2.0 226 227// Generated by $0 228// DO NOT MODIFY THIS FILE DIRECTLY 229 230#ifndef _LINUX_ATOMIC_FALLBACK_H 231#define _LINUX_ATOMIC_FALLBACK_H 232 233#include <linux/compiler.h> 234 235EOF 236 | 202} 203 204cat << EOF 205// SPDX-License-Identifier: GPL-2.0 206 207// Generated by $0 208// DO NOT MODIFY THIS FILE DIRECTLY 209 210#ifndef _LINUX_ATOMIC_FALLBACK_H 211#define _LINUX_ATOMIC_FALLBACK_H 212 213#include <linux/compiler.h> 214 215EOF 216 |
237for xchg in "${ARCH}xchg" "${ARCH}cmpxchg" "${ARCH}cmpxchg64"; do | 217for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64"; do |
238 gen_xchg_fallbacks "${xchg}" 239done 240 241gen_try_cmpxchg_fallbacks 242 243grep '^[a-z]' "$1" | while read name meta args; do | 218 gen_xchg_fallbacks "${xchg}" 219done 220 221gen_try_cmpxchg_fallbacks 222 223grep '^[a-z]' "$1" | while read name meta args; do |
244 gen_proto "${meta}" "${name}" "${ARCH}" "atomic" "int" ${args} | 224 gen_proto "${meta}" "${name}" "atomic" "int" ${args} |
245done 246 247cat <<EOF 248#ifdef CONFIG_GENERIC_ATOMIC64 249#include <asm-generic/atomic64.h> 250#endif 251 252EOF 253 254grep '^[a-z]' "$1" | while read name meta args; do | 225done 226 227cat <<EOF 228#ifdef CONFIG_GENERIC_ATOMIC64 229#include <asm-generic/atomic64.h> 230#endif 231 232EOF 233 234grep '^[a-z]' "$1" | while read name meta args; do |
255 gen_proto "${meta}" "${name}" "${ARCH}" "atomic64" "s64" ${args} | 235 gen_proto "${meta}" "${name}" "atomic64" "s64" ${args} |
256done 257 258cat <<EOF 259#endif /* _LINUX_ATOMIC_FALLBACK_H */ 260EOF | 236done 237 238cat <<EOF 239#endif /* _LINUX_ATOMIC_FALLBACK_H */ 240EOF |