/*****************************************************************************1* asm.S: arm utility macros2*****************************************************************************3* Copyright (C) 2008-2016 x264 project4*5* Authors: Mans Rullgard <[email protected]>6* David Conrad <[email protected]>7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License as published by10* the Free Software Foundation; either version 2 of the License, or11* (at your option) any later version.12*13* This program is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16* GNU General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to the Free Software20* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.21*22* This program is also available under a commercial proprietary license.23* For more information, contact us at [email protected].24*****************************************************************************/2526#include "config.h"2728.syntax unified2930#if HAVE_NEON31.arch armv7-a32#elif HAVE_ARMV6T233.arch armv6t234#elif HAVE_ARMV635.arch armv636#endif3738.fpu neon3940#ifdef PREFIX41# define EXTERN_ASM _42#else43# define EXTERN_ASM44#endif4546#ifdef __ELF__47# define ELF48#else49# define ELF @50#endif5152#if HAVE_AS_FUNC53# define FUNC54#else55# define FUNC @56#endif5758#if SYS_LINUX59#define HAVE_SECTION_DATA_REL_RO 160#else61#define HAVE_SECTION_DATA_REL_RO 062#endif6364.macro require8, val=165ELF .eabi_attribute 24, \val66.endm6768.macro preserve8, val=169ELF .eabi_attribute 25, \val70.endm7172.macro function name, export=173.macro endfunc74ELF .size \name, . - \name75FUNC .endfunc76.purgem endfunc77.endm78.align 279.if \export == 180.global EXTERN_ASM\name81ELF .hidden EXTERN_ASM\name82ELF .type EXTERN_ASM\name, %function83FUNC .func EXTERN_ASM\name84EXTERN_ASM\name:85.else86ELF .hidden \name87ELF .type \name, %function88FUNC .func \name89\name:90.endif91.endm9293.macro const name, align=2, relocate=094.macro endconst95ELF .size \name, . - \name96.purgem endconst97.endm98.if HAVE_SECTION_DATA_REL_RO && \relocate99.section .data.rel.ro100.else101.section .rodata102.endif103.align \align104\name:105.endm106107.macro movrel rd, val108#if defined(PIC)109ldr \rd, 1f110b 2f1111:112@ FIXME: thumb113.word \val - (2f + 8)1142:115add \rd, \rd, pc116#elif HAVE_ARMV6T2117movw \rd, #:lower16:\val118movt \rd, #:upper16:\val119#else120ldr \rd, =\val121#endif122.endm123124.macro movrelx rd, val, got125#if defined(PIC) && defined(__ELF__)126ldr \got, 2f127ldr \rd, 1f128b 3f1291:130@ FIXME: thumb131.word \val(GOT)1322:133.word _GLOBAL_OFFSET_TABLE_ - (3f + 8)1343:135add \got, \got, pc136ldr \rd, [\got, \rd]137#elif defined(PIC) && defined(__APPLE__)138ldr \rd, 1f139b 2f1401:141@ FIXME: thumb142.word 3f - (2f + 8)1432:144ldr \rd, [pc, \rd]145.non_lazy_symbol_pointer1463:147.indirect_symbol \val148.word 0149.text150#else151movrel \rd, \val152#endif153.endm154155.macro movconst rd, val156#if HAVE_ARMV6T2157movw \rd, #:lower16:\val158.if \val >> 16159movt \rd, #:upper16:\val160.endif161#else162ldr \rd, =\val163#endif164.endm165166#define GLUE(a, b) a ## b167#define JOIN(a, b) GLUE(a, b)168#define X(s) JOIN(EXTERN_ASM, s)169170#define FENC_STRIDE 16171#define FDEC_STRIDE 32172173.macro HORIZ_ADD dest, a, b174.ifnb \b175vadd.u16 \a, \a, \b176.endif177vpaddl.u16 \a, \a178vpaddl.u32 \dest, \a179.endm180181.macro SUMSUB_AB sum, diff, a, b182vadd.s16 \sum, \a, \b183vsub.s16 \diff, \a, \b184.endm185186.macro SUMSUB_ABCD s1, d1, s2, d2, a, b, c, d187SUMSUB_AB \s1, \d1, \a, \b188SUMSUB_AB \s2, \d2, \c, \d189.endm190191.macro ABS2 a b192vabs.s16 \a, \a193vabs.s16 \b, \b194.endm195196// dist = distance in elements (0 for vertical pass, 1/2 for horizontal passes)197// op = sumsub/amax (sum and diff / maximum of absolutes)198// d1/2 = destination registers199// s1/2 = source registers200.macro HADAMARD dist, op, d1, d2, s1, s2201.if \dist == 1202vtrn.16 \s1, \s2203.else204vtrn.32 \s1, \s2205.endif206.ifc \op, sumsub207SUMSUB_AB \d1, \d2, \s1, \s2208.else209vabs.s16 \s1, \s1210vabs.s16 \s2, \s2211vmax.s16 \d1, \s1, \s2212.endif213.endm214215.macro TRANSPOSE8x8 r0 r1 r2 r3 r4 r5 r6 r7216vtrn.32 \r0, \r4217vtrn.32 \r1, \r5218vtrn.32 \r2, \r6219vtrn.32 \r3, \r7220vtrn.16 \r0, \r2221vtrn.16 \r1, \r3222vtrn.16 \r4, \r6223vtrn.16 \r5, \r7224vtrn.8 \r0, \r1225vtrn.8 \r2, \r3226vtrn.8 \r4, \r5227vtrn.8 \r6, \r7228.endm229230.macro TRANSPOSE4x4 r0 r1 r2 r3231vtrn.16 \r0, \r2232vtrn.16 \r1, \r3233vtrn.8 \r0, \r1234vtrn.8 \r2, \r3235.endm236237.macro TRANSPOSE4x4_16 d0 d1 d2 d3238vtrn.32 \d0, \d2239vtrn.32 \d1, \d3240vtrn.16 \d0, \d1241vtrn.16 \d2, \d3242.endm243244245