[gimp/wip/nielsdg/conditional-cpu-exts: 158/158] meson: Always enable CPU extensions




commit 27156b8b15a5d7702d270d40a7a0b6b2c374e0cd
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Tue May 12 12:47:00 2020 +0200

    meson: Always enable CPU extensions
    
    Don't enable conditionally based on the buildtype.
    
    Further, don't use `add_project_arguments()` to enable the instructions:
    this will lead to crashes within g-ir-scanner, which can't properly
    parse these instructions.
    
    https://gitlab.gnome.org/GNOME/gimp/-/issues/5053

 app/gegl/meson.build                   | 17 ++++++++-
 app/operations/layer-modes/meson.build | 38 +++++++++++++++---
 meson.build                            | 70 ++++++++++++----------------------
 3 files changed, 72 insertions(+), 53 deletions(-)
---
diff --git a/app/gegl/meson.build b/app/gegl/meson.build
index 6cfd438f4a..a83c9771f6 100644
--- a/app/gegl/meson.build
+++ b/app/gegl/meson.build
@@ -16,11 +16,21 @@ appgeglenums = custom_target('gimp-gegl-enums.c',
   capture: true,
 )
 
+libappgegl_loops = simd.check('gimp-gegl-loops-simd',
+  sse2: 'gimp-gegl-loops-sse2.c',
+  compiler: cc,
+  include_directories: [ rootInclude, rootAppInclude, ],
+  dependencies: [
+    cairo,
+    gegl,
+    gdk_pixbuf,
+  ],
+)
+
 libappgegl_sources = [
   'gimp-babl-compat.c',
   'gimp-babl.c',
   'gimp-gegl-apply-operation.c',
-  'gimp-gegl-loops-sse2.c',
   'gimp-gegl-loops.cc',
   'gimp-gegl-mask-combine.cc',
   'gimp-gegl-mask.c',
@@ -35,9 +45,12 @@ libappgegl_sources = [
 
 libappgegl = static_library('appgegl',
   libappgegl_sources,
+  link_with: libappgegl_loops[0],
   include_directories: [ rootInclude, rootAppInclude, ],
   c_args: '-DG_LOG_DOMAIN="Gimp-GEGL"',
   dependencies: [
-    cairo, gegl, gdk_pixbuf,
+    cairo,
+    gegl,
+    gdk_pixbuf,
   ],
 )
diff --git a/app/operations/layer-modes/meson.build b/app/operations/layer-modes/meson.build
index 5031c4a344..0cf03134d7 100644
--- a/app/operations/layer-modes/meson.build
+++ b/app/operations/layer-modes/meson.build
@@ -1,27 +1,53 @@
-libapplayermodes_sources = [
+libapplayermodes_composite = simd.check('gimpoperationlayermode-composite-simd',
+  sse2: 'gimpoperationlayermode-composite-sse2.c',
+  compiler: cc,
+  include_directories: [ rootInclude, rootAppInclude, ],
+  dependencies: [
+    cairo,
+    gegl,
+    gdk_pixbuf,
+  ],
+)
+
+libapplayermodes_normal = simd.check('gimpoperationnormal-simd',
+  sse2: 'gimpoperationnormal-sse2.c',
+  sse41: 'gimpoperationnormal-sse4.c',
+  compiler: cc,
+  include_directories: [ rootInclude, rootAppInclude, ],
+  dependencies: [
+    cairo,
+    gegl,
+    gdk_pixbuf,
+  ],
+)
+
+libapplayermodes_sources = files(
   'gimp-layer-modes.c',
   'gimpoperationantierase.c',
   'gimpoperationbehind.c',
   'gimpoperationdissolve.c',
   'gimpoperationerase.c',
   'gimpoperationlayermode-blend.c',
-  'gimpoperationlayermode-composite-sse2.c',
   'gimpoperationlayermode-composite.c',
   'gimpoperationlayermode.c',
   'gimpoperationmerge.c',
-  'gimpoperationnormal-sse2.c',
-  'gimpoperationnormal-sse4.c',
   'gimpoperationnormal.c',
   'gimpoperationpassthrough.c',
   'gimpoperationreplace.c',
   'gimpoperationsplit.c',
-]
+)
 
 libapplayermodes = static_library('applayermodes',
   libapplayermodes_sources,
+  link_with: [
+    libapplayermodes_composite[0],
+    libapplayermodes_normal[0],
+  ],
   include_directories: [ rootInclude, rootAppInclude, ],
   c_args: '-DG_LOG_DOMAIN="Gimp-Layer-Modes"',
   dependencies: [
-    cairo, gegl, gdk_pixbuf,
+    cairo,
+    gegl,
+    gdk_pixbuf,
   ],
 )
diff --git a/meson.build b/meson.build
index 7222ec61d7..d42c0dd95c 100644
--- a/meson.build
+++ b/meson.build
@@ -91,6 +91,7 @@ pkgconfig = import('pkgconfig')
 i18n      = import('i18n')
 gnome     = import('gnome')
 pythonmod = import('python')
+simd      = import('unstable-simd')
 
 cc        = meson.get_compiler('c')
 cxx       = meson.get_compiler('cpp')
@@ -178,54 +179,33 @@ endif
 
 ################################################################################
 # Compiler CPU extensions for optimizations
+# -- Don't enable these project-wide, since some tools like g-ir-scanner,
+#    will crash on them.
+
+# Note that Meson has a SIMD module which can also do this for us, but it uses
+# its own #defines and we want to stay compatible with the autotools build
+conf.set('USE_MMX', cc.has_argument('-mmx'))
+conf.set('USE_SSE', cc.has_argument('-sse'))
+conf.set10('COMPILE_SSE2_INTRINISICS', cc.has_argument('-msse2'))
+conf.set10('COMPILE_SSE4_1_INTRINISICS', cc.has_argument('-msse4.1'))
+
+if host_cpu_family == 'ppc'
+  altivec_args = cc.get_supported_arguments([
+    '-faltivec',
+    '-maltivec',
+    '-mabi=altivec',
+  ])
 
-if (get_option('buildtype') == 'release' or
-    get_option('buildtype') == 'debugoptimized')
-
-  # Check for compiler CPU extensions
-  existing_cpu_exts = [
-    '-mfpmath=sse',
-    '-mmmx',
-    '-msse',
-    '-msse2',
-    '-msse4.1',
-  ]
-  supported_cpu_exts = cc.get_supported_arguments(existing_cpu_exts)
-
-  compiler_args += supported_cpu_exts
-
-  conf.set  ('USE_MMX',                   '-mmmx'    in supported_cpu_exts)
-  conf.set  ('USE_SSE',                   '-msse'    in supported_cpu_exts)
-  conf.set10('COMPILE_SSE2_INTRINISICS',  '-msse2'   in supported_cpu_exts)
-  conf.set10('COMPILE_SSE4_1_INTRINISICS','-msse4.1' in supported_cpu_exts)
-
-
-  have_altivec        = false
-  have_altivec_sysctl = false
-  if host_cpu_family == 'ppc'
-    altivec_args = cc.get_supported_arguments([
-      '-faltivec',
-      '-maltivec',
-      '-mabi=altivec',
-    ])
-
-    if altivec_args != []
-      compiler_args += altivec_args
-      linker_args   += altivec_args
-
-      if host_os.contains('darwin')
-        have_altivec = true
-        have_altivec_sysctl = true
-      elif cc.compiles('''
-        int main() { asm ("vand %v0, %v0, %v0"); return 0; }
-        ''')
-        have_altivec = true
-      endif
+  if altivec_args != []
+    if host_os.contains('darwin')
+      conf.set('USE_ALTIVEC', true)
+      conf.set('HAVE_ALTIVEC_SYSCTL', true)
+    elif cc.compiles('''
+      int main() { asm ("vand %v0, %v0, %v0"); return 0; }
+      ''')
+      conf.set('USE_ALTIVEC', true)
     endif
   endif
-  conf.set('HAVE_ALTIVEC_SYSCTL', have_altivec_sysctl)
-  conf.set('USE_ALTIVEC',         have_altivec)
-
 endif
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]