unstable_simd.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright 2017 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. from .. import mesonlib, compilers, mlog
  12. from . import ExtensionModule
  13. class SimdModule(ExtensionModule):
  14. def __init__(self):
  15. super().__init__()
  16. self.snippets.add('check')
  17. # FIXME add Altivec and AVX512.
  18. self.isets = ('mmx',
  19. 'sse',
  20. 'sse2',
  21. 'sse3',
  22. 'ssse3',
  23. 'sse41',
  24. 'sse42',
  25. 'avx',
  26. 'avx2',
  27. 'neon',
  28. )
  29. def check(self, interpreter, state, args, kwargs):
  30. result = []
  31. if len(args) != 1:
  32. raise mesonlib.MesonException('Check requires one argument, a name prefix for checks.')
  33. prefix = args[0]
  34. if not isinstance(prefix, str):
  35. raise mesonlib.MesonException('Argument must be a string.')
  36. if 'compiler' not in kwargs:
  37. raise mesonlib.MesonException('Must specify compiler keyword')
  38. compiler = kwargs['compiler'].compiler
  39. if not isinstance(compiler, compilers.compilers.Compiler):
  40. raise mesonlib.MesonException('Compiler argument must be a compiler object.')
  41. cdata = interpreter.func_configuration_data(None, [], {})
  42. conf = cdata.held_object
  43. for iset in self.isets:
  44. if iset not in kwargs:
  45. continue
  46. iset_fname = kwargs[iset] # Migth also be an array or Files. static_library will validate.
  47. args = compiler.get_instruction_set_args(iset)
  48. if args is None:
  49. mlog.log('Compiler supports %s:' % iset, mlog.red('NO'))
  50. continue
  51. if len(args) > 0:
  52. if not compiler.has_multi_arguments(args, state.environment):
  53. mlog.log('Compiler supports %s:' % iset, mlog.red('NO'))
  54. continue
  55. mlog.log('Compiler supports %s:' % iset, mlog.green('YES'))
  56. conf.values['HAVE_' + iset.upper()] = ('1', 'Compiler supports %s.' % iset)
  57. libname = prefix + '_' + iset
  58. lib_kwargs = {'sources': iset_fname,
  59. compiler.get_language() + '_args': args}
  60. result.append(interpreter.func_static_lib(None, [libname], lib_kwargs))
  61. return [result, cdata]
  62. def initialize():
  63. return SimdModule()