Debian Codegraph @

rpython/jit/backend/ppc/detect_feature.py

raw symbols SCIP
1 from __future__ import print_function
2
3 import os
4 import sys
5 import struct
6 import platform
7 from rpython.rtyper.lltypesystem import lltype, rffi
8 from rpython.rtyper.tool import rffi_platform
9 from rpython.rlib.rmmap import alloc, free
10 from rpython.rlib.rstruct.runpack import runpack
11
12 AT_HWCAP = rffi_platform.getconstantinteger('AT_HWCAP', '#include "linux/auxvec.h"')
13 AT_NULL = rffi_platform.getconstantinteger('AT_NULL', '#include "linux/auxvec.h"')
14 PPC_FEATURE_HAS_ALTIVEC = rffi_platform.getconstantinteger('PPC_FEATURE_HAS_ALTIVEC',
15 '#include "asm/cputable.h"')
16 SYSTEM = platform.system()
17
18 def detect_vsx_linux():
19 try:
20 fd = os.open("/proc/self/auxv", os.O_RDONLY, 0644)
21 try:
22 while True:
23 buf = os.read(fd, 8)
24 buf2 = os.read(fd, 8)
25 if not buf or not buf2:
26 break
27 key = runpack("L", buf)
28 value = runpack("L", buf2)
29 if key == AT_HWCAP:
30 if value & PPC_FEATURE_HAS_ALTIVEC:
31 return True
32 if key == AT_NULL:
33 return False
34 finally:
35 os.close(fd)
36 except OSError:
37 pass
38 return False
39
40 def detect_vsx():
41 if SYSTEM == 'Linux':
42 return detect_vsx_linux()
43 return False
44
45 if __name__ == '__main__':
46 print('The following extensions are supported:')
47 if detect_vsx():
48 print(' - AltiVec')