Bug 1571613 - basic support for Power ISA SIMD detection (v2). r=glandium
authorCameron Kaiser <spectre@floodgap.com>
Wed, 21 Aug 2019 03:36:55 +0000
changeset 489125 252643ff91c5b12225350e8c02d45e00656f8bb6
parent 489124 9c83333374ef9eeea424ed2ce3cc0496eb872b59
child 489126 6248f85c53133f5a9fb80177e3143357f08d3442
push id36465
push userdvarga@mozilla.com
push dateWed, 21 Aug 2019 16:47:43 +0000
treeherdermozilla-central@4ab60925635c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1571613
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1571613 - basic support for Power ISA SIMD detection (v2). r=glandium Differential Revision: https://phabricator.services.mozilla.com/D42592
build/moz.configure/toolchain.configure
mozglue/build/moz.build
mozglue/build/ppc.cpp
mozglue/build/ppc.h
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1424,16 +1424,31 @@ set_config('PREPROCESS_OPTION', preproce
 
 @depends(target, host)
 def is_windows(target, host):
     return host.kernel == 'WINNT' and target.kernel == 'WINNT'
 
 
 include('windows.configure', when=is_windows)
 
+
+# On Power ISA, determine compiler flags for VMX, VSX and VSX-3.
+
+set_config('PPC_VMX_FLAGS',
+           ['-maltivec'],
+           when=depends(target.cpu)(lambda cpu: cpu.startswith('ppc')))
+
+set_config('PPC_VSX_FLAGS',
+           ['-mvsx'],
+           when=depends(target.cpu)(lambda cpu: cpu.startswith('ppc')))
+
+set_config('PPC_VSX3_FLAGS',
+           ['-mvsx','-mcpu=power9'],
+           when=depends(target.cpu)(lambda cpu: cpu.startswith('ppc')))
+
 # ASAN
 # ==============================================================
 
 js_option('--enable-address-sanitizer', help='Enable Address Sanitizer')
 
 
 @depends(when='--enable-address-sanitizer')
 def asan():
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -89,16 +89,17 @@ if CONFIG['MOZ_WIDGET_TOOLKIT']:
         blocklist_defs = GENERATED_FILES[blocklist_files]
         blocklist_defs.script = 'gen_dll_blocklist_defs.py:gen_blocklists'
         blocklist_defs.inputs = ['WindowsDllBlocklistDefs.in']
         EXPORTS.mozilla += ['!' + hdr for hdr in blocklist_files]
 
     EXPORTS.mozilla += [
         'arm.h',
         'mips.h',
+        'ppc.h',
         'SSE.h',
         'WindowsDllBlocklist.h',
     ]
 
     if CONFIG['CPU_ARCH'].startswith('x86'):
         SOURCES += [
             'SSE.cpp',
         ]
@@ -108,16 +109,21 @@ if CONFIG['MOZ_WIDGET_TOOLKIT']:
             'arm.cpp',
         ]
 
     if CONFIG['CPU_ARCH'].startswith('mips'):
         SOURCES += [
             'mips.cpp',
         ]
 
+    if CONFIG['CPU_ARCH'].startswith('ppc'):
+        SOURCES += [
+            'ppc.cpp',
+        ]
+
     if CONFIG['MOZ_LINKER']:
         USE_LIBS += [
             'zlib',
         ]
 
 USE_LIBS += [
     'mfbt',
 ]
new file mode 100644
--- /dev/null
+++ b/mozglue/build/ppc.cpp
@@ -0,0 +1,64 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* compile-time and runtime tests for whether to use Power ISA-specific
+ * extensions */
+
+#include "ppc.h"
+#include "mozilla/Unused.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(XP_LINUX)
+// Use the getauxval() function if available.
+// ARCH_3_00 wasn't defined until glibc 2.23, so include just in case.
+#  include <sys/auxv.h>
+#  ifndef PPC_FEATURE2_ARCH_3_00
+#    define PPC_FEATURE2_ARCH_3_00 0x00800000
+#  endif
+#endif
+
+const unsigned PPC_FLAG_VMX = 1;
+const unsigned PPC_FLAG_VSX = 2;
+const unsigned PPC_FLAG_VSX3 = 4;
+
+static signed get_ppc_cpu_flags(void) {
+  // This could be expensive, so cache the result.
+  static signed cpu_flags = -1;
+
+  if (cpu_flags > -1) {  // already checked
+    return cpu_flags;
+  }
+  cpu_flags = 0;
+
+#if defined(XP_LINUX)
+  // Try getauxval().
+  unsigned long int cap = getauxval(AT_HWCAP);
+  unsigned long int cap2 = getauxval(AT_HWCAP2);
+
+  if (cap & PPC_FEATURE_HAS_ALTIVEC) {
+    cpu_flags |= PPC_FLAG_VMX;
+  }
+  if (cap & PPC_FEATURE_HAS_VSX) {
+    cpu_flags |= PPC_FLAG_VSX;
+  }
+  if (cap2 & PPC_FEATURE2_ARCH_3_00) {
+    cpu_flags |= PPC_FLAG_VSX3;
+  }
+#else
+  // Non-Linux detection here. Currently, on systems other than Linux,
+  // no CPU SIMD features will be detected.
+#endif
+
+  return cpu_flags;
+}
+
+namespace mozilla {
+namespace ppc_private {
+bool vmx_enabled = !!(get_ppc_cpu_flags() & PPC_FLAG_VMX);
+bool vsx_enabled = !!(get_ppc_cpu_flags() & PPC_FLAG_VSX);
+bool vsx3_enabled = !!(get_ppc_cpu_flags() & PPC_FLAG_VSX3);
+}  // namespace ppc_private
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/mozglue/build/ppc.h
@@ -0,0 +1,47 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* compile-time and runtime tests for whether to use Power ISA-specific
+   extensions */
+
+#ifndef mozilla_ppc_h_
+#define mozilla_ppc_h_
+
+// for definition of MFBT_DATA
+#include "mozilla/Types.h"
+
+namespace mozilla {
+namespace ppc_private {
+extern bool MFBT_DATA vmx_enabled;
+extern bool MFBT_DATA vsx_enabled;
+extern bool MFBT_DATA vsx3_enabled;
+}  // namespace ppc_private
+
+inline bool supports_vmx() {
+#ifdef __powerpc__
+  return ppc_private::vmx_enabled;
+#else
+  return false;
+#endif
+}
+
+inline bool supports_vsx() {
+#ifdef __powerpc__
+  return ppc_private::vsx_enabled;
+#else
+  return false;
+#endif
+}
+
+inline bool supports_vsx3() {
+#ifdef __powerpc__
+  return ppc_private::vsx3_enabled;
+#else
+  return false;
+#endif
+}
+
+}  // namespace mozilla
+
+#endif /* !defined(mozilla_ppc_h_) */