unstable_simd.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. from ..interpreterbase import FeatureNew
  14. class SimdModule(ExtensionModule):
  15. @FeatureNew('SIMD module', '0.42.0')
  16. def __init__(self, interpreter):
  17. super().__init__(interpreter)
  18. self.snippets.add('check')
  19. # FIXME add Altivec and AVX512.
  20. self.isets = ('mmx',
  21. 'sse',
  22. 'sse2',
  23. 'sse3',
  24. 'ssse3',
  25. 'sse41',
  26. 'sse42',
  27. 'avx',
  28. 'avx2',
  29. 'neon',
  30. )
  31. def check(self, interpreter, state, args, kwargs):
  32. result = []
  33. if len(args) != 1:
  34. raise mesonlib.MesonException('Check requires one argument, a name prefix for checks.')
  35. prefix = args[0]
  36. if not isinstance(prefix, str):
  37. raise mesonlib.MesonException('Argument must be a string.')
  38. if 'compiler' not in kwargs:
  39. raise mesonlib.MesonException('Must specify compiler keyword')
  40. if 'sources' in kwargs:
  41. raise mesonlib.MesonException('SIMD module does not support the "sources" keyword')
  42. basic_kwargs = {}
  43. for key, value in kwargs.items():
  44. if key not in self.isets and key != 'compiler':
  45. basic_kwargs[key] = value
  46. compiler = kwargs['compiler'].compiler
  47. if not isinstance(compiler, compilers.compilers.Compiler):
  48. raise mesonlib.MesonException('Compiler argument must be a compiler object.')
  49. cdata = interpreter.func_configuration_data(None, [], {})
  50. conf = cdata.held_object
  51. for iset in self.isets:
  52. if iset not in kwargs:
  53. continue
  54. iset_fname = kwargs[iset] # Migth also be an array or Files. static_library will validate.
  55. args = compiler.get_instruction_set_args(iset)
  56. if args is None:
  57. mlog.log('Compiler supports %s:' % iset, mlog.red('NO'))
  58. continue
  59. if len(args) > 0:
  60. if not compiler.has_multi_arguments(args, state.environment):
  61. mlog.log('Compiler supports %s:' % iset, mlog.red('NO'))
  62. continue
  63. mlog.log('Compiler supports %s:' % iset, mlog.green('YES'))
  64. conf.values['HAVE_' + iset.upper()] = ('1', 'Compiler supports %s.' % iset)
  65. libname = prefix + '_' + iset
  66. lib_kwargs = {'sources': iset_fname,
  67. }
  68. lib_kwargs.update(basic_kwargs)
  69. langarg_key = compiler.get_language() + '_args'
  70. old_lang_args = mesonlib.extract_as_list(lib_kwargs, langarg_key)
  71. all_lang_args = old_lang_args + args
  72. lib_kwargs[langarg_key] = all_lang_args
  73. result.append(interpreter.func_static_lib(None, [libname], lib_kwargs))
  74. return [result, cdata]
  75. def initialize(*args, **kwargs):
  76. return SimdModule(*args, **kwargs)