[Mesa-dev] [PATCH v2] meson: Enable SSE4.1 optimizations

Dylan Baker dylan at pnwbakers.com
Thu Nov 16 22:46:49 UTC 2017


This patch checks for an and then enables sse4.1 optimizations if the
host machine will be x86/x86_64.

v2: - Don't compile code, it's unnecessary since we require a compiler
      which always has SSE4.1 (Matt)

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com> (v1)
---
 meson.build          | 15 ++++++++++++++-
 src/mesa/meson.build | 14 +++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/meson.build b/meson.build
index 383ebb36662..2df4610a2fd 100644
--- a/meson.build
+++ b/meson.build
@@ -502,7 +502,20 @@ foreach a : ['-Wno-override-init', '-Wno-initializer-overrides']
   endif
 endforeach
 
-# TODO: SSE41 (which is only required for core mesa)
+if host_machine.cpu_family().startswith('x86')
+  pre_args += '-DHAVE_SSE41'
+  with_sse41 = true
+  sse41_args = ['-msse4.1']
+
+  # GCC on x86 (not x64) with -msse* assumes a 16 byte aligned stack, but
+  # that's not guaranteed
+  if host_machine.cpu_family() == 'x86'
+    sse41_args += '-mstackrealign'
+  endif
+else
+  with_sse41 = false
+  sse41_args = []
+endif
 
 # Check for GCC style atomics
 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index b839fd02981..05a3a9ac55d 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -592,9 +592,6 @@ files_libmesa_gallium = files(
   'state_tracker/st_vdpau.h',
 )
 
-# TODO: sse41
-libmesa_sse41 = []
-
 matypes_h = []
 if with_asm_arch == 'x86' or with_asm_arch == 'x86_64'
   gen_matypes = executable(
@@ -692,6 +689,17 @@ files_libmesa_common += [
   sha1_h,
 ]
 
+if with_sse41
+  libmesa_sse41 = static_library(
+    'mesa_sse41',
+    files('main/streaming-load-memcpy.c', 'main/sse_minmax.c'),
+    c_args : [c_vis_args, c_msvc_compat_args, sse41_args],
+    include_directories : inc_common,
+  )
+else
+  libmesa_sse41 = []
+endif
+
 libmesa_classic = static_library(
   'mesa_classic',
   [files_libmesa_common, files_libmesa_classic],
-- 
2.15.0



More information about the mesa-dev mailing list