diff options
author | Nick Foster | 2011-04-15 17:51:28 -0700 |
---|---|---|
committer | Nick Foster | 2011-04-15 17:51:28 -0700 |
commit | 8608fc3ae5f891eb5c11345a9b6102fdc8ae2393 (patch) | |
tree | 7bf1decdc292b1584989604e54204a11552ba7d2 | |
parent | 129ebd4dd46e92760f431c766ba61781f5885c41 (diff) | |
download | gnuradio-8608fc3ae5f891eb5c11345a9b6102fdc8ae2393.tar.gz gnuradio-8608fc3ae5f891eb5c11345a9b6102fdc8ae2393.tar.bz2 gnuradio-8608fc3ae5f891eb5c11345a9b6102fdc8ae2393.zip |
Volk: volk.c is now generated. manual build works OK.
-rw-r--r-- | volk/include/volk/make_c.py | 127 | ||||
-rw-r--r-- | volk/include/volk/make_h.py | 28 | ||||
-rw-r--r-- | volk/include/volk/make_init_c.py | 42 | ||||
-rw-r--r-- | volk/include/volk/make_init_h.py | 26 | ||||
-rw-r--r-- | volk/include/volk/make_machines_c.py | 2 | ||||
-rw-r--r-- | volk/include/volk/make_mktables.py | 33 | ||||
-rw-r--r-- | volk/include/volk/make_runtime.py | 27 | ||||
-rw-r--r-- | volk/include/volk/make_runtime_c.py | 47 | ||||
-rwxr-xr-x | volk/include/volk/volk_register.py | 51 |
9 files changed, 102 insertions, 281 deletions
diff --git a/volk/include/volk/make_c.py b/volk/include/volk/make_c.py index 89bf9ea1a..5f6669e40 100644 --- a/volk/include/volk/make_c.py +++ b/volk/include/volk/make_c.py @@ -1,55 +1,84 @@ -from xml.dom import minidom -import string +# +# Copyright 2010 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + from volk_regexp import * +import string +from emit_omnilog import * +#ok todo list: +#put n_archs into the info struct so it doesn't have to be arch_defs[0]. -def make_c(funclist, taglist, arched_arglist, retlist, my_arglist, fcountlist) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/'; - tempstring = tempstring + '\n\n#include<volk/volk.h>\n'; - tempstring = tempstring + '#include<volk/volk_tables.h>\n'; - tempstring = tempstring + '#include<volk/volk_typedefs.h>\n'; - tempstring = tempstring + '#include<volk/volk_registry.h>\n'; - tempstring = tempstring + '#include<string.h>\n'; - for func in funclist: - tempstring = tempstring + "#include<volk/" + func + ".h>\n" ; - tempstring = tempstring + '\n'; - - tempstring = tempstring + "static inline unsigned int volk_get_index(const char** indices, const char* arch, const int* arch_defs) {\n"; - tempstring = tempstring + " int i = 1;\n" - tempstring = tempstring + " for(;i<arch_defs[0];++i){\n" - tempstring = tempstring + " if (strcmp(arch, indices[i]) == 0) {\n" - tempstring = tempstring + " return i;\n" - tempstring = tempstring + " }\n" - tempstring = tempstring + " }\n" - tempstring = tempstring + " return 0;\n" - tempstring = tempstring + "}\n" - - for i in range(len(funclist)): - tempstring = tempstring + "static const " + replace_volk.sub("p", funclist[i]) + " " + funclist[i] + "_archs[] = {\n"; - - tags_counter = 0; - for arch_list in fcountlist[i]: - tempstring = tempstring + "#if defined(LV_HAVE_" - for ind in range(len(arch_list)): - - tempstring = tempstring + arch_list[ind] + ")"; - if ind < len(arch_list) - 1: - tempstring = tempstring + " && defined(LV_HAVE_"; - - tempstring = tempstring + "\n " + funclist[i] + "_" + str(taglist[i][tags_counter]) + ",\n#endif\n"; - tags_counter = tags_counter + 1; - - lindex = tempstring.rfind(","); - tempstring = tempstring[0:lindex] + string.replace(tempstring[lindex:len(tempstring)], ",", ""); - tempstring = tempstring + "};\n\n"; - - tempstring = tempstring + retlist[i] + "inline " + funclist[i] + "_manual" + arched_arglist[i] + '\n'; - tempstring = tempstring + "return " + funclist[i] + "_archs[volk_get_index(" + funclist[i] + "_indices, arch, " + funclist[i] + "_arch_defs)](" + my_arglist[i] + ");" + "\n}\n"; +def make_c(machines, archs, functions, arched_arglist, my_arglist): + tempstring = r""" +// This file is automatically generated by make_c.py. +// Do not edit this file. +""" + tempstring += """ +#include <volk_common.h> +#include <volk_machines.h> +#include <volk_registry.h> +#include <volk_typedefs.h> +#include <volk_cpu.h> +#include <volk_rank_archs.h> +#include <volk.h> +#include <stdio.h> + +""" + tempstring += emit_prolog(); - tempstring = tempstring + retlist[i] + "inline " + funclist[i] + replace_arch.sub("", arched_arglist[i]) + '\n'; +#OK here's the deal. the .h prototypes the functions. the .c impls them as fptrs, can use p_whatever. +#also .c impls the get_machine call +#also .c impls the default call for each fn + +#here do static fn get arch + tempstring += r""" +struct volk_machine *get_machine(void) { + extern struct volk_machine volk_machines[]; + extern unsigned int n_volk_machines; + static struct volk_machine *machine = NULL; - tempstring = tempstring + funclist[i] + "_archs[" + funclist[i] + "_func_table](" + my_arglist[i] + ");" + '\n'; - tempstring = tempstring + "}\n\n"; + if(machine != NULL) return machine; + else { + unsigned int max_score = 0; + int i; + for(i=0; i<n_volk_machines; i++) { + if(!(volk_machines[i].caps & (~volk_get_lvarch()))) { + if(volk_machines[i].caps > max_score) { + max_score = volk_machines[i].caps; + machine = &(volk_machines[i]); + } + } + } + printf("Using Volk machine: %s\n", machine->name); + return machine; + } +} + +""" - return tempstring; + for i in range(len(functions)): + tempstring += "void get_" + functions[i] + replace_arch.sub("", arched_arglist[i]) + "\n" + tempstring += " %s = get_machine()->%s_archs[volk_rank_archs(get_machine()->%s_desc.arch_defs, volk_get_lvarch())];\n" % (functions[i], functions[i], functions[i]) + tempstring += " %s(%s);\n}\n\n" % (functions[i], my_arglist[i]) + tempstring += replace_volk.sub("p", functions[i]) + " " + functions[i] + " = &get_" + functions[i] + ";\n\n" + + + tempstring += emit_epilog(); + + return tempstring + + diff --git a/volk/include/volk/make_h.py b/volk/include/volk/make_h.py index 6aea441b7..b235cd657 100644 --- a/volk/include/volk/make_h.py +++ b/volk/include/volk/make_h.py @@ -4,24 +4,24 @@ from volk_regexp import * -def make_h(funclist, arched_arglist, retlist) : +def make_h(funclist) : tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/'; - tempstring = tempstring + '\n#ifndef INCLUDED_VOLK_H'; - tempstring = tempstring + '\n#define INCLUDED_VOLK_H'; - tempstring = tempstring + '\n\n#include<inttypes.h>\n'; - tempstring = tempstring + '#include<volk/volk_complex.h>\n'; + tempstring = tempstring + '/*this file is auto generated by make_h.py*/\n'; + + tempstring = tempstring + '\n#ifndef INCLUDED_VOLK_RUNTIME'; + tempstring = tempstring + '\n#define INCLUDED_VOLK_RUNTIME'; + tempstring = tempstring + '\n\n#include<volk/volk_typedefs.h>\n'; tempstring = tempstring + '#include<volk/volk_config_fixed.h>\n'; - tempstring = tempstring + '#include<volk/volk_environment_init.h>\n' - tempstring = tempstring + emit_prolog() - tempstring = tempstring + '\n'; + tempstring = tempstring + '#include<volk/volk_complex.h>\n'; + tempstring = tempstring + emit_prolog(); - for i in range(len(retlist)): - tempstring = tempstring + retlist[i] + funclist[i] + replace_bracket.sub(";", replace_arch.sub("", arched_arglist[i])) + '\n'; - tempstring = tempstring + retlist[i] + funclist[i] + "_manual" + replace_bracket.sub(";", arched_arglist[i]) + '\n'; + tempstring = tempstring + '\n'; + + for i in range(len(funclist)): + tempstring = tempstring + "extern " + replace_volk.sub("p", funclist[i]) + " " + funclist[i] + ";\n" tempstring = tempstring + emit_epilog(); + tempstring = tempstring + "#endif /*INCLUDED_VOLK_RUNTIME*/\n"; - tempstring = tempstring + "#endif /*INCLUDED_VOLK_H*/\n"; - return tempstring; + diff --git a/volk/include/volk/make_init_c.py b/volk/include/volk/make_init_c.py deleted file mode 100644 index 0a7010cd6..000000000 --- a/volk/include/volk/make_init_c.py +++ /dev/null @@ -1,42 +0,0 @@ -from xml.dom import minidom - -def make_init_c(funclist, dom) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/'; - - tempstring = tempstring + '\n\n#include<volk/volk_runtime.h>\n'; - tempstring = tempstring + '#include<volk/volk_cpu.h>\n'; - tempstring = tempstring + '#include<volk_init.h>\n'; - for domarch in dom: - arch = str(domarch.attributes["name"].value); - incs = domarch.getElementsByTagName("include"); - for inc in incs: - my_inc = str(inc.firstChild.data); - tempstring = tempstring + "#ifdef LV_HAVE_" + arch.swapcase() + "\n"; - tempstring = tempstring + "#include<" + my_inc + ">\n"; - tempstring = tempstring + "#endif\n" - tempstring = tempstring + '\n\n'; - - tempstring = tempstring + "extern struct VOLK_RUNTIME volk_runtime;\n\n"; - tempstring = tempstring + "struct VOLK_RUNTIME* get_volk_runtime(){\n"; - tempstring = tempstring + " return &volk_runtime;\n"; - tempstring = tempstring + "}\n\n" - tempstring = tempstring + " void volk_runtime_init() {\nvolk_cpu_init();\n"; - - for func in funclist: - tempstring = tempstring + " volk_runtime." + func + " = default_acquire_" + func + ";\n"; - - for domarch in dom: - arch = str(domarch.attributes["name"].value); - envs = domarch.getElementsByTagName("environment"); - for env in envs: - cmd = str(env.firstChild.data); - tempstring = tempstring + " if(volk_cpu.has_" + arch + "()){\n"; - tempstring = tempstring + "#ifdef LV_HAVE_" + arch.swapcase() + "\n"; - tempstring = tempstring + " " + cmd + "\n"; - tempstring = tempstring + "#endif\n" - tempstring = tempstring + " }\n"; - - tempstring = tempstring + "}\n"; - - return tempstring diff --git a/volk/include/volk/make_init_h.py b/volk/include/volk/make_init_h.py deleted file mode 100644 index 6dbe1c585..000000000 --- a/volk/include/volk/make_init_h.py +++ /dev/null @@ -1,26 +0,0 @@ -from xml.dom import minidom -from emit_omnilog import * -from volk_regexp import * - - - -def make_init_h(funclist, arched_arglist, retlist) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/'; - - tempstring = tempstring + '\n#ifndef INCLUDED_VOLK_INIT_H'; - tempstring = tempstring + '\n#define INCLUDED_VOLK_INIT_H'; - tempstring = tempstring + '\n\n#include<inttypes.h>\n'; - tempstring = tempstring + '#include<volk/volk_complex.h>\n'; - - tempstring = tempstring + '\n'; - - tempstring = tempstring + emit_prolog(); - - for i in range(len(retlist)): - tempstring = tempstring + retlist[i] + " default_acquire_" + funclist[i] + replace_bracket.sub(";", replace_arch.sub("", arched_arglist[i])) + '\n'; - - tempstring= tempstring + emit_epilog(); - tempstring = tempstring + "#endif /*INCLUDED_VOLK_INIT_H*/\n"; - - return tempstring; diff --git a/volk/include/volk/make_machines_c.py b/volk/include/volk/make_machines_c.py index 55c0f1c06..12eabf98d 100644 --- a/volk/include/volk/make_machines_c.py +++ b/volk/include/volk/make_machines_c.py @@ -26,7 +26,7 @@ def make_machines_c(machines): #include <volk_typedefs.h> #include <volk_machines.h> -volk_machine volk_machines[] = { +struct volk_machine volk_machines[] = { """ for machine in machines: tempstring += """#if LV_MACHINE_""" + machine.swapcase() + "\n" diff --git a/volk/include/volk/make_mktables.py b/volk/include/volk/make_mktables.py deleted file mode 100644 index 051ac268d..000000000 --- a/volk/include/volk/make_mktables.py +++ /dev/null @@ -1,33 +0,0 @@ - - -def make_mktables(funclist) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/\n'; - - tempstring = tempstring + '#include<stdio.h>\n'; - tempstring = tempstring + '#include<volk/volk_registry.h>\n'; - tempstring = tempstring + '#include<volk_rank_archs.h>\n'; - tempstrgin = tempstring + '#include<volk/volk_cpu.h>\n'; - tempstring = tempstring + "\n\n"; - - tempstring = tempstring + 'int main() {\n'; - tempstring = tempstring + ' int i = 0;\n'; - tempstring = tempstring + ' FILE* output;\n'; - tempstring = tempstring + ' output = fopen("volk_tables.h", "w");\n'; - tempstring = tempstring + ' fprintf(output, "#ifndef INCLUDED_VOLK_TABLES_H\\n");\n'; - tempstring = tempstring + ' fprintf(output, "#define INCLUDED_VOLK_TABLES_H\\n\\n");\n'; - - for func in funclist: - tempstring = tempstring + ' fprintf(output, "static const ' + func + '_func_table = %u;\\n", volk_rank_archs(' + func + '_arch_defs, volk_get_lvarch()));\n'; - tempstring = tempstring + ' fprintf(output, "#endif /*INCLUDED_VOLK_TABLES_H*/\\n");\n'; - tempstring = tempstring + ' fclose(output);\n' - tempstring = tempstring + '}\n'; - return tempstring; - - - - - - - - diff --git a/volk/include/volk/make_runtime.py b/volk/include/volk/make_runtime.py deleted file mode 100644 index d468487d7..000000000 --- a/volk/include/volk/make_runtime.py +++ /dev/null @@ -1,27 +0,0 @@ -from xml.dom import minidom -from emit_omnilog import * -from volk_regexp import * - - - -def make_runtime(funclist, arglist) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/\n'; - - tempstring = tempstring + '\n#ifndef INCLUDED_VOLK_RUNTIME'; - tempstring = tempstring + '\n#define INCLUDED_VOLK_RUNTIME'; - tempstring = tempstring + '\n\n#include<volk/volk_typedefs.h>\n'; - tempstring = tempstring + '#include<volk/volk_config_fixed.h>\n'; - tempstring = tempstring + '#include<volk/volk_complex.h>\n'; - tempstring = tempstring + emit_prolog(); - - tempstring = tempstring + '\n'; - - for i in range(len(funclist)): - tempstring = tempstring + "extern void (*" + funclist[i] + ")(" + arglist[i] + ");\n" - - tempstring = tempstring + emit_epilog(); - tempstring = tempstring + "#endif /*INCLUDED_VOLK_RUNTIME*/\n"; - - return tempstring; - diff --git a/volk/include/volk/make_runtime_c.py b/volk/include/volk/make_runtime_c.py deleted file mode 100644 index 99cdf395f..000000000 --- a/volk/include/volk/make_runtime_c.py +++ /dev/null @@ -1,47 +0,0 @@ -from xml.dom import minidom -import string -from volk_regexp import * - - -def make_runtime_c(funclist, taglist, arched_arglist, retlist, my_arglist, fcountlist, my_argtypelist) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/'; - - - tempstring = tempstring + '\n\n#include<volk/volk_runtime.h>\n'; - tempstring = tempstring + "#include<volk/volk_config_fixed.h>\n"; - tempstring = tempstring + '#include<volk/volk_cpu.h>\n'; - tempstring = tempstring + '#include<volk_init.h>\n'; - tempstring = tempstring + '#include<volk/volk_registry.h>\n'; - - for func in funclist: - tempstring = tempstring + "#include<volk/" + func + ".h>\n" ; - tempstring = tempstring + '\n'; - - for i in range(len(funclist)): - tempstring = tempstring + "static const " + replace_volk.sub("p", funclist[i]) + " " + funclist[i] + "_archs[] = {\n"; - - tags_counter = 0; - for arch_list in fcountlist[i]: - tempstring = tempstring + "#if defined(LV_HAVE_" - for ind in range(len(arch_list)): - - tempstring = tempstring + arch_list[ind] + ")"; - if ind < len(arch_list) - 1: - tempstring = tempstring + " && defined(LV_HAVE_"; - - tempstring = tempstring + "\n " + funclist[i] + "_" + str(taglist[i][tags_counter]) + ",\n#endif\n"; - tags_counter = tags_counter + 1; - - lindex = tempstring.rfind(","); - tempstring = tempstring[0:lindex] + string.replace(tempstring[lindex:len(tempstring)], ",", ""); - tempstring = tempstring + "};\n\n"; - - - tempstring = tempstring + retlist[i] + "default_acquire_" + funclist[i] + replace_arch.sub("", arched_arglist[i]) + '\n'; - tempstring = tempstring + " %s = %s_archs[volk_rank_archs(%s_arch_defs, volk_get_lvarch())];\n" % (funclist[i], funclist[i], funclist[i]) - tempstring = tempstring + " %s(%s);\n}\n\n" % (funclist[i], my_arglist[i]) - - tempstring = tempstring + "%s(*%s)(%s) = &default_acquire_%s;\n\n" % (retlist[i], funclist[i], my_argtypelist[i], funclist[i]) - - return tempstring; diff --git a/volk/include/volk/volk_register.py b/volk/include/volk/volk_register.py index 9d33abe89..437fb33b1 100755 --- a/volk/include/volk/volk_register.py +++ b/volk/include/volk/volk_register.py @@ -9,38 +9,29 @@ from make_cpuid_c import make_cpuid_c from make_cpuid_h import make_cpuid_h from make_set_simd import make_set_simd from make_registry import make_registry -from make_h import make_h -from make_init_h import make_init_h from make_config_fixed import make_config_fixed -from make_config_in import make_config_in -from make_c import make_c -from make_runtime_c import make_runtime_c -from make_init_c import make_init_c -from make_runtime import make_runtime from make_typedefs import make_typedefs from make_environment_init_c import make_environment_init_c from make_environment_init_h import make_environment_init_h -from make_mktables import make_mktables from make_makefile_am import make_makefile_am from make_machines_h import make_machines_h from make_machines_c import make_machines_c from make_each_machine_c import make_each_machine_c +from make_c import make_c +from make_h import make_h import copy outfile_set_simd = open("../../config/lv_set_simd_flags.m4", "w"); outfile_reg = open("volk_registry.h", "w"); outfile_h = open("volk.h", "w"); outfile_c = open("../../lib/volk.c", "w"); -outfile_runtime = open("volk_runtime.h", "w"); -outfile_runtime_c = open("../../lib/volk_runtime.c", "w"); outfile_typedefs = open("volk_typedefs.h", "w"); outfile_init_h = open("../../lib/volk_init.h", "w"); -outfile_init_c = open("../../lib/volk_init.c", "w"); outfile_cpu_h = open("volk_cpu.h", "w"); outfile_cpu_c = open("../../lib/volk_cpu.c", "w"); #outfile_config_in = open("../../volk_config.h.in", "w"); outfile_config_fixed = open("volk_config_fixed.h", "w"); -outfile_mktables = open("../../lib/volk_mktables.c", "w"); +#outfile_mktables = open("../../lib/volk_mktables.c", "w"); outfile_environment_c = open("../../lib/volk_environment_init.c", "w"); outfile_environment_h = open("volk_environment_init.h", "w"); outfile_makefile_am = open("../../lib/Makefile.am", "w"); @@ -268,46 +259,16 @@ outfile_cpu_c.close(); outfile_set_simd.write(make_set_simd(filearchs, machines)); outfile_set_simd.close(); - -#outfile_config_in.write(make_config_in(filearchs)); -#outfile_config_in.close(); outfile_reg.write(make_registry(filearchs, functions, fcountlist, taglist)); outfile_reg.close(); -outfile_h.write(make_h(functions, arched_arglist, retlist)); -outfile_h.close(); - -outfile_init_h.write(make_init_h(functions, arched_arglist, retlist)); -outfile_init_h.close(); - outfile_config_fixed.write(make_config_fixed(filearchs)); outfile_config_fixed.close(); -outfile_c.write( make_c(functions, taglist, arched_arglist, retlist, my_arglist, fcountlist)); -outfile_c.close(); - -outfile_runtime_c.write(make_runtime_c(functions, taglist, arched_arglist, retlist, my_arglist, fcountlist, my_argtypelist)); -outfile_runtime_c.close(); - -outfile_init_c.write(make_init_c(functions, filearchs)); -outfile_init_c.close(); - -outfile_runtime.write(make_runtime(functions, my_argtypelist)); -outfile_runtime.close(); - outfile_typedefs.write(make_typedefs(functions, retlist, my_argtypelist)); outfile_typedefs.close(); -outfile_environment_c.write(make_environment_init_c(filearchs)); -outfile_environment_c.close(); - -outfile_environment_h.write(make_environment_init_h()); -outfile_environment_h.close(); - -outfile_mktables.write(make_mktables(functions)); -outfile_mktables.close(); - outfile_makefile_am.write(make_makefile_am(filearchs, machines, archflags_dict)) outfile_makefile_am.close() @@ -317,6 +278,12 @@ outfile_machines_h.close() outfile_machines_c.write(make_machines_c(machines)) outfile_machines_c.close() +outfile_c.write(make_c(machines, archs, functions, arched_arglist, my_arglist)) +outfile_c.close() + +outfile_h.write(make_h(functions)) +outfile_h.close() + for machine in machines: machine_c_filename = "../../lib/volk_machine_" + machine + ".c" outfile_machine_c = open(machine_c_filename, "w") |