Statistics
| Branch: | Tag: | Revision:

root / volk / gen / make_c.py @ 30fdc38d

History | View | Annotate | Download (3.3 kB)

1 8608fc3a Nick Foster
#
2 701b1c52 Josh Blum
# Copyright 2010-2011 Free Software Foundation, Inc.
3 8608fc3a Nick Foster
#
4 8608fc3a Nick Foster
# This program is free software: you can redistribute it and/or modify
5 8608fc3a Nick Foster
# it under the terms of the GNU General Public License as published by
6 8608fc3a Nick Foster
# the Free Software Foundation, either version 3 of the License, or
7 8608fc3a Nick Foster
# (at your option) any later version.
8 8608fc3a Nick Foster
#
9 8608fc3a Nick Foster
# This program is distributed in the hope that it will be useful,
10 8608fc3a Nick Foster
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 8608fc3a Nick Foster
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 8608fc3a Nick Foster
# GNU General Public License for more details.
13 8608fc3a Nick Foster
#
14 8608fc3a Nick Foster
# You should have received a copy of the GNU General Public License
15 8608fc3a Nick Foster
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 8608fc3a Nick Foster
#
17 8608fc3a Nick Foster
18 23914465 Tom Rondeau
from volk_regexp import *
19 8608fc3a Nick Foster
import string
20 23914465 Tom Rondeau
21 8608fc3a Nick Foster
#ok todo list:
22 8608fc3a Nick Foster
#put n_archs into the info struct so it doesn't have to be arch_defs[0].
23 23914465 Tom Rondeau
24 8608fc3a Nick Foster
def make_c(machines, archs, functions, arched_arglist, my_arglist):
25 8608fc3a Nick Foster
    tempstring = r"""
26 8608fc3a Nick Foster
// This file is automatically generated by make_c.py.
27 8608fc3a Nick Foster
// Do not edit this file.
28 8608fc3a Nick Foster
"""
29 8608fc3a Nick Foster
    tempstring += """
30 d59273f3 Nick Foster
#include <volk/volk_common.h>
31 d59273f3 Nick Foster
#include <volk/volk_machines.h>
32 d59273f3 Nick Foster
#include <volk/volk_typedefs.h>
33 d59273f3 Nick Foster
#include <volk/volk_cpu.h>
34 d59273f3 Nick Foster
#include "volk_rank_archs.h"
35 d59273f3 Nick Foster
#include <volk/volk.h>
36 8608fc3a Nick Foster
#include <stdio.h>
37 668da8bd Nick Foster
#include <string.h>
38 8608fc3a Nick Foster
39 8608fc3a Nick Foster
"""
40 5b4c7d27 Josh Blum
41 8608fc3a Nick Foster
#OK here's the deal. the .h prototypes the functions. the .c impls them as fptrs, can use p_whatever.
42 8608fc3a Nick Foster
#also .c impls the get_machine call
43 8608fc3a Nick Foster
#also .c impls the default call for each fn
44 8608fc3a Nick Foster
45 8608fc3a Nick Foster
#here do static fn get arch
46 8608fc3a Nick Foster
    tempstring += r"""
47 8608fc3a Nick Foster
struct volk_machine *get_machine(void) {
48 701b1c52 Josh Blum
    extern struct volk_machine *volk_machines[];
49 8608fc3a Nick Foster
    extern unsigned int n_volk_machines;
50 8608fc3a Nick Foster
    static struct volk_machine *machine = NULL;
51 23914465 Tom Rondeau
    
52 8608fc3a Nick Foster
    if(machine != NULL) return machine;
53 8608fc3a Nick Foster
    else {
54 8608fc3a Nick Foster
        unsigned int max_score = 0;
55 8608fc3a Nick Foster
        int i;
56 8608fc3a Nick Foster
        for(i=0; i<n_volk_machines; i++) {
57 701b1c52 Josh Blum
            if(!(volk_machines[i]->caps & (~volk_get_lvarch()))) {
58 701b1c52 Josh Blum
                if(volk_machines[i]->caps > max_score) {
59 701b1c52 Josh Blum
                    max_score = volk_machines[i]->caps;
60 701b1c52 Josh Blum
                    machine = volk_machines[i];
61 8608fc3a Nick Foster
                }
62 8608fc3a Nick Foster
            }
63 8608fc3a Nick Foster
        }
64 8608fc3a Nick Foster
        printf("Using Volk machine: %s\n", machine->name);
65 8608fc3a Nick Foster
        return machine;
66 8608fc3a Nick Foster
    }
67 8608fc3a Nick Foster
}
68 8608fc3a Nick Foster
69 8608fc3a Nick Foster
"""
70 23914465 Tom Rondeau
    
71 8608fc3a Nick Foster
    for i in range(len(functions)):
72 8608fc3a Nick Foster
        tempstring += "void get_" + functions[i] + replace_arch.sub("", arched_arglist[i]) + "\n"
73 30fdc38d Nick Foster
        tempstring += "    %s = get_machine()->%s_archs[volk_rank_archs(get_machine()->%s_indices, get_machine()->%s_arch_defs, get_machine()->%s_n_archs, get_machine()->%s_name, volk_get_lvarch())];\n" % (functions[i], functions[i], functions[i], functions[i], functions[i], functions[i])
74 8608fc3a Nick Foster
        tempstring += "    %s(%s);\n}\n\n" % (functions[i], my_arglist[i])
75 8608fc3a Nick Foster
        tempstring += replace_volk.sub("p", functions[i]) + " " + functions[i] + " = &get_" + functions[i] + ";\n\n"
76 668da8bd Nick Foster
        tempstring += "void %s_manual%s\n" % (functions[i], arched_arglist[i])
77 f9f3509d Josh Blum
        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])
78 668da8bd Nick Foster
        tempstring += "struct volk_func_desc %s_get_func_desc(void) {\n" % (functions[i])
79 f9f3509d Josh Blum
        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])
80 f9f3509d Josh Blum
        tempstring += "    return desc;\n}\n"
81 8608fc3a Nick Foster
82 8608fc3a Nick Foster
    return tempstring
83 8608fc3a Nick Foster