diff options
author | Nick Foster | 2012-04-15 16:03:27 -0700 |
---|---|---|
committer | Johnathan Corgan | 2012-04-16 08:25:23 -0700 |
commit | c3f2c30a54c75575f464afdd7cd11a017fb07695 (patch) | |
tree | 6889936b1b11ae77fbdcdfb6da17cb7ea840422f /volk/gen/make_cpuid_c.py | |
parent | 04e2ebb979942cada74f10ea022342716c6851bf (diff) | |
download | gnuradio-c3f2c30a54c75575f464afdd7cd11a017fb07695.tar.gz gnuradio-c3f2c30a54c75575f464afdd7cd11a017fb07695.tar.bz2 gnuradio-c3f2c30a54c75575f464afdd7cd11a017fb07695.zip |
Volk: add support for checking AVX enable state of OS.
Some systems (notably Xen hypervisor) appear to use XSETBV to disable AVX. This causes SIGILL when running AVX instructions. This commit makes Volk check XCR0 on the AVX arch before proceeding.
Diffstat (limited to 'volk/gen/make_cpuid_c.py')
-rw-r--r-- | volk/gen/make_cpuid_c.py | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/volk/gen/make_cpuid_c.py b/volk/gen/make_cpuid_c.py index 2be1123a8..4bd1ce5b1 100644 --- a/volk/gen/make_cpuid_c.py +++ b/volk/gen/make_cpuid_c.py @@ -90,20 +90,26 @@ def make_cpuid_c(dom) : no_test = False; else: no_test = False; - arch = str(domarch.attributes["name"].value); - op = domarch.getElementsByTagName("op"); + arch = str(domarch.attributes["name"].value) + op = domarch.getElementsByTagName("op") if op: - op = str(op[0].firstChild.data); - reg = domarch.getElementsByTagName("reg"); + op = str(op[0].firstChild.data) + reg = domarch.getElementsByTagName("reg") if reg: - reg = str(reg[0].firstChild.data); - shift = domarch.getElementsByTagName("shift"); + reg = str(reg[0].firstChild.data) + shift = domarch.getElementsByTagName("shift") if shift: - shift = str(shift[0].firstChild.data); - val = domarch.getElementsByTagName("val"); + shift = str(shift[0].firstChild.data) + val = domarch.getElementsByTagName("val") if val: - val = str(val[0].firstChild.data); - + 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 () { @@ -121,13 +127,23 @@ int i_can_has_%s () { int i_can_has_%s () { #if defined(VOLK_CPU_x86) unsigned int e%sx = cpuid_e%sx (%s); - return ((e%sx >> %s) & 1) == %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 } -""" % (arch, reg, reg, op, reg, shift, val) +""" elif op == "0x80000001": tempstring = tempstring + """\ |