summaryrefslogtreecommitdiff
path: root/volk/gen/make_each_machine_c.py
blob: 6d9b8c65fbd6208860b068a30b63249e0b037fe6 (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
#
# 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
# 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

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.
"""
    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_config_fixed.h>

"""
    for func in functions:
        tempstring += "#include <volk/" + func + ".h>\n"
    tempstring += "\n\n"

    #create the volk machine struct for this machine file
    tempstring += "struct volk_machine volk_machine_" + machine_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 += "    {%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"

    return tempstring