diff options
Diffstat (limited to 'volk/gen')
-rw-r--r-- | volk/gen/archs.xml | 230 | ||||
-rw-r--r-- | volk/gen/compilers.xml | 30 | ||||
-rw-r--r-- | volk/gen/machines.xml | 39 | ||||
-rw-r--r-- | volk/gen/make_c.py | 88 | ||||
-rw-r--r-- | volk/gen/make_config_fixed.py | 21 | ||||
-rw-r--r-- | volk/gen/make_config_in.py | 13 | ||||
-rw-r--r-- | volk/gen/make_cpuid_c.py | 283 | ||||
-rw-r--r-- | volk/gen/make_cpuid_h.py | 48 | ||||
-rw-r--r-- | volk/gen/make_each_machine_c.py | 90 | ||||
-rw-r--r-- | volk/gen/make_environment_init_c.py | 32 | ||||
-rw-r--r-- | volk/gen/make_environment_init_h.py | 18 | ||||
-rw-r--r-- | volk/gen/make_h.py | 38 | ||||
-rw-r--r-- | volk/gen/make_machines_c.py | 41 | ||||
-rw-r--r-- | volk/gen/make_machines_h.py | 59 | ||||
-rw-r--r-- | volk/gen/make_makefile_am.py | 123 | ||||
-rw-r--r-- | volk/gen/make_proccpu_sim.py | 47 | ||||
-rw-r--r-- | volk/gen/make_set_simd.py | 166 | ||||
-rw-r--r-- | volk/gen/make_typedefs.py | 23 | ||||
-rw-r--r-- | volk/gen/volk_arch_defs.py | 92 | ||||
-rw-r--r-- | volk/gen/volk_compile_utils.py | 58 | ||||
-rw-r--r-- | volk/gen/volk_kernel_defs.py | 224 | ||||
-rw-r--r-- | volk/gen/volk_machine_defs.py | 78 | ||||
-rw-r--r-- | volk/gen/volk_regexp.py | 13 | ||||
-rw-r--r-- | volk/gen/volk_register.py | 303 | ||||
-rw-r--r-- | volk/gen/volk_tmpl_utils.py | 74 |
25 files changed, 668 insertions, 1563 deletions
diff --git a/volk/gen/archs.xml b/volk/gen/archs.xml index 59cc81cc5..2c9ab41a5 100644 --- a/volk/gen/archs.xml +++ b/volk/gen/archs.xml @@ -1,155 +1,183 @@ <!-- archs appear in order of significance for blind, de-facto version ordering --> <grammar> -<arch name="generic" type="all"> <!-- name and type are both required--> - <flag>none</flag> <!-- flag is the only required field--> +<arch name="generic"> <!-- name is required--> </arch> -<arch name="altivec" type="powerpc"> - <flag>maltivec</flag> +<arch name="altivec"> + <flag compiler="gnu">-maltivec</flag> <alignment>16</alignment> + <check name="has_ppc"></check> </arch> -<arch name="neon" type="arm"> - <flag>mfpu=neon,mfloat-abi=softfp,funsafe-math-optimizations</flag> +<arch name="neon"> + <flag compiler="gnu">-mfpu=neon</flag> + <flag compiler="gnu">-mfloat-abi=softfp</flag> + <flag compiler="gnu">-funsafe-math-optimizations</flag> <alignment>16</alignment> + <check name="has_neon"></check> </arch> -<arch name="32" type="x86" no_test="true" > - <flag>m32</flag> - <overrule>MD_SUBCPU</overrule> - <overrule_val>x86_64</overrule_val> +<arch name="32"> + <flag compiler="gnu">-m32</flag> </arch> -<arch name="64" type="x86"> - <op>0x80000001</op> - <reg>d</reg> - <shift>29</shift> - <flag>m64</flag> - <val>1</val> - <overrule>MD_SUBCPU</overrule> - <overrule_val>x86</overrule_val> +<arch name="64"> + <check name="check_extended_cpuid"> + <param>0x80000001</param> + </check> + <check name="cpuid_x86_bit"> <!-- checks to see if a bit is set --> + <param>3</param> <!-- eax, ebx, ecx, [edx] --> + <param>0x80000001</param> <!-- cpuid operation --> + <param>29</param> <!-- bit shift --> + </check> + <flag compiler="gnu">-m64</flag> </arch> -<arch name="3dnow" type="x86"> - <op>0x80000001</op> - <reg>d</reg> - <shift>31</shift> - <flag>m3dnow</flag> - <val>1</val> +<arch name="3dnow"> + <check name="cpuid_x86_bit"> + <param>3</param> + <param>0x80000001</param> + <param>31</param> + </check> + <flag compiler="gnu">-m3dnow</flag> <alignment>8</alignment> </arch> -<arch name="abm" type="x86"> - <val>1</val> - <op>0x80000001</op> - <reg>d</reg> - <shift>5</shift> - <flag>msse4.2</flag> +<arch name="abm"> + <check name="cpuid_x86_bit"> + <param>3</param> + <param>0x80000001</param> + <param>5</param> + </check> + <flag compiler="gnu">-msse4.2</flag> <alignment>16</alignment> </arch> -<arch name="popcount" type="x86"> - <val>1</val> - <op>1</op> - <reg>c</reg> - <shift>23</shift> - <flag>mpopcnt</flag> -</arch> - -<arch name="mmx" type="x86"> - <val>1</val> - <op>1</op> - <reg>d</reg> - <shift>23</shift> - <flag>mmmx</flag> +<arch name="popcount"> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x00000001</param> + <param>23</param> + </check> + <flag compiler="gnu">-mpopcnt</flag> + <flag compiler="msvc">/arch:AVX</flag> +</arch> + +<arch name="mmx"> + <check name="cpuid_x86_bit"> + <param>3</param> + <param>0x00000001</param> + <param>23</param> + </check> + <flag compiler="gnu">-mmmx</flag> + <flag compiler="msvc">/arch:SSE</flag> <alignment>8</alignment> </arch> - -<arch name="sse" type="x86"> - <val>1</val> - <op>1</op> - <reg>d</reg> - <shift>25</shift> - <flag>msse</flag> +<arch name="sse"> + <check name="cpuid_x86_bit"> + <param>3</param> + <param>0x00000001</param> + <param>25</param> + </check> + <flag compiler="gnu">-msse</flag> + <flag compiler="msvc">/arch:SSE</flag> <environment>_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);</environment> <include>xmmintrin.h</include> <alignment>16</alignment> </arch> - -<arch name="sse2" type="x86"> - <val>1</val> - <op>1</op> - <reg>d</reg> - <shift>26</shift> - <flag>msse2</flag> +<arch name="sse2"> + <check name="cpuid_x86_bit"> + <param>3</param> + <param>0x00000001</param> + <param>26</param> + </check> + <flag compiler="gnu">-msse2</flag> + <flag compiler="msvc">/arch:SSE2</flag> <alignment>16</alignment> </arch> -<arch name="orc" type="all"> - <flag>lorc-0.4</flag> - <overrule>LV_HAVE_ORC</overrule> - <overrule_val>no</overrule_val> +<arch name="orc"> </arch> -<arch name="sse3" type="x86"> - <val>1</val> - <op>1</op> - <reg>c</reg> - <shift>0</shift> - <flag>msse3</flag> +<!-- it's here for overrule stuff. --> +<arch name="norc"> +</arch> + +<arch name="sse3"> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x00000001</param> + <param>0</param> + </check> + <flag compiler="gnu">-msse3</flag> + <flag compiler="msvc">/arch:AVX</flag> <environment>_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);</environment> <include>pmmintrin.h</include> <alignment>16</alignment> </arch> -<arch name="ssse3" type="x86"> - <val>1</val> - <op>1</op> - <reg>c</reg> - <shift>9</shift> - <flag>mssse3</flag> +<arch name="ssse3"> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x00000001</param> + <param>9</param> + </check> + <flag compiler="gnu">-mssse3</flag> + <flag compiler="msvc">/arch:AVX</flag> <alignment>16</alignment> </arch> -<arch name="sse4_a" type="x86"> - <val>1</val> - <op>0x80000001</op> - <reg>c</reg> - <shift>6</shift> - <flag>msse4a</flag> +<arch name="sse4_a"> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x80000001</param> + <param>6</param> + </check> + <flag compiler="gnu">-msse4a</flag> <alignment>16</alignment> </arch> - -<arch name="sse4_1" type="x86"> - <val>1</val> - <op>1</op> - <reg>c</reg> - <shift>19</shift> - <flag>msse4.1</flag> +<arch name="sse4_1"> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x00000001</param> + <param>19</param> + </check> + <flag compiler="gnu">-msse4.1</flag> + <flag compiler="msvc">/arch:AVX</flag> <alignment>16</alignment> </arch> -<arch name="sse4_2" type="x86"> - <val>1</val> - <op>1</op> - <reg>c</reg> - <shift>20</shift> - <flag>msse4.2</flag> +<arch name="sse4_2"> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x00000001</param> + <param>20</param> + </check> + <flag compiler="gnu">-msse4.2</flag> + <flag compiler="msvc">/arch:AVX</flag> <alignment>16</alignment> </arch> -<arch name="avx" type="x86"> - <val>1</val> - <op>1</op> - <reg>c</reg> - <shift>28</shift> - <flag>mavx</flag> - <check>xgetbv</check> - <checkval>7</checkval> +<arch name="avx"> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x00000001</param> + <param>28</param> + </check> + <!-- check to make sure that xgetbv is enabled in OS --> + <check name="cpuid_x86_bit"> + <param>2</param> + <param>0x00000001</param> + <param>27</param> + </check> + <!-- check to see that the OS has enabled AVX --> + <check name="get_avx_enabled"></check> + <flag compiler="gnu">-mavx</flag> + <flag compiler="msvc">/arch:AVX</flag> <alignment>32</alignment> </arch> diff --git a/volk/gen/compilers.xml b/volk/gen/compilers.xml deleted file mode 100644 index 005eda2aa..000000000 --- a/volk/gen/compilers.xml +++ /dev/null @@ -1,30 +0,0 @@ -<!-- compilers remap gcc-specific information from archs.xml to specific compiler cases--> -<grammar> - -<compiler name="MSVC"> - <!-- remap the following flags to SSE --> - <remap name="mmmx">arch:SSE</remap> - <remap name="msse">arch:SSE</remap> - - <!-- remap the following flags to SSE2 --> - <remap name="msse2">arch:SSE2</remap> - - <!-- remap the following flags to AVX --> - <remap name="msse3">arch:AVX</remap> - <remap name="mssse3">arch:AVX</remap> - <remap name="msse4.1">arch:AVX</remap> - <remap name="msse4.2">arch:AVX</remap> - <remap name="mpopcnt">arch:AVX</remap> - <remap name="mavx">arch:AVX</remap> - - <prefix>/</prefix> -</compiler> - -<compiler name="GNU"> - <prefix>-</prefix> -</compiler> - - - - -</grammar> diff --git a/volk/gen/machines.xml b/volk/gen/machines.xml index 9c19c91c6..8e3c9c8c2 100644 --- a/volk/gen/machines.xml +++ b/volk/gen/machines.xml @@ -1,64 +1,51 @@ <grammar> <machine name="generic"> -<archs>generic</archs> +<archs>generic orc|</archs> </machine> <!-- <machine name="mmx"> -<archs>generic 32|64 mmx</archs> +<archs>generic 32|64 mmx orc|</archs> </machine> <machine name="sse"> -<archs>generic 32|64 mmx sse</archs> +<archs>generic 32|64| mmx sse orc|</archs> </machine> --> -<!-- -Create an SSE2 and AVX only machine (without 64/32 inline assembly support). -This machine is intended to support the MSVC compiler on x86/amd64. -The MSVC compiler has intrinsic support for SSE, SSE2, AVX -however it does not support the gcc style inline assembly. ---> - <machine name="neon"> -<archs>generic neon</archs> -</machine> - -<machine name="sse2_only"> -<archs>generic mmx sse sse2</archs> +<archs>generic neon orc|</archs> </machine> +<!-- trailing | bar means generate without either for MSVC --> <machine name="sse2"> -<archs>generic 32|64 mmx sse sse2</archs> +<archs>generic 32|64| mmx sse sse2 orc|</archs> </machine> <machine name="sse3"> -<archs>generic 32|64 mmx sse sse2 sse3</archs> +<archs>generic 32|64 mmx sse sse2 sse3 orc|</archs> </machine> <machine name="ssse3"> -<archs>generic 32|64 mmx sse sse2 sse3 ssse3</archs> +<archs>generic 32|64 mmx sse sse2 sse3 ssse3 orc|</archs> </machine> <machine name="sse4_a"> -<archs>generic 32|64 mmx sse sse2 sse3 sse4_a popcount</archs> +<archs>generic 32|64 mmx sse sse2 sse3 sse4_a popcount orc|</archs> </machine> <machine name="sse4_1"> -<archs>generic 32|64 mmx sse sse2 sse3 ssse3 sse4_1</archs> +<archs>generic 32|64 mmx sse sse2 sse3 ssse3 sse4_1 orc|</archs> </machine> <machine name="sse4_2"> -<archs>generic 32|64 mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 popcount</archs> +<archs>generic 32|64 mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 popcount orc|</archs> </machine> +<!-- trailing | bar means generate without either for MSVC --> <machine name="avx"> -<archs>generic 32|64 mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 popcount avx</archs> -</machine> - -<machine name="avx_only"> -<archs>generic mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 popcount avx</archs> +<archs>generic 32|64| mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 popcount avx orc|</archs> </machine> <machine name="altivec"> diff --git a/volk/gen/make_c.py b/volk/gen/make_c.py deleted file mode 100644 index 233cb85c2..000000000 --- a/volk/gen/make_c.py +++ /dev/null @@ -1,88 +0,0 @@ -# -# 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 - -#ok todo list: -#put n_archs into the info struct so it doesn't have to be arch_defs[0]. - -def make_c(machines, archs, functions, arched_arglist, my_arglist): - tempstring = r""" -// This file is automatically generated by make_c.py. -// Do not edit this file. -""" - tempstring += """ -#include <volk/volk_common.h> -#include "volk_machines.h" -#include <volk/volk_typedefs.h> -#include <volk/volk_cpu.h> -#include "volk_rank_archs.h" -#include <volk/volk.h> -#include <stdio.h> -#include <string.h> - -""" - -#OK here's the deal. the .h prototypes the functions. the .c impls them as fptrs, can use p_whatever. -#also .c impls the get_machine call -#also .c impls the default call for each fn - -#here do static fn get arch - tempstring += r""" -struct volk_machine *get_machine(void) { - extern struct volk_machine *volk_machines[]; - extern unsigned int n_volk_machines; - static struct volk_machine *machine = NULL; - - if(machine != NULL) return machine; - else { - unsigned int max_score = 0; - unsigned int i; - for(i=0; i<n_volk_machines; i++) { - if(!(volk_machines[i]->caps & (~volk_get_lvarch()))) { - if(volk_machines[i]->caps > max_score) { - max_score = volk_machines[i]->caps; - machine = volk_machines[i]; - } - } - } - printf("Using Volk machine: %s\n", machine->name); - return machine; - } -} - -unsigned int volk_get_alignment(void) { - return get_machine()->alignment; -} - -""" - - 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_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]) - 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_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 += " 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" - - return tempstring - - diff --git a/volk/gen/make_config_fixed.py b/volk/gen/make_config_fixed.py deleted file mode 100644 index 96f20b6b2..000000000 --- a/volk/gen/make_config_fixed.py +++ /dev/null @@ -1,21 +0,0 @@ -from xml.dom import minidom - -def make_config_fixed(dom) : - tempstring = ""; - tempstring = tempstring +'/*this file is auto generated by volk_register.py*/'; - tempstring = tempstring + '\n#ifndef INCLUDED_VOLK_CONFIG_FIXED_H'; - tempstring = tempstring + '\n#define INCLUDED_VOLK_CONFIG_FIXED_H'; - tempstring = tempstring + '\n\n'; - enum_counter = 0; - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + '#define LV_' + arch.swapcase() + " " + str(enum_counter) + '\n'; - enum_counter = enum_counter + 1; - tempstring = tempstring + '\n\n'; - - tempstring = tempstring + "#endif /*INCLUDED_VOLK_CONFIG_FIXED*/\n" - - return tempstring; - - - diff --git a/volk/gen/make_config_in.py b/volk/gen/make_config_in.py deleted file mode 100644 index d29680af2..000000000 --- a/volk/gen/make_config_in.py +++ /dev/null @@ -1,13 +0,0 @@ -from xml.dom import minidom - -def make_config_in(dom) : - tempstring = ""; - tempstring = tempstring +'/*this file is auto generated by volk_register.py*/'; - tempstring = tempstring + '\n\n'; - - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + '#undef LV_HAVE_' + arch.swapcase() + '\n'; - tempstring = tempstring + '\n'; - - return tempstring diff --git a/volk/gen/make_cpuid_c.py b/volk/gen/make_cpuid_c.py deleted file mode 100644 index 005fc2b19..000000000 --- a/volk/gen/make_cpuid_c.py +++ /dev/null @@ -1,283 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2011 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from xml.dom import minidom - -HEADER_TEMPL = """\ -/*this file is auto_generated by volk_register.py*/ - -#include <volk/volk_cpu.h> -#include <volk/volk_config_fixed.h> - -struct VOLK_CPU volk_cpu; - -#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64) -# define VOLK_CPU_x86 -#endif - -#if defined(VOLK_CPU_x86) - -//implement get cpuid for gcc compilers using a copy of cpuid.h -#if defined(__GNUC__) -#include <gcc_x86_cpuid.h> -#define cpuid_x86(op, r) __get_cpuid(op, (unsigned int *)r+0, (unsigned int *)r+1, (unsigned int *)r+2, (unsigned int *)r+3) - - /* Return Intel AVX extended CPU capabilities register. - * This function will bomb on non-AVX-capable machines, so - * check for AVX capability before executing. - */ - #if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 - static inline unsigned long long _xgetbv(unsigned int index){ - unsigned int eax, edx; - __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); - return ((unsigned long long)edx << 32) | eax; - } - #define __xgetbv() _xgetbv(0) - #else - #define __xgetbv() 0 - #endif - -//implement get cpuid for MSVC compilers using __cpuid intrinsic -#elif defined(_MSC_VER) -#include <intrin.h> -#define cpuid_x86(op, r) __cpuid(r, op) - - #if defined(_XCR_XFEATURE_ENABLED_MASK) - #define __xgetbv() _xgetbv(_XCR_XFEATURE_ENABLED_MASK) - #else - #define __xgetbv() 0 - #endif - -#else -#error "A get cpuid for volk is not available on this compiler..." -#endif - -static inline unsigned int cpuid_eax(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[0]; -} - -static inline unsigned int cpuid_ebx(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[1]; -} - -static inline unsigned int cpuid_ecx(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[2]; -} - -static inline unsigned int cpuid_edx(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[3]; -} - -static inline unsigned int xgetbv(void) { - //check to make sure that xgetbv is enabled in OS - int xgetbv_enabled = cpuid_ecx(1) >> 27 & 0x01; - if(xgetbv_enabled == 0) return 0; - return __xgetbv(); -} -#endif - -""" - -def make_cpuid_c(dom) : - tempstring = HEADER_TEMPL; - - for domarch in dom: - if str(domarch.attributes["type"].value) == "x86": - if "no_test" in domarch.attributes.keys(): - no_test = str(domarch.attributes["no_test"].value); - if no_test == "true": - no_test = True; - else: - no_test = False; - else: - no_test = False; - arch = str(domarch.attributes["name"].value) - op = domarch.getElementsByTagName("op") - if op: - op = str(op[0].firstChild.data) - reg = domarch.getElementsByTagName("reg") - if reg: - reg = str(reg[0].firstChild.data) - shift = domarch.getElementsByTagName("shift") - if shift: - shift = str(shift[0].firstChild.data) - val = domarch.getElementsByTagName("val") - if val: - val = str(val[0].firstChild.data) - check = domarch.getElementsByTagName("check") - if check: - check = str(check[0].firstChild.data) - checkval = domarch.getElementsByTagName("checkval") - if checkval: - checkval = str(checkval[0].firstChild.data) - - if no_test: - tempstring = tempstring + """\ -int i_can_has_%s () { -#if defined(VOLK_CPU_x86) - return 1; -#else - return 0; -#endif -} - -""" % (arch) - - elif op == "1": - tempstring = tempstring + """\ -int i_can_has_%s () { -#if defined(VOLK_CPU_x86) - unsigned int e%sx = cpuid_e%sx (%s); - int hwcap = (((e%sx >> %s) & 1) == %s); -""" % (arch, reg, reg, op, reg, shift, val) - - if check and checkval: - tempstring += """\ - if (hwcap == 0) return 0; - hwcap &= (%s() == %s); -""" % (check, checkval) - - tempstring += """\ - return hwcap; -#else - return 0; -#endif -} - -""" - - elif op == "0x80000001": - tempstring = tempstring + """\ -int i_can_has_%s () { -#if defined(VOLK_CPU_x86) - unsigned int extended_fct_count = cpuid_eax(0x80000000); - if (extended_fct_count < 0x80000001) - return %s^1; - unsigned int extended_features = cpuid_e%sx (%s); - return ((extended_features >> %s) & 1) == %s; -#else - return 0; -#endif -} - -""" % (arch, val, reg, op, shift, val) - - elif str(domarch.attributes["type"].value) == "powerpc": - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + """\ -int i_can_has_%s () { -#ifdef __PPC__ - return 1; -#else - return 0; -#endif -} - -""" % (arch) - - elif str(domarch.attributes["type"].value) == "arm": - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + """\ -#if defined(__arm__) && defined(__linux__) -#include <asm/hwcap.h> -#include <linux/auxvec.h> -#include <stdio.h> -#define LOOK_FOR_NEON -#endif - -int i_can_has_%s () { -//it's linux-specific, but if you're compiling libvolk for NEON -//on Windows you have other problems - -#ifdef LOOK_FOR_NEON - FILE *auxvec_f; - unsigned long auxvec[2]; - unsigned int found_neon = 0; - auxvec_f = fopen("/proc/self/auxv", "rb"); - if(!auxvec_f) return 0; - - //so auxv is basically 32b of ID and 32b of value - //so it goes like this - while(!found_neon && auxvec_f) { - fread(auxvec, sizeof(unsigned long), 2, auxvec_f); - if((auxvec[0] == AT_HWCAP) && (auxvec[1] & HWCAP_NEON)) - found_neon = 1; - } - - fclose(auxvec_f); - return found_neon; - -#else - return 0; -#endif -} - -""" % (arch) - - elif str(domarch.attributes["type"].value) == "all": - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + """\ -int i_can_has_%s () { - return 1; -} - -""" % (arch) - else: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + """\ -int i_can_has_%s () { - return 0; -} - -""" % (arch) - - tempstring = tempstring + "void volk_cpu_init() {\n"; - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + " volk_cpu.has_" + arch + " = &i_can_has_" + arch + ";\n" - tempstring = tempstring + "}\n\n" - - tempstring = tempstring + "unsigned int volk_get_lvarch() {\n"; - tempstring = tempstring + " unsigned int retval = 0;\n" - tempstring = tempstring + " volk_cpu_init();\n" - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + " retval += volk_cpu.has_" + arch + "() << LV_" + arch.swapcase() + ";\n" - tempstring = tempstring + " return retval;\n" - tempstring = tempstring + "}\n\n" - - return tempstring; - - - - - - - diff --git a/volk/gen/make_cpuid_h.py b/volk/gen/make_cpuid_h.py deleted file mode 100644 index 1aa783781..000000000 --- a/volk/gen/make_cpuid_h.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2011 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from xml.dom import minidom - -def make_cpuid_h(dom) : - tempstring = ""; - tempstring = tempstring +'/*this file is auto generated by volk_register.py*/'; - tempstring = tempstring +'\n#ifndef INCLUDED_VOLK_CPU_H'; - tempstring = tempstring +'\n#define INCLUDED_VOLK_CPU_H\n\n'; - tempstring = tempstring + "#include <volk/volk_common.h>\n\n"; - tempstring = tempstring + '__VOLK_DECL_BEGIN\n'; - tempstring = tempstring + '\n' - - tempstring = tempstring + "struct VOLK_CPU {\n" - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + " int (*has_" + arch + ") ();\n"; - tempstring = tempstring + "};\n\n"; - tempstring = tempstring + "extern struct VOLK_CPU volk_cpu;\n\n"; - - tempstring = tempstring + "void volk_cpu_init ();\n" - tempstring = tempstring + "unsigned int volk_get_lvarch ();\n" - - tempstring = tempstring + "\n"; - tempstring = tempstring + "__VOLK_DECL_END\n"; - tempstring = tempstring + "#endif /*INCLUDED_VOLK_CPU_H*/\n" - - return tempstring; diff --git a/volk/gen/make_each_machine_c.py b/volk/gen/make_each_machine_c.py deleted file mode 100644 index 535578859..000000000 --- a/volk/gen/make_each_machine_c.py +++ /dev/null @@ -1,90 +0,0 @@ -# -# 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 - - diff --git a/volk/gen/make_environment_init_c.py b/volk/gen/make_environment_init_c.py deleted file mode 100644 index 6186162ee..000000000 --- a/volk/gen/make_environment_init_c.py +++ /dev/null @@ -1,32 +0,0 @@ -from xml.dom import minidom - -def make_environment_init_c(dom) : - tempstring = ""; - tempstring = tempstring + "/*this file is auto_generated by volk_register.py*/\n\n"; - tempstring = tempstring + "#include<volk/volk_environment_init.h>\n" - for domarch in dom: - arch = str(domarch.attributes["name"].value); - incs = domarch.getElementsByTagName("include"); - for inc in incs: - my_inc = str(inc.firstChild.data); - tempstring = tempstring + "#ifdef LV_HAVE_" + arch.swapcase() + "\n"; - tempstring = tempstring + "#include<" + my_inc + ">\n"; - tempstring = tempstring + "#endif\n" - tempstring = tempstring + '\n\n'; - tempstring = tempstring + "void volk_environment_init(){\n" - - for domarch in dom: - arch = str(domarch.attributes["name"].value); - envs = domarch.getElementsByTagName("environment"); - for env in envs: - cmd = str(env.firstChild.data); - tempstring = tempstring + "#ifdef LV_HAVE_" + arch.swapcase() + "\n"; - tempstring = tempstring + " " + cmd + "\n"; - tempstring = tempstring + "#endif\n" - - tempstring = tempstring + "}\n"; - return tempstring; - - - - diff --git a/volk/gen/make_environment_init_h.py b/volk/gen/make_environment_init_h.py deleted file mode 100644 index 0b0f35d61..000000000 --- a/volk/gen/make_environment_init_h.py +++ /dev/null @@ -1,18 +0,0 @@ -from xml.dom import minidom - -def make_environment_init_h() : - tempstring = ""; - tempstring = tempstring + "/*this file is auto_generated by volk_register.py*/\n\n"; - tempstring = tempstring + "#ifndef INCLUDE_LIBVECTOR_ENVIRONMENT_INIT_H\n"; - tempstring = tempstring + "#define INCLUDE_LIBVECTOR_ENVIRONMENT_INIT_H\n"; - tempstring = tempstring + "\n"; - tempstring = tempstring + "#include <volk/volk_common.h>\n\n"; - tempstring = tempstring + "__VOLK_DECL_BEGIN\n"; - tempstring = tempstring + "void volk_environment_init();\n"; - tempstring = tempstring + "__VOLK_DECL_END\n"; - tempstring = tempstring + "#endif\n" - return tempstring; - - - - diff --git a/volk/gen/make_h.py b/volk/gen/make_h.py deleted file mode 100644 index cf8987c39..000000000 --- a/volk/gen/make_h.py +++ /dev/null @@ -1,38 +0,0 @@ -from xml.dom import minidom -from volk_regexp import * - -def make_h(funclist, arched_arglist) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by make_h.py*/\n'; - - tempstring = tempstring + '\n#ifndef INCLUDED_VOLK_RUNTIME'; - tempstring = tempstring + '\n#define INCLUDED_VOLK_RUNTIME'; - tempstring = tempstring + '\n\n#include<volk/volk_typedefs.h>\n'; - tempstring = tempstring + '#include<volk/volk_config_fixed.h>\n'; - tempstring = tempstring + '#include<volk/volk_common.h>\n'; - tempstring = tempstring + '#include<volk/volk_complex.h>\n'; - tempstring = tempstring + '__VOLK_DECL_BEGIN\n'; - - tempstring = tempstring + '\n'; - - tempstring += """ -struct volk_func_desc { - const char **indices; - const int *arch_defs; - const int n_archs; -}; - -VOLK_API unsigned int volk_get_alignment(void); - -""" - for i in range(len(funclist)): - tempstring += "extern VOLK_API " + replace_volk.sub("p", funclist[i]) + " " + funclist[i] + ";\n" - tempstring += "extern VOLK_API void %s_manual%s;\n" % (funclist[i], arched_arglist[i]) - tempstring = strip_trailing(tempstring, " {") - tempstring += "extern VOLK_API struct volk_func_desc %s_get_func_desc(void);\n" % (funclist[i]) - - tempstring = tempstring + '__VOLK_DECL_END\n'; - tempstring = tempstring + "#endif /*INCLUDED_VOLK_RUNTIME*/\n"; - - return tempstring; - diff --git a/volk/gen/make_machines_c.py b/volk/gen/make_machines_c.py deleted file mode 100644 index f19da4ae4..000000000 --- a/volk/gen/make_machines_c.py +++ /dev/null @@ -1,41 +0,0 @@ -# -# 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 * - -def make_machines_c(machines): - tempstring = r""" -// This file is automatically generated by make_machines_c.py. -// Do not edit this file. - -#include <volk/volk_common.h> -#include <volk/volk_typedefs.h> -#include "volk_machines.h" - -struct volk_machine *volk_machines[] = { -""" - for machine in machines: - tempstring += """#if LV_MACHINE_""" + machine.swapcase() + "\n" - tempstring += "&volk_machine_" + machine - tempstring += "," - tempstring += "\n#endif\n" - - tempstring += r""" -}; -unsigned int n_volk_machines = sizeof(volk_machines)/sizeof(*volk_machines); -""" - return tempstring diff --git a/volk/gen/make_machines_h.py b/volk/gen/make_machines_h.py deleted file mode 100644 index d2374120b..000000000 --- a/volk/gen/make_machines_h.py +++ /dev/null @@ -1,59 +0,0 @@ -# -# 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 * - -def make_machines_h(functions, machines, archs): - tempstring = r""" -// This file is automatically generated by make_machines_h.py. -// Do not edit this file. - -#ifndef INCLUDED_LIBVOLK_MACHINES_H -#define INCLUDED_LIBVOLK_MACHINES_H - -#include <volk/volk_common.h> -#include <volk/volk_typedefs.h> - -__VOLK_DECL_BEGIN - -struct volk_machine { - const unsigned int caps; //capabilities (i.e., archs compiled into this machine, in the volk_get_lvarch format) - const char *name; - const unsigned int alignment; //the maximum byte alignment required for functions in this library -""" - for function in functions: - tempstring += " const char *%s_name;\n"%function - 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"""}; - -""" - for machine in machines: - tempstring += """#if LV_MACHINE_""" + machine.swapcase() + "\n" - tempstring += "extern struct volk_machine volk_machine_" + machine + ";\n" - tempstring += """#endif\n""" - - tempstring += r""" - -__VOLK_DECL_END - -#endif //INCLUDED_LIBVOLK_MACHINES_H""" - - return tempstring diff --git a/volk/gen/make_makefile_am.py b/volk/gen/make_makefile_am.py deleted file mode 100644 index 880ce4094..000000000 --- a/volk/gen/make_makefile_am.py +++ /dev/null @@ -1,123 +0,0 @@ -# -# 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 xml.dom import minidom - -def make_makefile_am(dom, machines, archflags_dict): - tempstring = r""" -# This file is automatically generated by make_makefile_am.py. -# Do not edit this file. - -include $(top_srcdir)/Makefile.common - -AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) \ - -I$(top_gendir)/include \ - -I$(top_srcdir)/include \ - -Dvolk_EXPORTS \ - -fvisibility=hidden \ - $(WITH_INCLUDES) - -lib_LTLIBRARIES = \ - libvolk.la - -EXTRA_DIST = \ - volk_rank_archs.h \ - gcc_x86_cpuid.h - -# ---------------------------------------------------------------- -# The main library -# ---------------------------------------------------------------- - -libvolk_la_SOURCES = \ - $(platform_CODE) \ - $(top_gendir)/lib/volk.c \ - $(top_gendir)/lib/volk_cpu.c \ - volk_rank_archs.c \ - volk_prefs.c \ - $(top_gendir)/lib/volk_machines.c - -if LV_HAVE_ORC -volk_orc_CFLAGS = -DLV_HAVE_ORC=1 -volk_orc_LDFLAGS = $(ORC_LDFLAGS) -lorc-0.4 -volk_orc_LIBADD = ../orc/libvolk_orc.la -else -volk_orc_CFLAGS = -volk_orc_LDFLAGS = -volk_orc_LIBADD = -endif - -libvolk_la_CPPFLAGS = $(AM_CPPFLAGS) $(volk_orc_CFLAGS) -libvolk_la_LDFLAGS = $(NO_UNDEFINED) -version-info 0:0:0 $(volk_orc_LDFLAGS) -libvolk_la_LIBADD = $(volk_orc_LIBADD) - -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 + ".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": - tempstring += "-" + archflags_dict[arch] + " " - - tempstring += "\nnoinst_LTLIBRARIES += libvolk_" + machine_name + ".la " - tempstring += "\nlibvolk_la_LIBADD += libvolk_" + machine_name + ".la\n" - tempstring += "libvolk_la_CPPFLAGS += -DLV_MACHINE_" + machine_name.swapcase() + " \n" - tempstring += "endif\n" - - - tempstring += r""" - -# ---------------------------------------------------------------- -# The QA library. Note libvolk.la in LIBADD -# ---------------------------------------------------------------- -#libvolk_qa_la_SOURCES = \ -# qa_utils.cc - -#libvolk_qa_la_LDFLAGS = $(NO_UNDEFINED) -version-info 0:0:0 -lboost - -#libvolk_qa_la_LIBADD = \ -# libvolk.la \ -# libvolk_runtime.la - -# ---------------------------------------------------------------- -# headers that don't get installed -# ---------------------------------------------------------------- -noinst_HEADERS = \ - $(top_gendir)/lib/volk_init.h \ - $(top_gendir)/lib/volk_machines.h \ - $(top_gendir)/lib/volk_environment_init.h \ - qa_utils.h - -# ---------------------------------------------------------------- -# Our test program -# ---------------------------------------------------------------- -noinst_PROGRAMS = \ - testqa - -testqa_SOURCES = testqa.cc qa_utils.cc -testqa_CPPFLAGS = -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN $(AM_CPPFLAGS) -testqa_LDFLAGS = $(BOOST_UNIT_TEST_FRAMEWORK_LIB) -testqa_LDADD = \ - libvolk.la -""" - - - return tempstring diff --git a/volk/gen/make_proccpu_sim.py b/volk/gen/make_proccpu_sim.py deleted file mode 100644 index e2c8123e5..000000000 --- a/volk/gen/make_proccpu_sim.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2011 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from xml.dom import minidom - -def make_proccpu_sim(dom) : - tempstring = ""; - tempstring = tempstring + "/*this file is auto_generated by volk_register.py*/\n\n"; - tempstring = tempstring + "#include <volk/volk_cpu.h>\n" - tempstring = tempstring + "#include <stdio.h>\n" - tempstring = tempstring + "\n\n" - - tempstring = tempstring + "void test_append(char* buf, int val, char* newkey){\n"; - tempstring = tempstring + " if(val==1){\n"; - tempstring = tempstring + " sprintf(buf, \"%s %s\", buf, newkey);\n"; - tempstring = tempstring + " }\n"; - tempstring = tempstring + "}\n"; - tempstring = tempstring + "\n\n"; - - tempstring = tempstring + "int main() {\n"; - tempstring = tempstring + " volk_cpu_init();\n"; - tempstring = tempstring + " char buf[2048];\n"; - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + " test_append(buf, volk_cpu.has_" + arch + "(), \"" + arch + "\");\n" - tempstring = tempstring + " printf(\"%s\\n\", buf);\n" - tempstring = tempstring + "}\n" - return tempstring; diff --git a/volk/gen/make_set_simd.py b/volk/gen/make_set_simd.py deleted file mode 100644 index 8334487d7..000000000 --- a/volk/gen/make_set_simd.py +++ /dev/null @@ -1,166 +0,0 @@ -# -# 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 xml.dom import minidom - -def make_set_simd(dom, machines) : - tempstring = ""; - tempstring = tempstring +'dnl this file is auto generated by volk_register.py\n\n'; - - tempstring = tempstring +'\ndnl define arch checks\n'; - for domarch in dom: - if str(domarch.attributes["type"].value) != "all": - arch = str(domarch.attributes["name"].value); - flag = domarch.getElementsByTagName("flag"); - flag = str(flag[0].firstChild.data); - tempstring = tempstring + "AC_DEFUN([_TRY_ADD_" + arch.swapcase() + "],\n"; - tempstring = tempstring + "[\n"; - tempstring = tempstring + " LF_CHECK_CC_FLAG([-" + flag + "])\n"; - tempstring = tempstring + " LF_CHECK_CXX_FLAG([-" + flag + "])\n"; - tempstring = tempstring + "])\n"; - - tempstring = tempstring +'\ndnl main set_simd_flags\n'; - tempstring = tempstring + "AC_DEFUN([LV_SET_SIMD_FLAGS],\n"; - tempstring = tempstring + "[\n"; - #tempstring = tempstring + " AC_REQUIRE([GR_SET_MD_CPU])\n"; - tempstring = tempstring + " AC_SUBST(LV_CXXFLAGS)\n"; - tempstring = tempstring + " indCC=no\n"; - tempstring = tempstring + " indCXX=no\n"; - tempstring = tempstring + " indLV_ARCH=no\n"; - tempstring = tempstring + " AC_ARG_WITH(lv_arch,\n"; - tempstring = tempstring + " AC_HELP_STRING([--with-lv_arch=ARCH],[set volk hardware speedups as space separated string with elements from the following list("; - - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + arch + ", " - tempstring = tempstring[0:len(tempstring) - 2]; - - tempstring = tempstring + ")]),\n"; - tempstring = tempstring + " [cf_with_lv_arch=\"$withval\"],\n"; - tempstring = tempstring + " [cf_with_lv_arch=\"\"])\n"; - if str(domarch.attributes["type"].value) == "all": - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + " AC_DEFINE(LV_MAKE_" + arch.swapcase() + ", 1, [always set "+ arch + "!])\n"; - tempstring = tempstring + " ADDONS=\"\"\n"; - tempstring = tempstring + " BUILT_ARCHS=\"\"\n"; - #tempstring = tempstring + " _MAKE_FAKE_PROCCPU\n"; - tempstring = tempstring + " OVERRULE_FLAG=\"no\"\n"; - tempstring = tempstring + " if test -z \"$cf_with_lv_arch\"; then\n"; - tempstring = tempstring + " cf_with_lv_arch=\""; - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + arch + " "; - tempstring = tempstring[0:-1] + "\"\n"; - tempstring = tempstring + " OVERRULE_FLAG=\"yes\"\n"; - tempstring = tempstring + " fi\n"; - - tempstring = tempstring +'\ndnl init LV_MAKE_XXX and then try to add archs\n'; - for domarch in dom: - if str(domarch.attributes["type"].value) != "all": - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + " LV_MAKE_" + arch.swapcase() + "=no\n"; - - for domarch in dom: - arch = str(domarch.attributes["name"].value); - atype = str(domarch.attributes["type"].value); - if atype != "all": - tempstring = tempstring + " _TRY_ADD_" + arch.swapcase() + "\n"; - - for domarch in dom: - arch = str(domarch.attributes["name"].value); - atype = str(domarch.attributes["type"].value); - tempstring = tempstring +'\ndnl add in flags for arch ' + arch + '\n'; - overrule = domarch.getElementsByTagName("overrule"); - if overrule: - overrule = str(overrule[0].firstChild.data); - else: - overrule = ""; - overrule_val = domarch.getElementsByTagName("overrule_val"); - if overrule_val: - overrule_val = str(overrule_val[0].firstChild.data); - else: - overrule_val = ""; - flag = domarch.getElementsByTagName("flag"); - flag = str(flag[0].firstChild.data); - if atype != "all": - tempstring = tempstring + " for i in $lf_CXXFLAGS\n" - tempstring = tempstring + " do\n" - tempstring = tempstring + " if test \"X$i\" = X-" + flag +"; then\n"; - tempstring = tempstring + " indCXX=yes\n"; - tempstring = tempstring + " fi\n" - tempstring = tempstring + " done\n" - tempstring = tempstring + " for i in $lf_CFLAGS\n" - tempstring = tempstring + " do\n" - tempstring = tempstring + " if test \"X$i\" = X-" + flag +"; then\n"; - tempstring = tempstring + " indCC=yes\n"; - tempstring = tempstring + " fi\n" - tempstring = tempstring + " done\n" - tempstring = tempstring + " for i in $cf_with_lv_arch\n" - tempstring = tempstring + " do\n" - tempstring = tempstring + " if test \"X$i\" = X" + arch + "; then\n"; - tempstring = tempstring + " indLV_ARCH=yes\n" - tempstring = tempstring + " fi\n" - tempstring = tempstring + " done\n" - tempstring = tempstring + " if test -n \"" + overrule + "\" && test \"$" + overrule + "\" == \"" + overrule_val + "\" && test \"$OVERRULE_FLAG\" == \"yes\" && test \"$indLV_ARCH\" == \"yes\"; then\n" - tempstring = tempstring + " indLV_ARCH=no\n" - tempstring = tempstring + " fi\n" - - tempstring = tempstring + " if test \"$indCC\" == \"yes\" && test \"$indCXX\" == \"yes\" && test \"$indLV_ARCH\" == \"yes\"; then\n" - - #tempstring = tempstring + " ADDONS=\"${ADDONS} -" + flag + "\"\n"; - tempstring = tempstring + " BUILT_ARCHS=\"${BUILT_ARCHS} " + arch + "\"\n"; - tempstring = tempstring + " LV_MAKE_" + arch.swapcase() + "=yes\n"; - tempstring = tempstring + " fi\n" - tempstring = tempstring + " indCC=no\n" - tempstring = tempstring + " indCXX=no\n" - tempstring = tempstring + " indLV_ARCH=no\n" - else: - tempstring = tempstring + " for i in $cf_with_lv_arch\n" - tempstring = tempstring + " do\n" - tempstring = tempstring + " if test \"X$i\" = X" + arch + "; then\n"; - tempstring = tempstring + " indLV_ARCH=yes\n" - tempstring = tempstring + " fi\n" - tempstring = tempstring + " done\n" - tempstring = tempstring + " if test -n \"" + overrule + "\" && test \"$" + overrule + "\" == \"" + overrule_val + "\" && test \"$OVERRULE_FLAG\" == \"yes\" && test \"$indLV_ARCH\" == \"yes\"; then\n" - tempstring = tempstring + " indLV_ARCH=no\n" - tempstring = tempstring + " fi\n" - tempstring = tempstring + " if test \"$indLV_ARCH\" == \"yes\"; then\n" - tempstring = tempstring + " LV_MAKE_" + arch.swapcase() + "=yes\n"; - tempstring = tempstring + " BUILT_ARCHS=\"${BUILT_ARCHS} " + arch + "\"\n"; - tempstring = tempstring + " fi\n" - tempstring = tempstring + " indLV_ARCH=no\n" - - - for domarch in dom: - arch = str(domarch.attributes["name"].value); - tempstring = tempstring + " AM_CONDITIONAL(LV_MAKE_" + arch.swapcase() + ", test \"$LV_MAKE_" + arch.swapcase() + "\" == \"yes\")\n"; - - tempstring += "\n" - #now we can define the machines we're compiling - for machine_name in machines: - tempstring += " AM_CONDITIONAL(LV_MACHINE_" + machine_name.swapcase() + ", " - marchlist = machines[machine_name] - for march in marchlist: - tempstring += "test \"$LV_MAKE_" + march.swapcase() + "\" == \"yes\" && " - - tempstring += "test true)\n" #just so we don't have to detect the last one in the group, i know - tempstring = tempstring + " LV_CXXFLAGS=\"${LV_CXXFLAGS} ${ADDONS}\"\n" - tempstring = tempstring + "])\n" - - return tempstring; - - diff --git a/volk/gen/make_typedefs.py b/volk/gen/make_typedefs.py deleted file mode 100644 index 09221d2ef..000000000 --- a/volk/gen/make_typedefs.py +++ /dev/null @@ -1,23 +0,0 @@ -from xml.dom import minidom -import string -from volk_regexp import * - - - -def make_typedefs(funclist, retlist, my_argtypelist) : - tempstring = ""; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/'; - tempstring = tempstring + '/*this file is auto generated by volk_register.py*/'; - tempstring = tempstring + '\n#ifndef INCLUDED_VOLK_TYPEDEFS'; - tempstring = tempstring + '\n#define INCLUDED_VOLK_TYPEDEFS\n'; - tempstring = tempstring + '\n\n#include<inttypes.h>\n'; - tempstring = tempstring + '#include<volk/volk_complex.h>\n'; - - tempstring = tempstring + '\n'; - - for i in range(len(funclist)): - tempstring = tempstring + "typedef " + retlist[i] +" (*" + replace_volk.sub("p", funclist[i]) + ")(" + my_argtypelist[i] + ");\n"; - - tempstring = tempstring + "#endif /*INCLUDED_VOLK_TYPEDEFS*/\n"; - - return tempstring; diff --git a/volk/gen/volk_arch_defs.py b/volk/gen/volk_arch_defs.py new file mode 100644 index 000000000..41154d5a7 --- /dev/null +++ b/volk/gen/volk_arch_defs.py @@ -0,0 +1,92 @@ +# +# Copyright 2012 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/>. +# + +archs = list() +arch_dict = dict() + +#TODO enable this when we are ready +create_unaligned_archs = False + +class arch_class: + def __init__(self, flags, checks, **kwargs): + for key, cast, failval in ( + ('name', str, None), + ('environment', str, None), + ('include', str, None), + ('alignment', int, 1) + ): + try: setattr(self, key, cast(kwargs[key])) + except: setattr(self, key, failval) + self.checks = checks + assert(self.name) + self._flags = flags + + def is_supported(self, compiler): + if not self._flags.keys(): return True + return compiler in self._flags.keys() + + def get_flags(self, compiler): + try: return self._flags[compiler] + except KeyError: return list() + + def __repr__(self): return self.name + +def register_arch(**kwargs): + arch = arch_class(**kwargs) + archs.append(arch) + arch_dict[arch.name] = arch + if arch.alignment > 1 and create_unaligned_archs: + kwargs['name'] += '_u' + kwargs['alignment'] = 1 + register_arch(**kwargs) + +######################################################################## +# register the arches +######################################################################## +#TODO skip the XML and put it here +from xml.dom import minidom +import os +gendir = os.path.dirname(__file__) +archs_xml = minidom.parse(os.path.join(gendir, 'archs.xml')).getElementsByTagName('arch') +for arch_xml in archs_xml: + kwargs = dict() + for attr in arch_xml.attributes.keys(): + kwargs[attr] = arch_xml.attributes[attr].value + for node in arch_xml.childNodes: + try: + name = node.tagName + val = arch_xml.getElementsByTagName(name)[0].firstChild.data + kwargs[name] = val + except: pass + checks = list() + for check_xml in arch_xml.getElementsByTagName("check"): + name = check_xml.attributes["name"].value + params = list() + for param_xml in check_xml.getElementsByTagName("param"): + params.append(param_xml.firstChild.data) + checks.append([name, params]) + flags = dict() + for flag_xml in arch_xml.getElementsByTagName("flag"): + name = flag_xml.attributes["compiler"].value + if not flags.has_key(name): flags[name] = list() + flags[name].append(flag_xml.firstChild.data) + #force kwargs keys to be of type str, not unicode for py25 + kwargs = dict((str(k), v) for k, v in kwargs.iteritems()) + register_arch(flags=flags, checks=checks, **kwargs) + +if __name__ == '__main__': + print archs diff --git a/volk/gen/volk_compile_utils.py b/volk/gen/volk_compile_utils.py new file mode 100644 index 000000000..cf1357375 --- /dev/null +++ b/volk/gen/volk_compile_utils.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2012 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/>. +# + +import optparse +import volk_arch_defs +import volk_machine_defs + +def do_arch_flags_list(compiler): + output = list() + for arch in volk_arch_defs.archs: + if not arch.is_supported(compiler): continue + fields = [arch.name] + arch.get_flags(compiler) + output.append(','.join(fields)) + print ';'.join(output) + +def do_machines_list(arch_names): + output = list() + for machine in volk_machine_defs.machines: + machine_arch_set = set(machine.arch_names) + if set(arch_names).intersection(machine_arch_set) == machine_arch_set: + output.append(machine.name) + print ';'.join(output) + +def do_machine_flags_list(compiler, machine_name): + output = list() + machine = volk_machine_defs.machine_dict[machine_name] + for arch in machine.archs: + output.extend(arch.get_flags(compiler)) + print ' '.join(output) + +def main(): + parser = optparse.OptionParser() + parser.add_option('--mode', type='string') + parser.add_option('--compiler', type='string') + parser.add_option('--archs', type='string') + parser.add_option('--machine', type='string') + (opts, args) = parser.parse_args() + + if opts.mode == 'arch_flags': return do_arch_flags_list(opts.compiler.lower()) + if opts.mode == 'machines': return do_machines_list(opts.archs.split(';')) + if opts.mode == 'machine_flags': return do_machine_flags_list(opts.compiler.lower(), opts.machine) + +if __name__ == '__main__': main() diff --git a/volk/gen/volk_kernel_defs.py b/volk/gen/volk_kernel_defs.py new file mode 100644 index 000000000..52cdb684c --- /dev/null +++ b/volk/gen/volk_kernel_defs.py @@ -0,0 +1,224 @@ +# +# Copyright 2011-2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import os +import re +import sys +import glob + +from volk_arch_defs import archs + +remove_after_underscore = re.compile("_.*"); +space_remove = re.compile(" "); +leading_space_remove = re.compile("^ *"); +replace_arch = re.compile(", const char\* arch"); +replace_bracket = re.compile(" {"); +replace_volk = re.compile("volk"); + +def strip_trailing(tostrip, stripstr): + lindex = tostrip.rfind(stripstr) + tostrip = tostrip[0:lindex] + tostrip[lindex:len(tostrip)].replace(stripstr, ""); + return tostrip + +srcdir = os.path.dirname(os.path.dirname(__file__)) +hdr_files = glob.glob(os.path.join(srcdir, "include/volk/*.h")) + +datatypes = []; +functions = []; + +for line in hdr_files: + subline = re.search(".*_(a|u)\.h.*", os.path.basename(line)) + if subline: + subsubline = re.search("(?<=volk_).*", subline.group(0)); + if subsubline: + dtype = remove_after_underscore.sub("", subsubline.group(0)); + subdtype = re.search("[0-9]+[A-z]+", dtype); + if subdtype: + datatypes.append(subdtype.group(0)); + + +datatypes = set(datatypes); + +for line in hdr_files: + for dt in datatypes: + if dt in line: + subline = re.search("(volk_" + dt +"_.*(a|u).*\.h)", line); + if subline: + + subsubline = re.search(".+(?=\.h)", subline.group(0)); + functions.append(subsubline.group(0)); + +archs_or = "(" +for arch in archs: + archs_or = archs_or + arch.name.upper() + "|"; +archs_or = archs_or[0:len(archs_or)-1]; +archs_or = archs_or + ")"; + +taglist = []; +fcountlist = []; +arched_arglist = []; +retlist = []; +my_arglist = []; +my_argtypelist = []; +for func in functions: + tags = []; + fcount = []; + infile_source = open(os.path.join(srcdir, 'include', 'volk', func + ".h")) + begun_name = 0; + begun_paren = 0; + sourcefile = infile_source.readlines(); + infile_source.close(); + for line in sourcefile: +#FIXME: make it work for multiple #if define()s + archline = re.search("^\#if.*?LV_HAVE_" + archs_or + ".*", line); + if archline: + arch = archline.group(0); + archline = re.findall(archs_or + "(?=( |\n|&))", line); + if archline: + archsublist = []; + for tup in archline: + archsublist.append(tup[0]); + fcount.append(archsublist); + testline = re.search("static inline.*?" + func, line); + if (not testline): + continue + tagline = re.search(func + "_.+", line); + if tagline: + tag = re.search("(?<=" + func + "_)\w+(?= *\()",line); + if tag: + tag = re.search("\w+", tag.group(0)); + if tag: + tags.append(tag.group(0)); + + + if begun_name == 0: + retline = re.search(".+(?=" + func + ")", line); + if retline: + ret = retline.group(0); + + + + + subline = re.search(func + ".*", line); + if subline: + subsubline = re.search("\(.*?\)", subline.group(0)); + if subsubline: + args = subsubline.group(0); + + else: + begun_name = 1; + subsubline = re.search("\(.*", subline.group(0)); + if subsubline: + args = subsubline.group(0); + begun_paren = 1; + else: + if begun_paren == 1: + subline = re.search(".*?\)", line); + if subline: + args = args + subline.group(0); + begun_name = 0; + begun_paren = 0; + else: + subline = re.search(".*", line); + args = args + subline.group(0); + else: + subline = re.search("\(.*?\)", line); + if subline: + args = subline.group(0); + begun_name = 0; + else: + subline = re.search("\(.*", line); + if subline: + args = subline.group(0); + begun_paren = 1; + + replace = re.compile("static "); + ret = replace.sub("", ret); + replace = re.compile("inline "); + ret = replace.sub("", ret); + arched_args = args[args.find('(')+1:args.find(')')] + + remove = re.compile('\)|\(|{'); + rargs = remove.sub("", args); + sargs = rargs.split(','); + + + + margs = []; + atypes = []; + for arg in sargs: + temp = arg.split(" "); + margs.append(temp[-1]); + replace = re.compile(" " + temp[-1]); + atypes.append(replace.sub("", arg)); + + + my_args = "" + arg_types = "" + for arg in range(0, len(margs) - 1): + this_arg = leading_space_remove.sub("", margs[arg]); + my_args = my_args + this_arg + ", "; + this_type = leading_space_remove.sub("", atypes[arg]); + arg_types = arg_types + this_type + ", "; + + this_arg = leading_space_remove.sub("", margs[-1]); + my_args = my_args + this_arg; + this_type = leading_space_remove.sub("", atypes[-1]); + arg_types = arg_types + this_type; + my_argtypelist.append(arg_types); + + if(ret[-1] != ' '): + ret = ret + ' '; + + arched_arglist.append(arched_args); #!!!!!!!!!!! + my_arglist.append(my_args) #!!!!!!!!!!!!!!!!! + retlist.append(ret); + fcountlist.append(fcount); + taglist.append(tags); + +class kernel_class: + def __init__(self, index): + self.name = functions[index] + self.pname = self.name.replace('volk_', 'p_') + self.rettype = retlist[index] + self.arglist_defs = my_argtypelist[index] + self.arglist_namedefs = arched_arglist[index] + self.arglist_names = my_arglist[index] + self._tagdeps = fcountlist[index] + self._taglist = taglist[index] + + def get_tags(self, archs): + def is_in(x): return x.lower() in archs + taglist = list() + tagdeps = list() + for i in range(len(self._tagdeps)): + if all(map(is_in, self._tagdeps[i])): + taglist.append(self._taglist[i]) + tagdeps.append(self._tagdeps[i]) + return taglist, tagdeps + + def __repr__(self): + return self.name + +kernels = map(kernel_class, range(len(retlist))) + +if __name__ == '__main__': + print kernels diff --git a/volk/gen/volk_machine_defs.py b/volk/gen/volk_machine_defs.py new file mode 100644 index 000000000..d1a856981 --- /dev/null +++ b/volk/gen/volk_machine_defs.py @@ -0,0 +1,78 @@ +# +# Copyright 2012 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_arch_defs import arch_dict + +machines = list() +machine_dict = dict() + +class machine_class: + def __init__(self, name, archs): + self.name = name + self.archs = list() + self.arch_names = list() + for arch_name in archs: + if not arch_name: continue + arch = arch_dict[arch_name] + self.archs.append(arch) + self.arch_names.append(arch_name) + arch_name += '_u' + if arch.alignment > 1 and arch_dict.has_key(arch_name): + arch = arch_dict[arch_name] + self.archs.append(arch) + self.alignment = max(map(lambda a: a.alignment, self.archs)) + + def __repr__(self): return self.name + +def register_machine(name, archs): + for i, arch_name in enumerate(archs): + if '|' in arch_name: #handle special arch names with the '|' + for arch_sub in arch_name.split('|'): + if arch_sub: + register_machine(name+'_'+arch_sub, archs[:i] + [arch_sub] + archs[i+1:]) + else: + register_machine(name, archs[:i] + archs[i+1:]) + return + machine = machine_class(name=name, archs=archs) + machines.append(machine) + machine_dict[machine.name] = machine + +######################################################################## +# register the machines +######################################################################## +#TODO skip the XML and put it here +from xml.dom import minidom +import os +gendir = os.path.dirname(__file__) +machines_xml = minidom.parse(os.path.join(gendir, 'machines.xml')).getElementsByTagName('machine') +for machine_xml in machines_xml: + kwargs = dict() + for attr in machine_xml.attributes.keys(): + kwargs[attr] = machine_xml.attributes[attr].value + for node in machine_xml.childNodes: + try: + name = node.tagName + val = machine_xml.getElementsByTagName(name)[0].firstChild.data + kwargs[name] = val + except: pass + kwargs['archs'] = kwargs['archs'].split() + #force kwargs keys to be of type str, not unicode for py25 + kwargs = dict((str(k), v) for k, v in kwargs.iteritems()) + register_machine(**kwargs) + +if __name__ == '__main__': + print machines diff --git a/volk/gen/volk_regexp.py b/volk/gen/volk_regexp.py deleted file mode 100644 index eb4ceb54b..000000000 --- a/volk/gen/volk_regexp.py +++ /dev/null @@ -1,13 +0,0 @@ -import re - -remove_after_underscore = re.compile("_.*"); -space_remove = re.compile(" "); -leading_space_remove = re.compile("^ *"); -replace_arch = re.compile(", const char\* arch"); -replace_bracket = re.compile(" {"); -replace_volk = re.compile("volk"); - -def strip_trailing(tostrip, stripstr): - lindex = tostrip.rfind(stripstr) - tostrip = tostrip[0:lindex] + tostrip[lindex:len(tostrip)].replace(stripstr, ""); - return tostrip diff --git a/volk/gen/volk_register.py b/volk/gen/volk_register.py deleted file mode 100644 index 3a237c5ca..000000000 --- a/volk/gen/volk_register.py +++ /dev/null @@ -1,303 +0,0 @@ -#! /usr/bin/env python - -import sys -import os -import re -import glob -from xml.dom import minidom -from volk_regexp import * -from make_cpuid_c import make_cpuid_c -from make_cpuid_h import make_cpuid_h -from make_set_simd import make_set_simd -from make_config_fixed import make_config_fixed -from make_typedefs import make_typedefs -from make_environment_init_c import make_environment_init_c -from make_environment_init_h import make_environment_init_h -from make_makefile_am import make_makefile_am -from make_machines_h import make_machines_h -from make_machines_c import make_machines_c -from make_each_machine_c import make_each_machine_c -from make_c import make_c -from make_h import make_h -import copy - -#set srcdir and gendir -srcdir = os.path.dirname(os.path.dirname(__file__)) -try: gendir = sys.argv[1] -except: gendir = os.path.dirname(__file__) - -#ensure directories exist -for dir in ( - (os.path.join(gendir, 'include', 'volk')), - (os.path.join(gendir, 'lib')), - (os.path.join(gendir, 'config')) -): - if not os.path.exists(dir): os.makedirs(dir) - -outfile_set_simd = open(os.path.join(gendir, "config/lv_set_simd_flags.m4"), "w") -outfile_h = open(os.path.join(gendir, "include/volk/volk.h"), "w") -outfile_c = open(os.path.join(gendir, "lib/volk.c"), "w") -outfile_typedefs = open(os.path.join(gendir, "include/volk/volk_typedefs.h"), "w") -outfile_init_h = open(os.path.join(gendir, "lib/volk_init.h"), "w") -outfile_cpu_h = open(os.path.join(gendir, "include/volk/volk_cpu.h"), "w") -outfile_cpu_c = open(os.path.join(gendir, "lib/volk_cpu.c"), "w") -#outfile_config_in = open(os.path.join(gendir, "include/volk/volk_config.h.in"), "w") -outfile_config_fixed = open(os.path.join(gendir, "include/volk/volk_config_fixed.h"), "w") -outfile_environment_c = open(os.path.join(gendir, "lib/volk_environment_init.c"), "w") -outfile_environment_h = open(os.path.join(gendir, "lib/volk_environment_init.h"), "w") -outfile_makefile_am = open(os.path.join(gendir, "lib/Makefile.am"), "w") -outfile_machines_h = open(os.path.join(gendir, "lib/volk_machines.h"), "w") -outfile_machines_c = open(os.path.join(gendir, "lib/volk_machines.c"), "w") -hdr_files = glob.glob(os.path.join(srcdir, "include/volk/*.h")) - -datatypes = []; -functions = []; - -for line in hdr_files: - subline = re.search(".*_(a|u)\.h.*", os.path.basename(line)) - if subline: - subsubline = re.search("(?<=volk_).*", subline.group(0)); - if subsubline: - dtype = remove_after_underscore.sub("", subsubline.group(0)); - subdtype = re.search("[0-9]+[A-z]+", dtype); - if subdtype: - datatypes.append(subdtype.group(0)); - - -datatypes = set(datatypes); - -for line in hdr_files: - for dt in datatypes: - if dt in line: - subline = re.search("(volk_" + dt +"_.*(a|u).*\.h)", line); - if subline: - - subsubline = re.search(".+(?=\.h)", subline.group(0)); - functions.append(subsubline.group(0)); - -archs = []; -afile = minidom.parse(os.path.join(srcdir, "gen/archs.xml")) -filearchs = afile.getElementsByTagName("arch"); -for filearch in filearchs: - archs.append(str(filearch.attributes["name"].value)); - -for arch in archs: - a_var = re.search("^\$", arch); - if a_var: - archs.remove(arch); - -#strip out mutex archs - -archflags_dict = {} -for filearch in filearchs: - archflags_dict[str(filearch.attributes["name"].value)] = str(filearch.getElementsByTagName("flag")[0].firstChild.data) - -archalign_dict = {} -for filearch in filearchs: - alignelem = filearch.getElementsByTagName("alignment") - if(alignelem): - archalign_dict[str(filearch.attributes["name"].value)] = int(alignelem[0].firstChild.data) - -archs_or = "(" -for arch in archs: - archs_or = archs_or + arch.upper() + "|"; -archs_or = archs_or[0:len(archs_or)-1]; -archs_or = archs_or + ")"; - -#get machine list and parse to a list of machines, each with a list of archs (none of this DOM crap) -machine_str_dict = {} -mfile = minidom.parse(os.path.join(srcdir, "gen/machines.xml")) -filemachines = mfile.getElementsByTagName("machine") - -for filemachine in filemachines: - machine_str_dict[str(filemachine.attributes["name"].value)] = str(filemachine.getElementsByTagName("archs")[0].firstChild.data).split() - -#all right now you have a dict of arch lists -#next we expand it -#this is an expanded list accounting for the OR syntax -#TODO: make this work for multiple "|" machines -machines = {} -already_done = False -for machine_name in machine_str_dict: - already_done = False - marchlist = machine_str_dict[machine_name] - for march in marchlist: - or_marchs = march.split("|") - if len(or_marchs) > 1: - marchlist.remove(march) - for or_march in or_marchs: - tempmarchlist = copy.deepcopy(marchlist) - tempmarchlist.append(or_march) - machines[machine_name + "_" + or_march] = tempmarchlist - already_done = True - - if not already_done: - machines[machine_name] = marchlist - -#get the maximum alignment for all archs in a machine -machine_alignment_dict = {} -for machine in machines: - machine_alignment_dict[machine] = max((archalign_dict.get(k, 1)) for k in machines[machine]) - -#for machine in machine_alignment_dict: -# print machine + ": %d" % machine_alignment_dict[machine] - -taglist = []; -fcountlist = []; -arched_arglist = []; -retlist = []; -my_arglist = []; -my_argtypelist = []; -for func in functions: - tags = []; - fcount = []; - infile_source = open(os.path.join(srcdir, 'include', 'volk', func + ".h")) - begun_name = 0; - begun_paren = 0; - sourcefile = infile_source.readlines(); - infile_source.close(); - for line in sourcefile: -#FIXME: make it work for multiple #if define()s - archline = re.search("^\#if.*?LV_HAVE_" + archs_or + ".*", line); - if archline: - arch = archline.group(0); - archline = re.findall(archs_or + "(?=( |\n|&))", line); - if archline: - archsublist = []; - for tup in archline: - archsublist.append(tup[0]); - fcount.append(archsublist); - testline = re.search("static inline.*?" + func, line); - if (not testline): - continue - tagline = re.search(func + "_.+", line); - if tagline: - tag = re.search("(?<=" + func + "_)\w+(?= *\()",line); - if tag: - tag = re.search("\w+", tag.group(0)); - if tag: - tags.append(tag.group(0)); - - - if begun_name == 0: - retline = re.search(".+(?=" + func + ")", line); - if retline: - ret = retline.group(0); - - - - - subline = re.search(func + ".*", line); - if subline: - subsubline = re.search("\(.*?\)", subline.group(0)); - if subsubline: - args = subsubline.group(0); - - else: - begun_name = 1; - subsubline = re.search("\(.*", subline.group(0)); - if subsubline: - args = subsubline.group(0); - begun_paren = 1; - else: - if begun_paren == 1: - subline = re.search(".*?\)", line); - if subline: - args = args + subline.group(0); - begun_name = 0; - begun_paren = 0; - else: - subline = re.search(".*", line); - args = args + subline.group(0); - else: - subline = re.search("\(.*?\)", line); - if subline: - args = subline.group(0); - begun_name = 0; - else: - subline = re.search("\(.*", line); - if subline: - args = subline.group(0); - begun_paren = 1; - - replace = re.compile("static "); - ret = replace.sub("", ret); - replace = re.compile("inline "); - ret = replace.sub("", ret); - replace = re.compile("\)"); - arched_args = replace.sub(", const char* arch) {", args); - - remove = re.compile('\)|\(|{'); - rargs = remove.sub("", args); - sargs = rargs.split(','); - - - - margs = []; - atypes = []; - for arg in sargs: - temp = arg.split(" "); - margs.append(temp[-1]); - replace = re.compile(" " + temp[-1]); - atypes.append(replace.sub("", arg)); - - - my_args = "" - arg_types = "" - for arg in range(0, len(margs) - 1): - this_arg = leading_space_remove.sub("", margs[arg]); - my_args = my_args + this_arg + ", "; - this_type = leading_space_remove.sub("", atypes[arg]); - arg_types = arg_types + this_type + ", "; - - this_arg = leading_space_remove.sub("", margs[-1]); - my_args = my_args + this_arg; - this_type = leading_space_remove.sub("", atypes[-1]); - arg_types = arg_types + this_type; - my_argtypelist.append(arg_types); - - if(ret[-1] != ' '): - ret = ret + ' '; - - arched_arglist.append(arched_args); #!!!!!!!!!!! - my_arglist.append(my_args) #!!!!!!!!!!!!!!!!! - retlist.append(ret); - fcountlist.append(fcount); - taglist.append(tags); - - -outfile_cpu_h.write(make_cpuid_h(filearchs)); -outfile_cpu_h.close(); - -outfile_cpu_c.write(make_cpuid_c(filearchs)); -outfile_cpu_c.close(); - -outfile_set_simd.write(make_set_simd(filearchs, machines)); -outfile_set_simd.close(); - -outfile_config_fixed.write(make_config_fixed(filearchs)); -outfile_config_fixed.close(); - -outfile_typedefs.write(make_typedefs(functions, retlist, my_argtypelist)); -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, archs)) -outfile_machines_h.close() - -outfile_machines_c.write(make_machines_c(machines)) -outfile_machines_c.close() - -outfile_c.write(make_c(machines, archs, functions, arched_arglist, my_arglist)) -outfile_c.close() - -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 + ".c") - outfile_machine_c = open(machine_c_filename, "w") - outfile_machine_c.write(make_each_machine_c(machine, machines[machine], functions, fcountlist, taglist, machine_alignment_dict[machine])) - outfile_machine_c.close() diff --git a/volk/gen/volk_tmpl_utils.py b/volk/gen/volk_tmpl_utils.py new file mode 100644 index 000000000..6c08a8213 --- /dev/null +++ b/volk/gen/volk_tmpl_utils.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import os +import re +import sys +import optparse +import volk_arch_defs +import volk_machine_defs +import volk_kernel_defs +from Cheetah import Template + +def __escape_pre_processor(code): + out = list() + for line in code.splitlines(): + m = re.match('^(\s*)#(\s*)(\w+)(.*)$', line) + if m: + p0, p1, fcn, stuff = m.groups() + conly = fcn in ('include', 'define', 'ifdef', 'ifndef', 'endif', 'elif', 'pragma') + both = fcn in ('if', 'else') + istmpl = '$' in stuff + if 'defined' in stuff: istmpl = False + if conly or (both and not istmpl): + line = '%s\\#%s%s%s'%(p0, p1, fcn, stuff) + out.append(line) + return '\n'.join(out) + +def __parse_tmpl(_tmpl, **kwargs): + defs = { + 'archs': volk_arch_defs.archs, + 'arch_dict': volk_arch_defs.arch_dict, + 'machines': volk_machine_defs.machines, + 'machine_dict': volk_machine_defs.machine_dict, + 'kernels': volk_kernel_defs.kernels, + } + defs.update(kwargs) + _tmpl = __escape_pre_processor(_tmpl) + _tmpl = """ + +/* this file was generated by volk template utils, do not edit! */ + +""" + _tmpl + return str(Template.Template(_tmpl, defs)) + +def main(): + parser = optparse.OptionParser() + parser.add_option('--input', type='string') + parser.add_option('--output', type='string') + (opts, args) = parser.parse_args() + + output = __parse_tmpl(open(opts.input).read(), args=args) + if opts.output: open(opts.output, 'w').write(output) + else: print output + +if __name__ == '__main__': main() |