Bug 1536070 - Enable ASM in dav1d for Tier3 platforms. r=TD-Linux
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 22 Mar 2019 14:18:27 +0000
changeset 465747 cc78d8cad2cedab669fddcc804d6282a2af900a2
parent 465746 f2935b75f9dcf8b5816192d7d2b6a01f43f2d029
child 465748 77cafd05c85c01998b90fac9d87e924040de1a90
push id35746
push usershindli@mozilla.com
push dateSat, 23 Mar 2019 09:46:24 +0000
treeherdermozilla-central@02b7484f316b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTD-Linux
bugs1536070
milestone68.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 1536070 - Enable ASM in dav1d for Tier3 platforms. r=TD-Linux Differential Revision: https://phabricator.services.mozilla.com/D24361
media/libdav1d/asm/moz.build
media/libdav1d/moz.build
modules/libpref/init/all.js
toolkit/moz.configure
--- a/media/libdav1d/asm/moz.build
+++ b/media/libdav1d/asm/moz.build
@@ -29,26 +29,34 @@ CFLAGS += [
 stack_alignment = 16
 
 # Attaching config.asm file
 if CONFIG['CPU_ARCH'] == 'x86':
     if CONFIG['OS_TARGET'] == 'WINNT':
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_32/win/' % TOPSRCDIR]
     else:
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_32/' % TOPSRCDIR]
+        # Default stack aligment can be 4 bytes, change it to 16 bytes.
+        if CONFIG['CC_TYPE'] == 'clang':
+            CFLAGS += ['-mstack-alignment=16']
+        elif CONFIG['CC_TYPE'] == 'gcc':
+            CFLAGS += ['-mpreferred-stack-boundary=4']
+
 
 if CONFIG['CPU_ARCH'] == 'x86_64':
-    if CONFIG['OS_TARGET'] == 'Linux':
-        ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/linux/' % TOPSRCDIR]
-    elif CONFIG['OS_TARGET'] == 'Darwin':
+    if CONFIG['OS_TARGET'] == 'Darwin':
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/osx/' % TOPSRCDIR]
     elif CONFIG['OS_TARGET'] == 'WINNT':
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/' % TOPSRCDIR]
+    elif CONFIG['OS_TARGET'] == 'Android':
+        error('Platform %s is not expected' % CONFIG['OS_TARGET'])
     else:
-        error('Platform %s is not expected' % CONFIG['OS_TARGET'])
+        # The rest of the platforms are all Linux flavors
+        # Linux,OpenBSD,NetBSD,FreeBSD,DragonFly,SunOS
+        ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/linux/' % TOPSRCDIR]
 
     if CONFIG['OS_TARGET'] == 'WINNT':
         # Change the default stack alignment (16) to 32 bytes.
         stack_alignment = 32
         if CONFIG['CC_TYPE'] == 'clang':
             CFLAGS += ['-mstack-alignment=32']
         elif CONFIG['CC_TYPE'] == 'gcc':
             CFLAGS += ['-mpreferred-stack-boundary=5']
--- a/media/libdav1d/moz.build
+++ b/media/libdav1d/moz.build
@@ -25,30 +25,47 @@ entrypoint_source_files = [
 ]
 SOURCES += [f for f in entrypoint_source_files]
 
 # Don't export DAV1D_API symbols from libxul
 # see: third_party/dav1d/include/dav1d/common.h
 DEFINES['DAV1D_API'] = ''
 
 if CONFIG['MOZ_DAV1D_ASM']:
-    # Default stack alignment is 16 bytes.
+    DIRS += ['asm']
+
+    # Default stack alignment can be 4 bytes on x86.
+    if CONFIG['CPU_ARCH'] == 'x86':
+        # Update stack alignment to 16 bytes.
+        if CONFIG['CC_TYPE'] == 'clang':
+            CFLAGS += ['-mstack-alignment=16']
+            for ep in entrypoint_source_files:
+                SOURCES[ep].flags += ['-mstackrealign']
+        elif CONFIG['CC_TYPE'] == 'gcc':
+            CFLAGS += ['-mpreferred-stack-boundary=4']
+            for ep in entrypoint_source_files:
+                SOURCES[ep].flags += ['-mincoming-stack-boundary=2']
+
+    # Expect stack alignment of 16 bytes.
     stack_alignment = 16
-    DIRS += ['asm']
+
+    # The default stack alignment in x86_64 is 16 bytes. On all Linux flavors the
+    # default is used due to crashes with 32 bytes stack alignment.
     if CONFIG['OS_TARGET'] == 'WINNT' and CONFIG['CPU_ARCH'] == 'x86_64':
         stack_alignment = 32
         # Update stack alignment to 32 bytes.
         if CONFIG['CC_TYPE'] == 'clang':
             CFLAGS += ['-mstack-alignment=32']
             for ep in entrypoint_source_files:
                 SOURCES[ep].flags += ['-mstackrealign']
         elif CONFIG['CC_TYPE'] == 'gcc':
             CFLAGS += ['-mpreferred-stack-boundary=5']
             for ep in entrypoint_source_files:
                 SOURCES[ep].flags += ['-mincoming-stack-boundary=4']
+
     # Set the macro here instead of config.h
     DEFINES['STACK_ALIGNMENT'] = stack_alignment
 
 if CONFIG['OS_TARGET'] == 'Linux':
     # For fuzzing, We only support building on Linux currently.
     include('/tools/fuzzing/libfuzzer-config.mozbuild')
     if CONFIG['FUZZING_INTERFACES']:
         TEST_DIRS += [
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -658,17 +658,17 @@ pref("media.cubeb.sandbox", false);
 
 #ifdef MOZ_AV1
 #if defined(XP_WIN) && !defined(_ARM64_)
 pref("media.av1.enabled", true);
 pref("media.av1.use-dav1d", true);
 #elif defined(XP_MACOSX)
 pref("media.av1.enabled", true);
 pref("media.av1.use-dav1d", true);
-#elif defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID)
+#elif defined(XP_UNIX) && !defined(MOZ_WIDGET_ANDROID)
 pref("media.av1.enabled", true);
 pref("media.av1.use-dav1d", true);
 #else
 pref("media.av1.enabled", false);
 pref("media.av1.use-dav1d", false);
 #endif
 #endif
 
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -438,21 +438,17 @@ option('--disable-av1',
 
 @depends('--enable-av1')
 def av1(value):
     if value:
         return True
 
 @depends(target, nasm_version, when=av1 & compile_environment)
 def dav1d_asm(target, nasm_version):
-    if (
-            target.os == 'GNU' and target.kernel == 'Linux' and target.cpu in ('x86', 'x86_64') or
-            target.os == 'WINNT' and target.cpu in ('x86', 'x86_64') or
-            target.os == 'OSX' and target.kernel == 'Darwin' and target.cpu == 'x86_64'
-       ):
+    if target.os != 'Android' and target.cpu in ('x86', 'x86_64'):
         if nasm_version < '2.13':
             die('nasm 2.13 or greater is required for AV1 support. '
                 'Either install nasm or add --disable-av1 to your configure options.')
         return True
 
 
 set_config('MOZ_DAV1D_ASM', dav1d_asm)
 set_define('MOZ_DAV1D_ASM', dav1d_asm)