summaryrefslogtreecommitdiff
path: root/volk/gen/make_each_machine_c.py
blob: 94d6d77894ba1b98cdb5ed2ce045b21de782a43b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# 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_each_machine_c(machine_name, archs, functions, fcountlist, taglist):
    tempstring = r"""
// This file is automatically generated by make_each_machine_c.py.
// Do not edit this file.
"""
    for arch in archs:
        tempstring += "#define LV_HAVE_" + arch.swapcase() + " 1\n"
    
    tempstring += """
#include <volk/volk_common.h>
#include <volk/volk_machines.h>
#include <volk/volk_registry.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"
    tempstring += "struct volk_machine volk_machine_" + machine_name + " = {\n"
    tempstring += "    caps,\n"
    tempstring += "    name,\n"
    
    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 = strip_trailing(tempstring, ",")
    tempstring += "};\n"
    tempstring += emit_epilog();

    return tempstring