Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.5KB

  1. #!/usr/bin/env python3
  2. import re
  3. import os
  4. generic = {
  5. '7' : 'arm7',
  6. '8' : 'arm8',
  7. '9' : 'arm9tdmi',
  8. 'a' : 'arm10e',
  9. 'b' : 'mpcore'
  10. }
  11. specific = {
  12. '810' : 'arm810',
  13. '8xx' : 'arm8',
  14. '920' : 'arm920t',
  15. '922' : 'arm922t',
  16. '946' : 'arm946e-s',
  17. '926' : 'arm926ej-s',
  18. '966' : 'arm966e-s',
  19. '968' : 'arm968e-s',
  20. '940' : 'arm940e',
  21. '9xx' : 'arm9tdmi',
  22. 'a20' : 'arm1020e',
  23. 'a22' : 'arm1022e',
  24. 'a26' : 'arm1026ej-s',
  25. 'axx' : 'arm10e',
  26. 'b36' : 'arm1136j-s',
  27. 'b56' : 'arm1156t2-s',
  28. 'b76' : 'arm1176jz-s',
  29. 'bxx' : 'mpcore',
  30. 'c05' : 'cortex-a5',
  31. 'c07' : 'cortex-a7',
  32. 'c08' : 'cortex-a8',
  33. 'c09' : 'cortex-a9',
  34. 'c0d' : 'cortex-a12',
  35. 'c0f' : 'cortex-a15',
  36. 'c0e' : 'cortex-a17',
  37. 'd01' : 'cortex-a32',
  38. 'd04' : 'cortex-a35',
  39. 'd03' : 'cortex-a53',
  40. 'd05' : 'cortex-a55',
  41. 'd07' : 'cortex-a57',
  42. 'd08' : 'cortex-a72',
  43. 'd09' : 'cortex-a73',
  44. 'd0a' : 'cortex-a75',
  45. 'c14' : 'cortex-r4',
  46. 'c15' : 'cortex-r5',
  47. 'c17' : 'cortex-r7',
  48. 'c18' : 'cortex-r8',
  49. 'd21' : 'cortex-m33',
  50. 'd20' : 'cortex-m23',
  51. 'c20' : 'cortex-m7',
  52. 'c24' : 'cortex-m4',
  53. 'c23' : 'cortex-m3',
  54. 'c21' : 'cortex-m1',
  55. 'c20' : 'cortex-m0',
  56. 'c60' : 'cortex-m0plus'
  57. }
  58. class CPUInfo(object):
  59. ARM='arm'
  60. Intel='x86'
  61. Generic='generic'
  62. def __init__(self):
  63. self.architecture=os.uname().machine
  64. if re.match('arm',self.architecture): self.chip=CPUInfo.ARM
  65. elif re.match('x86',self.architecture): self.chip=CPUInfo.Intel
  66. else : self.chip=CPUInfo.Generic
  67. with open('/proc/cpuinfo','r') as proc:
  68. lines=[l for l in proc]
  69. self.lines=[re.sub('\s+',' ',l) for l in lines]
  70. f=[re.match('(?:Features|flags) . ([\w ]+)$',l) for l in self.lines]
  71. f=[m.groups(0)[0] for m in f if m is not None]
  72. self.features=set()
  73. for line in f : self.features.update(line.strip().split(' '))
  74. if self.chip==CPUInfo.ARM:
  75. c=[re.match('CPU part\s:\s+0x([0-9a-f]+)',l) for l in self.lines]
  76. self.cpu={m.groups(0)[0] for m in c if m is not None}.pop()
  77. self.model=specific.get(self.cpu,generic.get(self.cpu,'generic'))
  78. else:
  79. self.cpu=None
  80. self.model='generic'
  81. def __getitem__(self,key):
  82. return key in self.features
  83. @property
  84. def fpuFlags(self):
  85. if self.chip==CPUInfo.Intel:
  86. if self['sse'] or self['sse2']:
  87. return ['-msse','-mfpmath=sse']
  88. return []
  89. elif self.chip==CPUInfo.ARM:
  90. f=[]
  91. if self['neon']: f=['-mfpu=neon-fp-armv8','-mneon-for-64bits']
  92. elif self['vfpv4']: f=['-mfpu=neon-vfpv4']
  93. elif self['vfpv3']: f=['-mfpu=neon-vpfv3']
  94. elif self['vfpv3d16']: f=['-mfpu=vfpv3-d16']
  95. elif self['vfp'] or self['vfpv2'] or self['vfpd32']: f=['-mfpu=vfp']
  96. f.append('-mfloat-abi=hard')
  97. return f
  98. else:
  99. return []
  100. @property
  101. def modelFlags(self):
  102. if self.chip==CPUInfo.ARM:
  103. if self.model=='generic': return ['-mtune=generic']
  104. else: return ['-mcpu={}'.format(self.model),'-mtune={}'.format(self.model)]
  105. else:
  106. return ['-mtune=generic']
  107. @property
  108. def flags(self):
  109. f=self.modelFlags
  110. f.extend(self.fpuFlags)
  111. return f
  112. try:
  113. c=CPUInfo()
  114. print(' '.join(c.flags))
  115. except Exception as e:
  116. print('Error : {}'.format(e))