summaryrefslogtreecommitdiff
path: root/volk/gen/make_each_machine_c.py
blob: 535578859aabab8f3135d789bcf3b9e762be27b3 (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
83
84
85
86
87
88
89
90
#
# 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_struct(machine_name, archs, functions, fcountlist, taglist, alignment):

    #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)

    #create the volk machine struct for this machine file
    tempstring = ""
    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
    tempstring += "    %s,\n"%alignment

    #fill in the description for each function
    for i in range(len(functions)):
        tempstring += "    \"%s\",\n"%functions[i]
        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

def make_each_machine_c(machine_name, archs, functions, fcountlist, taglist, alignment):
    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_machines.h"
#include <volk/volk_config_fixed.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

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

    tempstring += """
#ifdef LV_HAVE_ORC
%s
#else
%s
#endif
"""%(
    _make_each_machine_struct(machine_name, archs+["orc"], functions, fcountlist, taglist, alignment),
    _make_each_machine_struct(machine_name, archs, functions, fcountlist, taglist, alignment)
)

    return tempstring