Date: 2018.7.22
.s文件:在后期阶段不进行预处理操作,不能写预处理语句;
.S文件:还会进行预处理、汇编等操作,所以可以加入预处理的命令;
即两者的区别在于是否可以包含预处理语句。
下面的asm.S是ffmpeg中arm32的通用预处理头,可以在编写汇编代码时使用。
示例如下:
#include < asm.S >
function loopfilter_4_arm_neon, export=1
.......
.......
endfunc
asm.S如下:
/*
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#ifdef __ELF__
# define ELF
#else
# define ELF @
#endif
#if CONFIG_THUMB
# define A @
# define T
#else
# define A
# define T @
#endif
#if HAVE_AS_FUNC
# define FUNC
#else
# define FUNC @
#endif
#if HAVE_NEON
.arch armv7-a
#elif HAVE_ARMV6T2
.arch armv6t2
#elif HAVE_ARMV6
.arch armv6
#elif HAVE_ARMV5TE
.arch armv5te
#endif
#if HAVE_AS_OBJECT_ARCH
ELF .object_arch armv4
#endif
#if HAVE_NEON
.fpu neon
ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
ELF .eabi_attribute 12, 0 @ suppress Tag_Advanced_SIMD_arch
#elif HAVE_VFP
.fpu vfp
ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
#endif
.syntax unified
T .thumb
ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
.macro function name, export=0, align=2
.set .Lpic_idx, 0
.set .Lpic_gp, 0
.macro endfunc
.if .Lpic_idx
.align 2
.altmacro
put_pic %(.Lpic_idx - 1)
.noaltmacro
.endif
ELF .size
ame, . -
ame
FUNC .endfunc
.purgem endfunc
.endm
.text
.align align
.if export
.global EXTERN_ASM
ame
ELF .type EXTERN_ASM
ame, %function
FUNC .func EXTERN_ASM
ame
EXTERN_ASM
ame:
.else
ELF .type
ame, %function
FUNC .func
ame
ame:
.endif
.endm
.macro const name, align=2, relocate=0
.macro endconst
ELF .size
ame, . -
ame
.purgem endconst
.endm
.if HAVE_SECTION_DATA_REL_RO &&
elocate
.section .data.rel.ro
.else
.section .rodata
.endif
.align align
ame:
.endm
#if !HAVE_ARMV6T2_EXTERNAL
.macro movw rd, val
mov
d, val & 255
orr
d, val & ~255
.endm
#endif
.macro mov32 rd, val
#if HAVE_ARMV6T2_EXTERNAL
movw
d, #(val) & 0xffff
.if (val) >> 16
movt
d, #(val) >> 16
.endif
#else
ldr
d, =val
#endif
.endm
.macro put_pic num
put_pic_
um
.endm
.macro do_def_pic num, val, label
.macro put_pic_
um
.if
um
.altmacro
put_pic %(
um - 1)
.noaltmacro
.endif
label: .word val
.purgem put_pic_
um
.endm
.endm
.macro def_pic val, label
.altmacro
do_def_pic %.Lpic_idx, val, label
.noaltmacro
.set .Lpic_idx, .Lpic_idx + 1
.endm
.macro ldpic rd, val, indir=0
ldr
d, .Lpicoff@
.Lpic@:
.if indir
A ldr
d, [pc,
d]
T add
d, pc
T ldr
d, [
d]
.else
add
d, pc
.endif
def_pic val - (.Lpic@ + (8 >> CONFIG_THUMB)), .Lpicoff@
.endm
.macro movrel rd, val
#if CONFIG_PIC
ldpic
d, val
#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
movw
d, #:lower16:val
movt
d, #:upper16:val
#else
ldr
d, =val
#endif
.endm
.macro movrelx rd, val, gp
#if CONFIG_PIC && defined(__ELF__)
.ifnb gp
.if .Lpic_gp
.unreq gp
.endif
gp .req gp
ldpic gp, _GLOBAL_OFFSET_TABLE_
.elseif !.Lpic_gp
gp .req r12
ldpic gp, _GLOBAL_OFFSET_TABLE_
.endif
.set .Lpic_gp, 1
ldr
d, .Lpicoff@
ldr
d, [gp,
d]
def_pic val(GOT), .Lpicoff@
#elif CONFIG_PIC && defined(__APPLE__)
ldpic
d, .Lpic@, indir=1
.non_lazy_symbol_pointer
.Lpic@:
.indirect_symbol val
.word 0
.text
#else
movrel
d, val
#endif
.endm
.macro add_sh rd, rn, rm, sh:vararg
A add
d,
n,
m, sh
T mov
m,
m, sh
T add
d,
n,
m
.endm
.macro ldr_pre rt, rn, rm:vararg
A ldr
t, [
n,
m]!
T add
n,
n,
m
T ldr
t, [
n]
.endm
.macro ldr_dpre rt, rn, rm:vararg
A ldr
t, [
n, -
m]!
T sub
n,
n,
m
T ldr
t, [
n]
.endm
.macro ldr_nreg rt, rn, rm:vararg
A ldr
t, [
n, -
m]
T sub
t,
n,
m
T ldr
t, [
t]
.endm
.macro ldr_post rt, rn, rm:vararg
A ldr
t, [
n],
m
T ldr
t, [
n]
T add
n,
n,
m
.endm
.macro ldrc_pre cc, rt, rn, rm:vararg
A ldrcc
t, [
n,
m]!
T itt cc
T addcc
n,
n,
m
T ldrcc
t, [
n]
.endm
.macro ldrd_reg rt, rt2, rn, rm
A ldrd
t,
t2, [
n,
m]
T add
t,
n,
m
T ldrd
t,
t2, [
t]
.endm
.macro ldrd_post rt, rt2, rn, rm
A ldrd
t,
t2, [
n],
m
T ldrd
t,
t2, [
n]
T add
n,
n,
m
.endm
.macro ldrh_pre rt, rn, rm
A ldrh
t, [
n,
m]!
T add
n,
n,
m
T ldrh
t, [
n]
.endm
.macro ldrh_dpre rt, rn, rm
A ldrh
t, [
n, -
m]!
T sub
n,
n,
m
T ldrh
t, [
n]
.endm
.macro ldrh_post rt, rn, rm
A ldrh
t, [
n],
m
T ldrh
t, [
n]
T add
n,
n,
m
.endm
.macro ldrb_post rt, rn, rm
A ldrb
t, [
n],
m
T ldrb
t, [
n]
T add
n,
n,
m
.endm
.macro str_post rt, rn, rm:vararg
A str
t, [
n],
m
T str
t, [
n]
T add
n,
n,
m
.endm
.macro strb_post rt, rn, rm:vararg
A strb
t, [
n],
m
T strb
t, [
n]
T add
n,
n,
m
.endm
.macro strd_post rt, rt2, rn, rm
A strd
t,
t2, [
n],
m
T strd
t,
t2, [
n]
T add
n,
n,
m
.endm
.macro strh_pre rt, rn, rm
A strh
t, [
n,
m]!
T add
n,
n,
m
T strh
t, [
n]
.endm
.macro strh_dpre rt, rn, rm
A strh
t, [
n, -
m]!
T sub
n,
n,
m
T strh
t, [
n]
.endm
.macro strh_post rt, rn, rm
A strh
t, [
n],
m
T strh
t, [
n]
T add
n,
n,
m
.endm
.macro strh_dpost rt, rn, rm
A strh
t, [
n], -
m
T strh
t, [
n]
T sub
n,
n,
m
.endm
#if HAVE_VFP_ARGS
ELF .eabi_attribute 28, 1
# define VFP
# define NOVFP @
#else
# define VFP @
# define NOVFP
#endif
#define GLUE(a, b) a ## b
#define JOIN(a, b) GLUE(a, b)
#define X(s) JOIN(EXTERN_ASM, s)