Commit 01d7deaf authored by Loren Merritt's avatar Loren Merritt

cosmetics: merge x86inc*.asm

parent 3b6d783f
......@@ -23,24 +23,25 @@ endif
ifneq ($(AS),)
X86SRC0 = cabac-a.asm dct-a.asm deblock-a.asm mc-a.asm mc-a2.asm \
pixel-a.asm predict-a.asm quant-a.asm sad-a.asm \
cpu-32.asm dct-32.asm x86util.asm
cpu-32.asm dct-32.asm
X86SRC = $(X86SRC0:%=common/x86/%)
ifeq ($(ARCH),X86)
SRCS += common/x86/mc-c.c common/x86/predict-c.c
ASMSRC = $(X86SRC) common/x86/pixel-32.asm
OBJASM = $(ASMSRC:%.asm=%.o)
ASFLAGS += -Icommon/x86/
$(OBJASM): common/x86/x86inc.asm common/x86/x86inc-32.asm
checkasm: tools/checkasm-a.o
ARCH_X86 = yes
ASMSRC = $(X86SRC) common/x86/pixel-32.asm
endif
ifeq ($(ARCH),X86_64)
ARCH_X86 = yes
ASMSRC = $(X86SRC:-32.asm=-64.asm)
ASFLAGS += -DARCH_X86_64
endif
ifdef ARCH_X86
ASFLAGS += -Icommon/x86/
SRCS += common/x86/mc-c.c common/x86/predict-c.c
ASMSRC = $(X86SRC:-32.asm=-64.asm)
OBJASM = $(ASMSRC:%.asm=%.o)
ASFLAGS += -Icommon/x86/ -DARCH_X86_64
$(OBJASM): common/x86/x86inc.asm common/x86/x86inc-64.asm
$(OBJASM): common/x86/x86inc.asm common/x86/x86util.asm
checkasm: tools/checkasm-a.o
endif
endif
......
;*****************************************************************************
;* x86inc-32.asm: h264 encoder library
;*****************************************************************************
;* Copyright (C) 2006-2008 x264 project
;*
;* Authors: Sam Hocevar <sam@zoy.org>
;* Loren Merritt <lorenm@u.washington.edu>
;*
;* This program is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 of the License, or
;* (at your option) any later version.
;*
;* This program is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;* GNU General Public License for more details.
;*
;* You should have received a copy of the GNU General Public License
;* along with this program; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
;*****************************************************************************
BITS 32
; Name of the .rodata section. On OS X we cannot use .rodata because NASM
; is unable to compute address offsets outside of .text so we use the .text
; section instead until NASM is fixed.
%macro SECTION_RODATA 0
%ifidn __OUTPUT_FORMAT__,macho
SECTION .text align=16
fakegot:
%else
SECTION .rodata align=16
%endif
%endmacro
; PIC support macros. All these macros are totally harmless when __PIC__ is
; not defined but can ruin everything if misused in PIC mode. On x86, shared
; objects cannot directly access global variables by address, they need to
; go through the GOT (global offset table). Most OSes do not care about it
; and let you load non-shared .so objects (Linux, Win32...). However, OS X
; requires PIC code in its .dylib objects.
;
; - GLOBAL should be used as a suffix for global addressing, eg.
; picgetgot ebx
; mov eax, [foo GLOBAL]
; instead of
; mov eax, [foo]
;
; - picgetgot computes the GOT address into the given register in PIC
; mode, otherwise does nothing. You need to do this before using GLOBAL.
; Before in both execution order and compiled code order (so GLOBAL knows
; which register the GOT is in).
;
; - picpush and picpop respectively push and pop the given register
; in PIC mode, otherwise do nothing. You should always use them around
; picgetgot except when sure that the register is no longer used and is
; being restored later by other means.
;
; - picesp is defined to compensate the changing of esp when pushing
; a register into the stack, eg.
; mov eax, [esp + 8]
; pushpic ebx
; mov eax, [picesp + 12]
; instead of
; mov eax, [esp + 8]
; pushpic ebx
; mov eax, [esp + 12]
;
%ifdef __PIC__
%define PIC32
%ifidn __OUTPUT_FORMAT__,macho
; There is no real global offset table on OS X, but we still
; need to reference our variables by offset.
%define GOT_reg(x) - fakegot + x
%macro picgetgot 1
call %%getgot
%%getgot:
pop %1
add %1, $$ - %%getgot
%undef GLOBAL
%define GLOBAL GOT_reg(%1)
%endmacro
%else
%ifidn __OUTPUT_FORMAT__,elf
%define GOT _GLOBAL_OFFSET_TABLE_
%else ; for a.out
%define GOT __GLOBAL_OFFSET_TABLE_
%endif
extern GOT
%define GOT_reg(x) + x wrt ..gotoff
%macro picgetgot 1
call %%getgot
%%getgot:
pop %1
add %1, GOT + $$ - %%getgot wrt ..gotpc
%undef GLOBAL
%define GLOBAL GOT_reg(%1)
%endmacro
%endif
%macro picpush 1
push %1
%endmacro
%macro picpop 1
pop %1
%endmacro
%define picesp esp+4
%else
%define GLOBAL
%macro picgetgot 1
%endmacro
%macro picpush 1
%endmacro
%macro picpop 1
%endmacro
%define picesp esp
%endif
;*****************************************************************************
;* x86inc-64.asm: h264 encoder library
;*****************************************************************************
;* Copyright (C) 2005-2008 Loren Merritt <lorenm@u.washington.edu>
;*
;* This program is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 of the License, or
;* (at your option) any later version.
;*
;* This program is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;* GNU General Public License for more details.
;*
;* You should have received a copy of the GNU General Public License
;* along with this program; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
;*****************************************************************************
BITS 64
; FIXME: All of the 64bit asm functions that take a stride as an argument
; via register, assume that the high dword of that register is filled with 0.
; This is true in practice (since we never do any 64bit arithmetic on strides,
; and x264's strides are all positive), but is not guaranteed by the ABI.
; Name of the .rodata section. On OS X we cannot use .rodata because YASM
; is unable to compute address offsets outside of .text so we use the .text
; section instead until YASM is fixed.
%macro SECTION_RODATA 0
%ifidn __OUTPUT_FORMAT__,macho64
SECTION .text align=16
%else
SECTION .rodata align=16
%endif
%endmacro
; PIC support macros. On x86_64 we just use RIP-relative addressing, which is
; much simpler than the GOT handling we need to perform on x86.
;
; - GLOBAL should be used as a suffix for global addressing, eg.
; mov eax, [foo GLOBAL]
; instead of
; mov eax, [foo]
;
%ifdef __PIC__
%define GLOBAL wrt rip
%define PIC64
%else
%define GLOBAL
%endif
%macro picgetgot 1
%endmacro
;*****************************************************************************
;* x86inc.asm
;*****************************************************************************
;* Copyright (C) 2008 Loren Merritt <lorenm@u.washington.edu>
;* Copyright (C) 2005-2008 Loren Merritt <lorenm@u.washington.edu>
;*
;* This program is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
......@@ -18,10 +18,76 @@
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
;*****************************************************************************
%ifdef ARCH_X86_64
%include "x86inc-64.asm"
; FIXME: All of the 64bit asm functions that take a stride as an argument
; via register, assume that the high dword of that register is filled with 0.
; This is true in practice (since we never do any 64bit arithmetic on strides,
; and x264's strides are all positive), but is not guaranteed by the ABI.
; Name of the .rodata section.
; Kludge: Something on OS X fails to align .rodata even given an align attribute,
; so use a different read-only section.
%macro SECTION_RODATA 0
%ifidn __OUTPUT_FORMAT__,macho64
SECTION .text align=16
%elifidn __OUTPUT_FORMAT__,macho
SECTION .text align=16
fakegot:
%else
SECTION .rodata align=16
%endif
%endmacro
; PIC support macros. All these macros are totally harmless when __PIC__ is
; not defined but can ruin everything if misused in PIC mode. On x86_32, shared
; objects cannot directly access global variables by address, they need to
; go through the GOT (global offset table). Most OSes do not care about it
; and let you load non-shared .so objects (Linux, Win32...). However, OS X
; requires PIC code in its .dylib objects.
;
; - GLOBAL should be used as a suffix for global addressing, eg.
; picgetgot ebx
; mov eax, [foo GLOBAL]
; instead of
; mov eax, [foo]
;
; - picgetgot computes the GOT address into the given register in PIC
; mode, otherwise does nothing. You need to do this before using GLOBAL.
; Before in both execution order and compiled code order (so GLOBAL knows
; which register the GOT is in).
%ifndef __PIC__
%define GLOBAL
%macro picgetgot 1
%endmacro
%elifdef ARCH_X86_64
%define PIC64
%define GLOBAL wrt rip
%macro picgetgot 1
%endmacro
%else
%include "x86inc-32.asm"
%define PIC32
%ifidn __OUTPUT_FORMAT__,macho
; There is no real global offset table on OS X, but we still
; need to reference our variables by offset.
%macro picgetgot 1
call %%getgot
%%getgot:
pop %1
add %1, $$ - %%getgot
%undef GLOBAL
%define GLOBAL + %1 - fakegot
%endmacro
%else ; elf
extern _GLOBAL_OFFSET_TABLE_
%macro picgetgot 1
call %%getgot
%%getgot:
pop %1
add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%getgot wrt ..gotpc
%undef GLOBAL
%define GLOBAL + %1 wrt ..gotoff
%endmacro
%endif
%endif
; Macros to eliminate most code duplication between x86_32 and x86_64:
......@@ -387,7 +453,7 @@ INIT_MMX
CAT_XDEFINE n, m%2, %2
%else
; If we were called as "SWAP m0,m1" rather than "SWAP 0,1" infer the original numbers here.
; Be careful using the mode in nested macros though, as in some cases there may be
; Be careful using this mode in nested macros though, as in some cases there may be
; other copies of m# that have already been dereferenced and don't get updated correctly.
%xdefine %%n1 n %+ %1
%xdefine %%n2 n %+ %2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment