diff --git a/meson.build b/meson.build index d6cd3136b36..6089a620eaf 100644 --- a/meson.build +++ b/meson.build @@ -1129,6 +1129,21 @@ if host_machine.system() == 'windows' endif endif +if get_option('sse2') and host_machine.system() == 'windows' and host_machine.cpu_family() == 'x86' and cc.get_id() == 'gcc' + # These settings make generated MinGW code match MSVC and follow + # GCC advice on https://gcc.gnu.org/wiki/FloatingPointMath#x86note + # + # NOTE: We need to ensure stack is realigned given that we + # produce shared objects, and have no control over the stack + # alignment policy of the application. Therefore we need + # -mstackrealign or -mincoming-stack-boundary=2. + # + # XXX: We could have SSE without -mstackrealign if we always used + # __attribute__((force_align_arg_pointer)), but that's not + # always the case. + c_args += ['-msse', '-msse2', '-mfpmath=sse', '-mstackrealign'] +endif + if host_machine.cpu_family().startswith('x86') and cc.get_id() != 'msvc' pre_args += '-DUSE_SSE41' with_sse41 = true diff --git a/meson_options.txt b/meson_options.txt index 8bc3a228f25..949d7d39774 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -441,3 +441,9 @@ option( value : 'auto', description : 'Use ZSTD instead of ZLIB in some cases.' ) +option( + 'sse2', + type : 'boolean', + value : true, + description : 'use msse2 flag for mingw x86. Default: true', +)