Bug 1521062 - Configure assembly builds for libdav1d on Windows. r=TD-Linux
authorAlex Chronopoulos <achronop@gmail.com>
Thu, 07 Mar 2019 09:32:15 +0000
changeset 462834 5fb9ad2446bc49615d9d658108d2f52747ad1f9a
parent 462833 4db188219e4779e107bf352bea309600f70320f9
child 462835 44d8a4dbe146fb84464b66634e94c6c00a8d066d
push id35661
push useraiakab@mozilla.com
push dateThu, 07 Mar 2019 21:56:20 +0000
treeherdermozilla-central@ca64604d4b78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTD-Linux
bugs1521062
milestone67.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 1521062 - Configure assembly builds for libdav1d on Windows. r=TD-Linux Differential Revision: https://phabricator.services.mozilla.com/D22080
media/libdav1d/asm/moz.build
media/libdav1d/asm/x86_32/win/config.asm
media/libdav1d/config.h
media/libdav1d/moz.build
toolkit/moz.configure
--- a/media/libdav1d/asm/moz.build
+++ b/media/libdav1d/asm/moz.build
@@ -20,55 +20,68 @@ LOCAL_INCLUDES += [
 # see: third_party/dav1d/include/dav1d/common.h
 DEFINES['DAV1D_API'] = ''
 
 CFLAGS += [
     # find the config.h file.
     '-I%s/dist/include/dav1d/' % TOPOBJDIR,
 ]
 
-# This is Linux only for now
+# This code is only built on Windows and Linux for now.
 
 # Attaching config.asm file
 if CONFIG['CPU_ARCH'] == 'x86':
-    ASFLAGS += ['-I%s/media/libdav1d/asm/x86_32/' % TOPSRCDIR]
+    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]
 
 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':
+        ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/osx/' % TOPSRCDIR]
+    elif CONFIG['OS_TARGET'] == 'WINNT':
+        ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/' % TOPSRCDIR]
+    else:
+        error('Platform %s is not expected' % CONFIG['OS_TARGET'])
+
+    if CONFIG['OS_TARGET'] in ('Darwin', 'WINNT'):
         # Change the default stack aligment (16) to 32
         if CONFIG['CC_TYPE'] == 'clang':
             CFLAGS += ['-mstack-alignment=32']
         elif CONFIG['CC_TYPE'] == 'gcc':
             CFLAGS += ['-mpreferred-stack-boundary=5']
-        ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/osx/' % TOPSRCDIR]
-    else:
-        ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/' % TOPSRCDIR]
 
 if CONFIG['CPU_ARCH'] in ('x86', 'x86_64'):
     SOURCES += [
         '../../../third_party/dav1d/src/x86/cpu.c',
     ]
 
     EXPORTS.dav1d += [
         '../../../third_party/dav1d/src/x86/cpu.h',
     ]
 
     # ASM source files
+    if CONFIG['CPU_ARCH'] == 'x86_64':
+        # Empty file on all other archs. Nasm produces
+        # an error when it compiles empty files.
+        SOURCES += [
+            '../../../third_party/dav1d/src/x86/cdef.asm',
+            '../../../third_party/dav1d/src/x86/ipred.asm',
+            '../../../third_party/dav1d/src/x86/itx.asm',
+            '../../../third_party/dav1d/src/x86/loopfilter.asm',
+            '../../../third_party/dav1d/src/x86/looprestoration.asm',
+            '../../../third_party/dav1d/src/x86/mc.asm',
+        ]
+
     SOURCES += [
-        '../../../third_party/dav1d/src/x86/cdef.asm',
         '../../../third_party/dav1d/src/x86/cpuid.asm',
-        '../../../third_party/dav1d/src/x86/ipred.asm',
         '../../../third_party/dav1d/src/x86/ipred_ssse3.asm',
-        '../../../third_party/dav1d/src/x86/itx.asm',
         '../../../third_party/dav1d/src/x86/itx_ssse3.asm',
-        '../../../third_party/dav1d/src/x86/loopfilter.asm',
-        '../../../third_party/dav1d/src/x86/looprestoration.asm',
-        '../../../third_party/dav1d/src/x86/mc.asm',
         '../../../third_party/dav1d/src/x86/mc_ssse3.asm',
     ]
 
     # BITDEPTH
     relative_path = '../../../third_party/dav1d/src/x86/'
     bitdepth_basenames = [
         'cdef_init_tmpl.c',
         'ipred_init_tmpl.c',
new file mode 100644
--- /dev/null
+++ b/media/libdav1d/asm/x86_32/win/config.asm
@@ -0,0 +1,13 @@
+; Autogenerated by the Meson build system.
+; Do not edit, your changes will be lost.
+
+%define ARCH_X86_32 1
+
+%define ARCH_X86_64 0
+
+%define PIC 1
+
+%define PREFIX 1
+
+%define STACK_ALIGNMENT 16
+
--- a/media/libdav1d/config.h
+++ b/media/libdav1d/config.h
@@ -31,31 +31,38 @@
 #  define ARCH_X86 0
 #endif
 
 // Set both bitdepeth in every case
 #define CONFIG_16BPC 1
 #define CONFIG_8BPC 1
 
 // Enable asm
-#if (ARCH_x86_32 == 1 || ARCH_X86_64 == 1) && defined(__linux__) && \
-    !defined(__ANDROID__)
+#if defined(MOZ_DAV1D_ASM)
 #  define HAVE_ASM 1
 #else
 #  define HAVE_ASM 0
 #endif
 
 // The following macros are defined from autoconf
 // according to the system configuration.
 // (HAVE_MEMALIGN | HAVE_ALIGNED_MALLOC | HAVE_POSIX_MEMALIGN)
 // HAVE_UNISTD_H
 
 // Important when asm is enabled
-#if defined(__APPLE__)
+#if defined(__APPLE__) || \
+    (ARCH_x86_32 == 1 && defined(_WIN32))
 #  define PREFIX 1
 #endif
 
 #if (ARCH_x86_32 == 1 || ARCH_X86_64 == 1) && defined(__linux__) && \
     !defined(__ANDROID__)
 #  define STACK_ALIGNMENT 16
 #else
 #  define STACK_ALIGNMENT 32
 #endif
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+// _WIN32_WINNT 0x0601 is set in global macros
+#define UNICODE 1
+#define _UNICODE 1
+#define __USE_MINGW_ANSI_STDIO 1
+#endif
--- a/media/libdav1d/moz.build
+++ b/media/libdav1d/moz.build
@@ -14,28 +14,39 @@ LOCAL_INCLUDES += [
 ]
 
 EXPORTS.dav1d += [
     'config.h',
     'version.h',
 ]
 
 # entrypoint source files
-SOURCES += [
+entrypoint_source_files = [
     '../../third_party/dav1d/src/lib.c',
     '../../third_party/dav1d/src/thread_task.c',
 ]
+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 aligment is 16 bytes
     DIRS += ['asm']
+    if CONFIG['OS_TARGET'] == 'WINNT' and CONFIG['CPU_ARCH'] == 'x86_64':
+         # Update stack aligment 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']
 
 # common sources
 SOURCES += [
     '../../third_party/dav1d/src/cdf.c',
     '../../third_party/dav1d/src/cpu.c',
     '../../third_party/dav1d/src/data.c',
     '../../third_party/dav1d/src/decode.c',
     '../../third_party/dav1d/src/dequant_tables.c',
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -438,24 +438,28 @@ 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'):
+    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')
+       ):
         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)
 set_config('MOZ_AV1', av1)
 set_define('MOZ_AV1', av1)
 
 # Built-in fragmented MP4 support.
 # ==============================================================
 option('--disable-fmp4', env='MOZ_FMP4',
        help='Disable support for in built Fragmented MP4 parsing')