Bug 583849 - Use YASM to compile libvpx on Windows. r=ted, a2.0=blocking

This commit is contained in:
Justin Lebar 2010-08-11 16:37:24 -07:00
Родитель 215062605a
Коммит 84ca22aa38
5 изменённых файлов: 69 добавлений и 420 удалений

Просмотреть файл

@ -4682,6 +4682,26 @@ else
fi
fi
dnl ======================
dnl Detect yasm
dnl ======================
AC_MSG_CHECKING([for YASM assembler])
AC_CHECK_PROGS(YASM, yasm, "")
if test -n "$YASM"; then
dnl Pull out yasm's version string
changequote(,)
_YASM_VER_FILTER='s|.* ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*|\1|p'
changequote([,])
YASM_VERSION=`yasm --version | sed -nre "$_YASM_VER_FILTER"`
_YASM_MAJOR_VERSION=`echo ${YASM_VERSION} | $AWK -F\. '{ print $1 }'`
_YASM_MINOR_VERSION=`echo ${YASM_VERSION} | $AWK -F\. '{ print $2 }'`
_YASM_RELEASE=` echo ${YASM_VERSION} | $AWK -F\. '{ print $3 }'`
_YASM_BUILD=` echo ${YASM_VERSION} | $AWK -F\. '{ print $4 }'`
fi
if test -z "$SKIP_LIBRARY_CHECKS"; then
dnl system JPEG support
dnl ========================================================
@ -5943,64 +5963,62 @@ if test -n "$MOZ_WEBM"; then
MOZ_VORBIS=1
dnl Detect if we can use an assembler to compile optimized assembly for libvpx.
dnl For Win32 (MSVC) we must use MASM.
if test "$OS_ARCH" = "WINNT" -a "$CPU_ARCH" = "x86" -a -z "$GNU_CC"; then
AC_MSG_CHECKING([for MASM assembler])
AC_CHECK_PROGS(VPX_AS, ml, "")
if test -n "$VPX_AS"; then
VPX_X86_ASM=1
VPX_AS='sh $(topsrcdir)/media/libvpx/yasm2masm-as.sh'
else
AC_MSG_ERROR([Need MASM (ml.exe) in order to assemble libvpx optimized assembly. Either disable webm (reconfigure with --disable-webm) or install MASM. MASM is included in the Windows 7 SDK, or you can download MASM directly from http://www.microsoft.com/downloads/details.aspx?familyid=7a1c9da0-0510-44a2-b042-7ef370530c64&displaylang=en])
fi
else
dnl We currently require yasm on all platforms and require yasm 1.1.0 on Win32.
VPX_AS=$YASM
dnl For Darwin x86, Darwin x86_64, Linux x86, and WINNT x86_64
dnl we can use YASM.
AC_MSG_CHECKING([for YASM assembler])
AC_CHECK_PROGS(VPX_AS, $YASM yasm, "")
dnl We have YASM, see if we have assembly on this platform.
case "$OS_ARCH:$OS_TEST" in
Linux:x86|Linux:i?86)
VPX_ASFLAGS="-f elf32 -rnasm -pnasm"
dnl See if we have assembly on this platform.
case "$OS_ARCH:$CPU_ARCH" in
Linux:x86)
VPX_ASFLAGS="-f elf32 -rnasm -pnasm"
VPX_X86_ASM=1
;;
Linux:x86_64)
VPX_ASFLAGS="-f elf64 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
SunOS:x86)
VPX_ASFLAGS="-f elf32 -rnasm -pnasm"
VPX_X86_ASM=1
;;
SunOS:x86_64)
VPX_ASFLAGS="-f elf64 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
Darwin:x86)
VPX_ASFLAGS="-f macho32 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
Darwin:x86_64)
VPX_ASFLAGS="-f macho64 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
WINNT:x86_64)
if test -z "$GNU_CC"; then
VPX_ASFLAGS="-f x64 -rnasm -pnasm"
VPX_X86_ASM=1
;;
Linux:x86_64)
VPX_ASFLAGS="-f elf64 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
SunOS:i?86)
VPX_ASFLAGS="-f elf32 -rnasm -pnasm"
VPX_X86_ASM=1
;;
SunOS:x86_64)
VPX_ASFLAGS="-f elf64 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
Darwin:i?86)
VPX_ASFLAGS="-f macho32 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
Darwin:x86_64)
VPX_ASFLAGS="-f macho64 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
;;
WINNT:x86_64)
if test -z "$GNU_CC"; then
VPX_ASFLAGS="-f x64 -rnasm -pnasm"
VPX_X86_ASM=1
fi
;;
esac
if test "$COMPILE_ENVIRONMENT" -a -n "$VPX_X86_ASM" -a -z "$VPX_AS"; then
AC_MSG_ERROR([yasm is a required build tool for this architecture when webm is enabled. You may either install yasm or --disable-webm (which disables the WebM video format). See https://developer.mozilla.org/en/YASM for more details.])
fi
fi # end !WINNT_x86_MSVC
;;
WINNT:x86)
if test -z "$GNU_CC"; then
dnl Check for yasm 1.1 or greater.
if test "$_YASM_MAJOR_VERSION" -gt "1" -o \( "$_YASM_MAJOR_VERSION" -eq "1" -a "$_YASM_MINOR_VERSION" -ge "1" \) ; then
VPX_ASFLAGS="-f win32 -rnasm -pnasm -DPIC"
VPX_X86_ASM=1
else
AC_MSG_ERROR([yasm 1.1 or greater is required to build libvpx on Win32, but you appear to have version $_YASM_MAJOR_VERSION.$_YASM_MINOR_VERSION. Upgrade to the newest version (included in MozillaBuild 1.5.1 and newer) or configure with --disable-webm (which disables the WebM video format). See https://developer.mozilla.org/en/YASM for more details.])
fi
fi
;;
esac
if test "$COMPILE_ENVIROMENT" -a -n "$VPX_X86_ASM" -a -z "$VPX_AS"; then
AC_MSG_ERROR([yasm is a required build tool for this architecture when webm is enabled. You may either install yasm or --disable-webm (which disables the WebM video format). See https://developer.mozilla.org/en/YASM for more details.])
fi
if test -n "$VPX_X86_ASM"; then
AC_DEFINE(VPX_X86_ASM)
else
AC_MSG_WARN([No assembler or assembly support for libvpx, using unoptimized C routines.])
AC_MSG_WARN([No assembler or assembly support for libvpx. Using unoptimized C routines.])
fi
fi

Просмотреть файл

@ -191,14 +191,6 @@ ASFILES += \
emms.asm \
$(NULL)
ifeq ($(OS_ARCH),WINNT)
ifneq ($(OS_TEST),x86_64)
ASFILES += \
safeseh.asm \
$(NULL)
endif
endif
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -1,46 +0,0 @@
; ***** BEGIN LICENSE BLOCK *****
; Version: MPL 1.1/GPL 2.0/LGPL 2.1
;
; The contents of this file are subject to the Mozilla Public License Version
; 1.1 (the "License"); you may not use this file except in compliance with
; the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS" basis,
; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
; for the specific language governing rights and limitations under the
; License.
;
; The Original Code is Mozilla code.
;
; The Initial Developer of the Original Code is the Mozilla Foundation.
; Portions created by the Initial Developer are Copyright (C) 2010
; the Initial Developer. All Rights Reserved.
;
; Contributor(s):
; Chris Pearce <chris@pearce.org.nz>
;
; Alternatively, the contents of this file may be used under the terms of
; either the GNU General Public License Version 2 or later (the "GPL"), or
; the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
; in which case the provisions of the GPL or the LGPL are applicable instead
; of those above. If you wish to allow use of your version of this file only
; under the terms of either the GPL or the LGPL, and not to allow others to
; use your version of this file under the terms of the MPL, indicate your
; decision by deleting the provisions above and replace them with the notice
; and other provisions required by the GPL or the LGPL. If you do not delete
; the provisions above, a recipient may use your version of this file under
; the terms of any one of the MPL, the GPL or the LGPL.
;
; ***** END LICENSE BLOCK *****
.686p
.XMM
.model flat, C
option casemap :none ; be case-insensitive
.code
public _MyHandler
_MyHandler:
mov eax,1 ; 1 means let default handler handle exception
ret
end

Просмотреть файл

@ -1,142 +0,0 @@
#!/bin/bash
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla code.
#
# The Initial Developer of the Original Code is the Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Chris Pearce <chris@pearce.org.nz>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
# YASM to MASM syntax translator plus assembler wrapper script.
# Takes standard gcc-style arguments, and calls yasm2masm.py to
# translate the input source file, and then assembles the translated
# file using MASM.
output_file=
input_file=
translate_only=false
includes=
translate_to_masm=true
# Get the path of the script. We assume that yasm2masm.py is in the
# same directory as the script.
path=`dirname $0`
while [ $# -gt 0 ]
do
case $1
in
-o)
if ( test $# -gt 1 ) && ($output_file)
then
output_file=$2
shift 2
else
echo "Supply one output file name with -o argument."
exit 1
fi
;;
-dont-translate)
translate_to_masm=false
shift
;;
-t)
translate_only=true
shift 1
;;
-I)
includes="$includes -I$2"
shift 2
;;
-c)
# ignore -c
shift 1
;;
-I*)
includes="$includes $1"
shift 1
;;
*)
if [ $input_file ]
then
echo "Don't supply two input filenames!"
exit 1
fi
input_file=$1
shift 1
;;
esac
done
translated_file=${output_file}".p"
if ( test -z $input_file ) || (test -z $output_file)
then
echo "YASM-to-MASM translator-compiler wrapper."
echo "Usage:"
echo " yasm2masm-as.sh [-t] -o output_file [-Iinclude1 -I include2] input_file"
echo " -t only runs the translator, storing result in \$output_file.p, does not assemble using MASM."
exit 1
fi
# First run the translator
if [ $translate_to_masm == false ]
then
translated_file=$input_file
else
python ${path}/yasm2masm.py < $input_file > $translated_file
if [ ! $? ]
then
echo "Translation from YASM to MASM syntax failed!"
exit $?
fi
fi
if [ $translate_only == true ]
then
echo "Translated file is in $translated_file"
exit
fi
# Assemble the translated file.
echo "YASM-to-MASM translate-compile: $input_file"
echo "ml -c -Fo $output_file $includes -D __OUTPUT_FORMAT__=win32 -safeseh $translated_file"
ml -c -Fo $output_file $includes -D __OUTPUT_FORMAT__=win32 -safeseh $translated_file
retval=$?
if [ $translate_to_masm == true ]
then
rm ${translated_file}
fi
exit $retval

Просмотреть файл

@ -1,173 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla code.
#
# The Initial Developer of the Original Code is the Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Robert O'Callahan <robert@ocallahan.org>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
# A crude YASM-to-MASM translation script for the VP8 code
import sys, os.path, re
known_extern_types = {
'rand': 'PROC',
'vp8_bilinear_filters_mmx': 'DWORD'
}
comment_re = re.compile(r'(;.*)$')
global_re = re.compile(r'^\s*global ([\w()]+)')
extern_re = re.compile(r'^extern (sym\((\w+)\))')
movd_from_mem_re = re.compile(r'\b(movd\s+x?mm\d,\s*)(\[[^]]+\]|arg\(\d+\))')
movd_to_mem_re = re.compile(r'\b(movd\s*)(\[[^]]+\],\s*x?mm\d)')
label_re = re.compile(r'^\s*([\w()]+):')
times_hex_re = re.compile(r'^\s*times\s+(\d+)\s+(db|dw|dd)\s+0x([0-9a-fA-F]+)')
times_dec_re = re.compile(r'^\s*times\s+(\d+)\s+(db|dw|dd)\s+(-?\d+)')
mem_define_re = re.compile(r'^\s*%define\s*(\w+)\s*(\[[^]]+\])')
num_define_re = re.compile(r'^\s*%define\s*(\w+)\s*(\d+)')
preproc_re = re.compile(r'^\s*%(if|else|endif|elif)\b(.*)$')
ifidn_re = re.compile(r'^\s*%ifidn\b(.*)$')
undef_re = re.compile(r'%undef\s')
size_arg_re = re.compile(r'\b(byte|word|dword)\s+(arg\(\d+\)|\[[^]]+\])')
hex_re = re.compile(r'\b0x([0-9A-Fa-f]+)')
and_expr_re = re.compile(r'^(.*)&&(.*)$')
equal_expr_re = re.compile(r'^(.*)=(.*)$')
section_text_re = re.compile(r'^\s*section .text')
in_data = False
data_label = ''
def translate_expr(s):
if and_expr_re.search(s):
match = and_expr_re.search(s)
return '(' + translate_expr(match.group(1)) + ' and ' + translate_expr(match.group(2)) + ')'
if equal_expr_re.search(s):
match = equal_expr_re.search(s)
return '(' + translate_expr(match.group(1)) + ' eq ' + translate_expr(match.group(2)) + ')'
return s
def type_of_extern(id):
if id in known_extern_types:
return known_extern_types[id]
return 'ABS'
def translate(s):
# Fix include, get rid of quotes and load the special hand-coded win32 preamble
if s == '%include "vpx_ports/x86_abi_support.asm"':
return 'include vpx_ports/x86_abi_support_win32.asm'
if s == '%include "x86_abi_support.asm"':
return 'include x86_abi_support_win32.asm'
# Replace 'global' with 'public'
if global_re.search(s):
return global_re.sub('public \\1', s)
# Add types to externs
if extern_re.search(s):
match = extern_re.search(s)
return extern_re.sub('extern \\1:' + type_of_extern(match.group(2)), s)
# Replace %define with textequ/equ
if mem_define_re.search(s):
return mem_define_re.sub('\\1 textequ <\\2>', s)
if num_define_re.search(s):
return num_define_re.sub('\\1 equ \\2', s)
# Translate conditional compilation directives
if preproc_re.search(s):
match = preproc_re.search(s)
if match.group(1) == 'elif':
return 'elseif ' + translate_expr(match.group(2))
return match.group(1) + translate_expr(match.group(2))
if ifidn_re.search(s):
return 'if 0'
if section_text_re.search(s):
return '.code';
# Remove undefs
if undef_re.search(s):
return ''
# Fix 'movd' to add 'dword ptr' to its memory argument
if movd_from_mem_re.search(s):
return movd_from_mem_re.sub('\\1dword ptr \\2', s)
if movd_to_mem_re.search(s):
return movd_to_mem_re.sub('\\1dword ptr \\2', s)
# Replace byte/word/dword with '... ptr' before 'arg(n)' or memory expressions
if size_arg_re.search(s):
return size_arg_re.sub('\\1 ptr \\2', s)
# Translate data declarations, in particular we need to give data
# labels the correct type
global data_label
if in_data and label_re.search(s):
data_label = label_re.search(s).group(1)
return ''
if in_data and times_hex_re.search(s):
match = times_hex_re.search(s)
if (match.group(1) == '8' and match.group(2) == 'db') or \
(match.group(1) == '4' and match.group(2) == 'dw'):
# make labels for 8-byte quantities have type 'qword'
print data_label + ' equ this qword'
data_label = ''
if match.group(1) == '16' and match.group(2) == 'db':
# make labels for 16-byte quantities have type 'xmmword'
print data_label + ' equ this xmmword'
data_label = ''
s = times_hex_re.sub(data_label + ' \\2 \\1 dup (0\\3h)', s)
data_label = ''
return s
if in_data and times_dec_re.search(s):
s = times_dec_re.sub(data_label + ' \\2 \\1 dup (\\3)', s)
data_label = ''
return s
# Replace 0xABC with ABCh
if hex_re.search(s):
return hex_re.sub('0\\1h', s)
return s
while 1:
try:
s = raw_input()
except EOFError:
break
if s == 'SECTION_RODATA':
in_data = True
print translate(s)
print "end"