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



commit 34c20127ab7c05dc9153c9bc1e3b0296c45116b9
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                   | 18 +++++++-
 app/operations/layer-modes/meson.build | 40 +++++++++++++++---
 libgimpbase/meson.build                |  1 +
 meson.build                            | 76 ++++++++++++++--------------------
 4 files changed, 83 insertions(+), 52 deletions(-)
---
diff --git a/app/gegl/meson.build b/app/gegl/meson.build
index 6cfd438f4a..60ac76525f 100644
--- a/app/gegl/meson.build
+++ b/app/gegl/meson.build
@@ -16,11 +16,22 @@ 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, ],
+  c_args: cpu_exts_defines,
+  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 +46,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..109efff547 100644
--- a/app/operations/layer-modes/meson.build
+++ b/app/operations/layer-modes/meson.build
@@ -1,27 +1,55 @@
-libapplayermodes_sources = [
+libapplayermodes_composite = simd.check('gimpoperationlayermode-composite-simd',
+  sse2: 'gimpoperationlayermode-composite-sse2.c',
+  compiler: cc,
+  include_directories: [ rootInclude, rootAppInclude, ],
+  c_args: cpu_exts_defines,
+  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, ],
+  c_args: cpu_exts_defines,
+  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/libgimpbase/meson.build b/libgimpbase/meson.build
index a688785df2..0b5d0f1953 100644
--- a/libgimpbase/meson.build
+++ b/libgimpbase/meson.build
@@ -110,6 +110,7 @@ libgimpbase = library('gimpbase-' + gimp_api_version,
   c_args: [
     '-DG_LOG_DOMAIN="LibGimpBase"',
     '-DGIMP_BASE_COMPILATION',
+    cpu_exts_defines,
   ],
   vs_module_defs: 'gimpbase.def',
   install: true,
diff --git a/meson.build b/meson.build
index 304c79fe4f..e7cf39b07a 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,41 @@ 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 gives
+# its own #defines and we want to stay backwards compatible with autotools build
+cpu_exts = [
+  { 'flag': '-mmmx', 'define': '-DUSE_MMX' },
+  { 'flag': '-msse', 'define': '-DUSE_SSE' },
+  { 'flag': '-msse2', 'define': '-DCOMPILE_SSE2_INTRINISICS=1' },
+  { 'flag': '-msse4.1', 'define': '-DCOMPILE_SSE4_1_INTRINISICS=1' },
+]
 
-if (get_option('buildtype') == 'release' or
-    get_option('buildtype') == 'debugoptimized')
+cpu_exts_defines = []
+foreach cpu_ext : cpu_exts
+  if cc.has_argument(cpu_ext['flag'])
+    cpu_exts_defines += [ cpu_ext['define'] ]
+  endif
+endforeach
 
-  # 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 host_cpu_family == 'ppc'
+  altivec_args = cc.get_supported_arguments([
+    '-faltivec',
+    '-maltivec',
+    '-mabi=altivec',
+  ])
+
+  if altivec_args != []
+    if host_os.contains('darwin')
+      cpu_exts_defines += [ '-DUSE_ALTIVEC', '-DHAVE_ALTIVEC_SYSCTL' ]
+    elif cc.compiles('''
+      int main() { asm ("vand %v0, %v0, %v0"); return 0; }
+      ''')
+      cpu_exts_defines += [ '-DUSE_ALTIVEC' ]
     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]