6 Usage: $self [options] FILE
8 Reads the Run Time CPU Detections definitions from FILE and generates a
9 C header file on stdout.
12 --arch=ARCH Architecture to generate defs for (required)
13 --disable-EXT Disable support for EXT extensions
14 --require-EXT Require support for EXT extensions
15 --sym=SYMBOL Unique symbol to use for RTCD initialization function
16 --config=FILE File with CONFIG_FOO=yes lines to parse
26 die_argument_required() {
27 die "Option $opt requires argument"
33 --arch) die_argument_required;;
34 --arch=*) arch=${optval};;
35 --disable-*) eval "disable_${opt#--disable-}=true";;
36 --require-*) REQUIRES="${REQUIRES}${opt#--require-} ";;
37 --sym) die_argument_required;;
38 --sym=*) symbol=${optval};;
39 --config=*) config_file=${optval};;
44 die "Unrecognized option: ${opt%%=*}"
47 defs_file="$defs_file $opt"
52 for f in $defs_file; do [ -f "$f" ] || usage; done
53 [ -n "$arch" ] || usage
55 # Import the configuration
56 [ -f "$config_file" ] && eval $(grep CONFIG_ "$config_file")
59 # Routines for the RTCD DSL to call
64 unsigned) rtyp="$1 "; shift;;
70 eval "${2}_rtyp='$rtyp'"
72 ALL_FUNCS="$ALL_FUNCS $fn"
80 eval "${fn}_${opt}=${fn}_${opt}"
85 for fn in $ALL_FUNCS; do
87 ofn=$(eval "echo \$${fn}_${opt}")
88 [ -z "$ofn" ] && continue
90 # if we already have a default, then we can disable it, as we know
92 best=$(eval "echo \$${fn}_default")
93 best_ofn=$(eval "echo \$${best}")
94 [ -n "$best" ] && [ "$best_ofn" != "$ofn" ] && eval "${best}_link=false"
95 eval "${fn}_default=${fn}_${opt}"
96 eval "${fn}_${opt}_link=true"
102 ALL_FORWARD_DECLS="$ALL_FORWARD_DECLS $1"
106 # Include the user's directives
108 for f in $defs_file; do
113 # Process the directives according to the command line
115 process_forward_decls() {
116 for fn in $ALL_FORWARD_DECLS; do
121 determine_indirection() {
122 [ "$CONFIG_RUNTIME_CPU_DETECT" = "yes" ] || require $ALL_ARCHS
123 for fn in $ALL_FUNCS; do
125 rtyp="$(eval "echo \$${fn}_rtyp")"
126 args="$(eval "echo \"\$${fn}_args\"")"
127 dfn="$(eval "echo \$${fn}_default")"
128 dfn=$(eval "echo \$${dfn}")
130 ofn=$(eval "echo \$${fn}_${opt}")
131 [ -z "$ofn" ] && continue
132 link=$(eval "echo \$${fn}_${opt}_link")
133 [ "$link" = "false" ] && continue
136 if [ "$n" = "x" ]; then
137 eval "${fn}_indirect=false"
139 eval "${fn}_indirect=true"
144 declare_function_pointers() {
145 for fn in $ALL_FUNCS; do
146 rtyp="$(eval "echo \$${fn}_rtyp")"
147 args="$(eval "echo \"\$${fn}_args\"")"
148 dfn="$(eval "echo \$${fn}_default")"
149 dfn=$(eval "echo \$${dfn}")
151 ofn=$(eval "echo \$${fn}_${opt}")
152 [ -z "$ofn" ] && continue
153 echo "$rtyp ${ofn}($args);"
155 if [ "$(eval "echo \$${fn}_indirect")" = "false" ]; then
156 echo "#define ${fn} ${dfn}"
158 echo "RTCD_EXTERN $rtyp (*${fn})($args);"
164 set_function_pointers() {
165 for fn in $ALL_FUNCS; do
167 rtyp="$(eval "echo \$${fn}_rtyp")"
168 args="$(eval "echo \"\$${fn}_args\"")"
169 dfn="$(eval "echo \$${fn}_default")"
170 dfn=$(eval "echo \$${dfn}")
171 if $(eval "echo \$${fn}_indirect"); then
174 ofn=$(eval "echo \$${fn}_${opt}")
175 [ -z "$ofn" ] && continue
176 [ "$ofn" = "$dfn" ] && continue;
177 link=$(eval "echo \$${fn}_${opt}_link")
178 [ "$link" = "false" ] && continue
179 cond="$(eval "echo \$have_${opt}")"
180 echo " if (${cond}) $fn = $ofn;"
190 [ -z $(eval "echo \$disable_${opt}") ] && filtered="$filtered $opt"
196 # Helper functions for generating the arch specific RTCD files
199 outfile_basename=$(basename ${symbol:-rtcd})
200 include_guard=$(echo $outfile_basename | tr '[a-z]' '[A-Z]' | \
201 tr -c '[A-Z0-9]' _)H_
203 #ifndef ${include_guard}
204 #define ${include_guard}
209 #define RTCD_EXTERN extern
216 $(process_forward_decls)
218 $(declare_function_pointers c $ALL_ARCHS)
220 void ${symbol:-rtcd}(void);
236 determine_indirection c $ALL_ARCHS
238 # Assign the helper variable for each enabled extension
239 for opt in $ALL_ARCHS; do
240 uc=$(echo $opt | tr '[a-z]' '[A-Z]')
241 eval "have_${opt}=\"flags & HAS_${uc}\""
248 #include "vpx_ports/x86.h"
249 static void setup_rtcd_internal(void)
251 int flags = x86_simd_caps();
255 $(set_function_pointers c $ALL_ARCHS)
263 determine_indirection c $ALL_ARCHS
265 # Assign the helper variable for each enabled extension
266 for opt in $ALL_ARCHS; do
267 uc=$(echo $opt | tr '[a-z]' '[A-Z]')
268 eval "have_${opt}=\"flags & HAS_${uc}\""
273 #include "vpx_config.h"
276 #include "vpx_ports/arm.h"
277 static void setup_rtcd_internal(void)
279 int flags = arm_cpu_caps();
283 $(set_function_pointers c $ALL_ARCHS)
292 determine_indirection c $ALL_ARCHS
295 #include "vpx_config.h"
298 static void setup_rtcd_internal(void)
300 $(set_function_pointers c $ALL_ARCHS)
303 void dsputil_static_init();
304 dsputil_static_init();
307 void vp9_dsputil_static_init();
308 vp9_dsputil_static_init();
318 determine_indirection c
321 #include "vpx_config.h"
324 static void setup_rtcd_internal(void)
326 $(set_function_pointers c)
336 ALL_FUNCS=$(export LC_ALL=C; echo $ALL_FUNCS | tr ' ' '\n' | sort |tr '\n' ' ')
340 ALL_ARCHS=$(filter mmx sse sse2 sse3 ssse3 sse4_1 avx avx2)
344 ALL_ARCHS=$(filter mmx sse sse2 sse3 ssse3 sse4_1 avx avx2)
345 REQUIRES=${REQUIRES:-mmx sse sse2}
346 require $(filter $REQUIRES)
350 ALL_ARCHS=$(filter mips32)
351 dspr2=$([ -f "$config_file" ] && eval echo $(grep HAVE_DSPR2 "$config_file"))
352 HAVE_DSPR2="${dspr2#*=}"
353 if [ "$HAVE_DSPR2" = "yes" ]; then
354 ALL_ARCHS=$(filter mips32 dspr2)
359 ALL_ARCHS=$(filter edsp)
363 ALL_ARCHS=$(filter edsp media)
367 ALL_ARCHS=$(filter edsp media neon)