summaryrefslogtreecommitdiff
path: root/volk/gen
diff options
context:
space:
mode:
authorJosh Blum2011-05-06 11:01:57 -0700
committerJosh Blum2011-05-06 11:01:57 -0700
commitf9f3509dabe429953afc30ca7672b167dc4b5523 (patch)
tree74a86c099aadfeb089a126294a9b874be36d40c2 /volk/gen
parent701b1c520865388a4287c6a3f63afb3ce2626cf1 (diff)
downloadgnuradio-f9f3509dabe429953afc30ca7672b167dc4b5523.tar.gz
gnuradio-f9f3509dabe429953afc30ca7672b167dc4b5523.tar.bz2
gnuradio-f9f3509dabe429953afc30ca7672b167dc4b5523.zip
volk: make volk_machine_xxx.cc c-safe
Initialize each machine struct using C constants, (rather than relying on C++ to copy objects). Each machine file is far simpler, because we know what archs are in a machine, we can generate exactly the right code. In addition, rename the file extensions to .c so we know its C only.
Diffstat (limited to 'volk/gen')
-rw-r--r--volk/gen/make_c.py7
-rw-r--r--volk/gen/make_each_machine_c.py61
-rw-r--r--volk/gen/make_machines_h.py8
-rw-r--r--volk/gen/make_makefile_am.py2
-rw-r--r--volk/gen/volk_register.py4
5 files changed, 38 insertions, 44 deletions
diff --git a/volk/gen/make_c.py b/volk/gen/make_c.py
index 5bad910ae..65c42d89a 100644
--- a/volk/gen/make_c.py
+++ b/volk/gen/make_c.py
@@ -85,13 +85,14 @@ static unsigned int get_index(const char *indices[], unsigned int n_archs, const
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, get_machine()->%s_desc.n_archs, volk_get_lvarch())];\n" % (functions[i], functions[i], functions[i], functions[i])
+ tempstring += " %s = get_machine()->%s_archs[volk_rank_archs(get_machine()->%s_arch_defs, get_machine()->%s_n_archs, volk_get_lvarch())];\n" % (functions[i], 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 += "void %s_manual%s\n" % (functions[i], arched_arglist[i])
- tempstring += " get_machine()->%s_archs[get_index(get_machine()->%s_desc.indices, get_machine()->%s_desc.n_archs, arch)](%s);\n}\n" % (functions[i], functions[i], functions[i], my_arglist[i])
+ tempstring += " get_machine()->%s_archs[get_index(get_machine()->%s_indices, get_machine()->%s_n_archs, arch)](%s);\n}\n" % (functions[i], functions[i], functions[i], my_arglist[i])
tempstring += "struct volk_func_desc %s_get_func_desc(void) {\n" % (functions[i])
- tempstring += " return get_machine()->%s_desc;\n}\n" % (functions[i])
+ tempstring += " struct volk_func_desc desc = {get_machine()->%s_indices, get_machine()->%s_arch_defs, get_machine()->%s_n_archs};\n" % (functions[i], functions[i], functions[i])
+ tempstring += " return desc;\n}\n"
tempstring += emit_epilog();
diff --git a/volk/gen/make_each_machine_c.py b/volk/gen/make_each_machine_c.py
index 94d6d7789..4e6684745 100644
--- a/volk/gen/make_each_machine_c.py
+++ b/volk/gen/make_each_machine_c.py
@@ -1,5 +1,5 @@
#
-# Copyright 2010 Free Software Foundation, Inc.
+# Copyright 2010-2011 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
@@ -19,10 +19,21 @@ 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_each_machine_c(machine_name, archs, functions, fcountlist, taglist):
+
+ #make the machine fcountlist and taglist a subset given the archs list
+ machine_fcountlists = list()
+ machine_taglists = list()
+ for i in range(len(fcountlist)):
+ machine_fcountlist = list()
+ machine_taglist = list()
+ for j in range(len(fcountlist[i])):
+ if len(set(archs).intersection(map(str.lower, fcountlist[i][j]))) == len(fcountlist[i][j]):
+ machine_fcountlist.append(fcountlist[i][j])
+ machine_taglist.append(taglist[i][j])
+ machine_fcountlists.append(machine_fcountlist)
+ machine_taglists.append(machine_taglist)
+
tempstring = r"""
// This file is automatically generated by make_each_machine_c.py.
// Do not edit this file.
@@ -33,46 +44,26 @@ def make_each_machine_c(machine_name, archs, functions, fcountlist, taglist):
tempstring += """
#include <volk/volk_common.h>
#include <volk/volk_machines.h>
-#include <volk/volk_registry.h>
+#include <volk/volk_config_fixed.h>
"""
tempstring += emit_prolog();
for func in functions:
tempstring += "#include <volk/" + func + ".h>\n"
tempstring += "\n\n"
-
- for i in range(len(functions)):
- tempstring += "static const " + replace_volk.sub("p", functions[i]) + " " + functions[i] + "_archs[] = {\n"
-
- tags_counter = 0
- for arch_list in fcountlist[i]:
- tempstring += "#if "
- for arch in arch_list:
- tempstring += "defined(LV_HAVE_" + arch + ") && "
- tempstring = strip_trailing(tempstring, " && ")
- tempstring += "\n " + functions[i] + "_" + str(taglist[i][tags_counter]) + ",\n"
- tempstring += "#endif\n"
- tags_counter += 1
- tempstring = strip_trailing(tempstring, ",")
- tempstring += "};\n\n"
-
-
- tempstring += "static unsigned int caps = "
- for arch in archs:
- tempstring += "(1 << LV_" + arch.swapcase() + ") + "
- tempstring = strip_trailing(tempstring, " + ")
- tempstring += ";\n"
-
- tempstring += "static const char* name = \"" + machine_name + "\";\n"
+ #create the volk machine struct for this machine file
tempstring += "struct volk_machine volk_machine_" + machine_name + " = {\n"
- tempstring += " caps,\n"
- tempstring += " name,\n"
-
+ tempstring += " " + ' | '.join(["(1 << LV_" + arch.swapcase() + ")" for arch in archs]) + ",\n"
+ tempstring += " \"%s\",\n"%machine_name
+
+ #fill in the description for each function
for i in range(len(functions)):
- tempstring += " { " + functions[i] + "_indices, " + functions[i] + "_arch_defs, " + functions[i] + "_n_archs },\n"
- tempstring += " " + functions[i] + "_archs,\n"
-
+ tempstring += " {%s},\n"%(', '.join(['"%s"'%tag for tag in machine_taglists[i]]))
+ tempstring += " {%s},\n"%(', '.join([' | '.join(['(1 << LV_%s)'%fc for fc in fcount]) for fcount in machine_fcountlists[i]]))
+ tempstring += " {%s},\n"%(', '.join(['%s_%s'%(functions[i], tag) for tag in machine_taglists[i]]))
+ tempstring += " %d,\n"%len(machine_taglists[i])
+
tempstring = strip_trailing(tempstring, ",")
tempstring += "};\n"
tempstring += emit_epilog();
diff --git a/volk/gen/make_machines_h.py b/volk/gen/make_machines_h.py
index 082ca1488..aa6daa6cc 100644
--- a/volk/gen/make_machines_h.py
+++ b/volk/gen/make_machines_h.py
@@ -17,7 +17,7 @@
from volk_regexp import *
-def make_machines_h(functions, machines):
+def make_machines_h(functions, machines, archs):
tempstring = r"""
// This file is automatically generated by make_machines_h.py.
// Do not edit this file.
@@ -33,8 +33,10 @@ struct volk_machine {
const char *name;
"""
for function in functions:
- tempstring += "\n const struct volk_func_desc " + function + "_desc;\n"
- tempstring += " const " + replace_volk.sub("p", function) + " *" + function + "_archs;\n"
+ tempstring += " const char *%s_indices[%d];\n"%(function, len(archs))
+ tempstring += " const int %s_arch_defs[%d];\n"%(function, len(archs))
+ tempstring += " const %s %s_archs[%d];\n"%(replace_volk.sub("p", function), function, len(archs))
+ tempstring += " const int %s_n_archs;\n"%function
tempstring += r"""};
diff --git a/volk/gen/make_makefile_am.py b/volk/gen/make_makefile_am.py
index 929b6075d..54017d2b3 100644
--- a/volk/gen/make_makefile_am.py
+++ b/volk/gen/make_makefile_am.py
@@ -69,7 +69,7 @@ noinst_LTLIBRARIES =
#here be dragons
for machine_name in machines:
tempstring += "if LV_MACHINE_" + machine_name.swapcase() + "\n"
- tempstring += "libvolk_" + machine_name + "_la_SOURCES = $(top_gendir)/lib/volk_machine_" + machine_name + ".cc\n"
+ tempstring += "libvolk_" + machine_name + "_la_SOURCES = $(top_gendir)/lib/volk_machine_" + machine_name + ".c\n"
tempstring += "libvolk_" + machine_name + "_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_gendir)/include $(volk_orc_CFLAGS) "
for arch in machines[machine_name]:
if archflags_dict[arch] != "none":
diff --git a/volk/gen/volk_register.py b/volk/gen/volk_register.py
index aae32c705..f67a8d17e 100644
--- a/volk/gen/volk_register.py
+++ b/volk/gen/volk_register.py
@@ -286,7 +286,7 @@ outfile_typedefs.close();
outfile_makefile_am.write(make_makefile_am(filearchs, machines, archflags_dict))
outfile_makefile_am.close()
-outfile_machines_h.write(make_machines_h(functions, machines))
+outfile_machines_h.write(make_machines_h(functions, machines, archs))
outfile_machines_h.close()
outfile_machines_c.write(make_machines_c(machines))
@@ -299,7 +299,7 @@ outfile_h.write(make_h(functions, arched_arglist))
outfile_h.close()
for machine in machines:
- machine_c_filename = os.path.join(gendir, "lib/volk_machine_" + machine + ".cc")
+ machine_c_filename = os.path.join(gendir, "lib/volk_machine_" + machine + ".c")
outfile_machine_c = open(machine_c_filename, "w")
outfile_machine_c.write(make_each_machine_c(machine, machines[machine], functions, fcountlist, taglist))
outfile_machine_c.close()