xref: /third_party/ffmpeg/libavutil/x86/asm.h (revision cabdff1a)
1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14cabdff1aSopenharmony_ci * Lesser General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci#ifndef AVUTIL_X86_ASM_H
22cabdff1aSopenharmony_ci#define AVUTIL_X86_ASM_H
23cabdff1aSopenharmony_ci
24cabdff1aSopenharmony_ci#include <stdint.h>
25cabdff1aSopenharmony_ci#include "config.h"
26cabdff1aSopenharmony_ci
27cabdff1aSopenharmony_citypedef struct xmm_reg { uint64_t a, b; } xmm_reg;
28cabdff1aSopenharmony_citypedef struct ymm_reg { uint64_t a, b, c, d; } ymm_reg;
29cabdff1aSopenharmony_ci
30cabdff1aSopenharmony_ci#if ARCH_X86_64
31cabdff1aSopenharmony_ci#    define FF_OPSIZE "q"
32cabdff1aSopenharmony_ci#    define FF_REG_a "rax"
33cabdff1aSopenharmony_ci#    define FF_REG_b "rbx"
34cabdff1aSopenharmony_ci#    define FF_REG_c "rcx"
35cabdff1aSopenharmony_ci#    define FF_REG_d "rdx"
36cabdff1aSopenharmony_ci#    define FF_REG_D "rdi"
37cabdff1aSopenharmony_ci#    define FF_REG_S "rsi"
38cabdff1aSopenharmony_ci#    define FF_PTR_SIZE "8"
39cabdff1aSopenharmony_citypedef int64_t x86_reg;
40cabdff1aSopenharmony_ci
41cabdff1aSopenharmony_ci/* FF_REG_SP is defined in Solaris sys headers, so use FF_REG_sp */
42cabdff1aSopenharmony_ci#    define FF_REG_sp "rsp"
43cabdff1aSopenharmony_ci#    define FF_REG_BP "rbp"
44cabdff1aSopenharmony_ci#    define FF_REGBP   rbp
45cabdff1aSopenharmony_ci#    define FF_REGa    rax
46cabdff1aSopenharmony_ci#    define FF_REGb    rbx
47cabdff1aSopenharmony_ci#    define FF_REGc    rcx
48cabdff1aSopenharmony_ci#    define FF_REGd    rdx
49cabdff1aSopenharmony_ci#    define FF_REGSP   rsp
50cabdff1aSopenharmony_ci
51cabdff1aSopenharmony_ci#elif ARCH_X86_32
52cabdff1aSopenharmony_ci
53cabdff1aSopenharmony_ci#    define FF_OPSIZE "l"
54cabdff1aSopenharmony_ci#    define FF_REG_a "eax"
55cabdff1aSopenharmony_ci#    define FF_REG_b "ebx"
56cabdff1aSopenharmony_ci#    define FF_REG_c "ecx"
57cabdff1aSopenharmony_ci#    define FF_REG_d "edx"
58cabdff1aSopenharmony_ci#    define FF_REG_D "edi"
59cabdff1aSopenharmony_ci#    define FF_REG_S "esi"
60cabdff1aSopenharmony_ci#    define FF_PTR_SIZE "4"
61cabdff1aSopenharmony_citypedef int32_t x86_reg;
62cabdff1aSopenharmony_ci
63cabdff1aSopenharmony_ci#    define FF_REG_sp "esp"
64cabdff1aSopenharmony_ci#    define FF_REG_BP "ebp"
65cabdff1aSopenharmony_ci#    define FF_REGBP   ebp
66cabdff1aSopenharmony_ci#    define FF_REGa    eax
67cabdff1aSopenharmony_ci#    define FF_REGb    ebx
68cabdff1aSopenharmony_ci#    define FF_REGc    ecx
69cabdff1aSopenharmony_ci#    define FF_REGd    edx
70cabdff1aSopenharmony_ci#    define FF_REGSP   esp
71cabdff1aSopenharmony_ci#else
72cabdff1aSopenharmony_citypedef int x86_reg;
73cabdff1aSopenharmony_ci#endif
74cabdff1aSopenharmony_ci
75cabdff1aSopenharmony_ci#define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE))
76cabdff1aSopenharmony_ci#define HAVE_6REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE || HAVE_EBP_AVAILABLE))
77cabdff1aSopenharmony_ci
78cabdff1aSopenharmony_ci#if ARCH_X86_64 && defined(PIC)
79cabdff1aSopenharmony_ci#    define BROKEN_RELOCATIONS 1
80cabdff1aSopenharmony_ci#endif
81cabdff1aSopenharmony_ci
82cabdff1aSopenharmony_ci/*
83cabdff1aSopenharmony_ci * If gcc is not set to support sse (-msse) it will not accept xmm registers
84cabdff1aSopenharmony_ci * in the clobber list for inline asm. XMM_CLOBBERS takes a list of xmm
85cabdff1aSopenharmony_ci * registers to be marked as clobbered and evaluates to nothing if they are
86cabdff1aSopenharmony_ci * not supported, or to the list itself if they are supported. Since a clobber
87cabdff1aSopenharmony_ci * list may not be empty, XMM_CLOBBERS_ONLY should be used if the xmm
88cabdff1aSopenharmony_ci * registers are the only in the clobber list.
89cabdff1aSopenharmony_ci * For example a list with "eax" and "xmm0" as clobbers should become:
90cabdff1aSopenharmony_ci * : XMM_CLOBBERS("xmm0",) "eax"
91cabdff1aSopenharmony_ci * and a list with only "xmm0" should become:
92cabdff1aSopenharmony_ci * XMM_CLOBBERS_ONLY("xmm0")
93cabdff1aSopenharmony_ci */
94cabdff1aSopenharmony_ci#if HAVE_XMM_CLOBBERS
95cabdff1aSopenharmony_ci#    define XMM_CLOBBERS(...)        __VA_ARGS__
96cabdff1aSopenharmony_ci#    define XMM_CLOBBERS_ONLY(...) : __VA_ARGS__
97cabdff1aSopenharmony_ci#else
98cabdff1aSopenharmony_ci#    define XMM_CLOBBERS(...)
99cabdff1aSopenharmony_ci#    define XMM_CLOBBERS_ONLY(...)
100cabdff1aSopenharmony_ci#endif
101cabdff1aSopenharmony_ci
102cabdff1aSopenharmony_ci/* Use to export labels from asm. */
103cabdff1aSopenharmony_ci#define LABEL_MANGLE(a) EXTERN_PREFIX #a
104cabdff1aSopenharmony_ci
105cabdff1aSopenharmony_ci// Use rip-relative addressing if compiling PIC code on x86-64.
106cabdff1aSopenharmony_ci#if ARCH_X86_64 && defined(PIC)
107cabdff1aSopenharmony_ci#    define LOCAL_MANGLE(a) #a "(%%rip)"
108cabdff1aSopenharmony_ci#else
109cabdff1aSopenharmony_ci#    define LOCAL_MANGLE(a) #a
110cabdff1aSopenharmony_ci#endif
111cabdff1aSopenharmony_ci
112cabdff1aSopenharmony_ci#if HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS
113cabdff1aSopenharmony_ci#   define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
114cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS_ADD(...)
115cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS(...)
116cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS_ARRAY_ADD(...)
117cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS_ARRAY(...)
118cabdff1aSopenharmony_ci#else
119cabdff1aSopenharmony_ci    /* When direct symbol references are used in code passed to a compiler that does not support them
120cabdff1aSopenharmony_ci     *  then these references need to be converted to named asm constraints instead.
121cabdff1aSopenharmony_ci     * Instead of returning a direct symbol MANGLE now returns a named constraint for that specific symbol.
122cabdff1aSopenharmony_ci     * In order for this to work there must also be a corresponding entry in the asm-interface. To add this
123cabdff1aSopenharmony_ci     *  entry use the macro NAMED_CONSTRAINTS() and pass in a list of each symbol reference used in the
124cabdff1aSopenharmony_ci     *  corresponding block of code. (e.g. NAMED_CONSTRAINTS(var1,var2,var3) where var1 is the first symbol etc. ).
125cabdff1aSopenharmony_ci     * If there are already existing constraints then use NAMED_CONSTRAINTS_ADD to add to the existing constraint list.
126cabdff1aSopenharmony_ci     */
127cabdff1aSopenharmony_ci#   define MANGLE(a) "%["#a"]"
128cabdff1aSopenharmony_ci    // Intel/MSVC does not correctly expand va-args so we need a rather ugly hack in order to get it to work
129cabdff1aSopenharmony_ci#   define FE_0(P,X) P(X)
130cabdff1aSopenharmony_ci#   define FE_1(P,X,X1) P(X), FE_0(P,X1)
131cabdff1aSopenharmony_ci#   define FE_2(P,X,X1,X2) P(X), FE_1(P,X1,X2)
132cabdff1aSopenharmony_ci#   define FE_3(P,X,X1,X2,X3) P(X), FE_2(P,X1,X2,X3)
133cabdff1aSopenharmony_ci#   define FE_4(P,X,X1,X2,X3,X4) P(X), FE_3(P,X1,X2,X3,X4)
134cabdff1aSopenharmony_ci#   define FE_5(P,X,X1,X2,X3,X4,X5) P(X), FE_4(P,X1,X2,X3,X4,X5)
135cabdff1aSopenharmony_ci#   define FE_6(P,X,X1,X2,X3,X4,X5,X6) P(X), FE_5(P,X1,X2,X3,X4,X5,X6)
136cabdff1aSopenharmony_ci#   define FE_7(P,X,X1,X2,X3,X4,X5,X6,X7) P(X), FE_6(P,X1,X2,X3,X4,X5,X6,X7)
137cabdff1aSopenharmony_ci#   define FE_8(P,X,X1,X2,X3,X4,X5,X6,X7,X8) P(X), FE_7(P,X1,X2,X3,X4,X5,X6,X7,X8)
138cabdff1aSopenharmony_ci#   define FE_9(P,X,X1,X2,X3,X4,X5,X6,X7,X8,X9) P(X), FE_8(P,X1,X2,X3,X4,X5,X6,X7,X8,X9)
139cabdff1aSopenharmony_ci#   define GET_FE_IMPL(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
140cabdff1aSopenharmony_ci#   define GET_FE(A) GET_FE_IMPL A
141cabdff1aSopenharmony_ci#   define GET_FE_GLUE(x, y) x y
142cabdff1aSopenharmony_ci#   define FOR_EACH_VA(P,...) GET_FE_GLUE(GET_FE((__VA_ARGS__,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1,FE_0)), (P,__VA_ARGS__))
143cabdff1aSopenharmony_ci#   define NAME_CONSTRAINT(x) [x] "m"(x)
144cabdff1aSopenharmony_ci    // Parameters are a list of each symbol reference required
145cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS_ADD(...) , FOR_EACH_VA(NAME_CONSTRAINT,__VA_ARGS__)
146cabdff1aSopenharmony_ci    // Same but without comma for when there are no previously defined constraints
147cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS(...) FOR_EACH_VA(NAME_CONSTRAINT,__VA_ARGS__)
148cabdff1aSopenharmony_ci    // Same as above NAMED_CONSTRAINTS except used for passing arrays/pointers instead of normal variables
149cabdff1aSopenharmony_ci#   define NAME_CONSTRAINT_ARRAY(x) [x] "m"(*x)
150cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS_ARRAY_ADD(...) , FOR_EACH_VA(NAME_CONSTRAINT_ARRAY,__VA_ARGS__)
151cabdff1aSopenharmony_ci#   define NAMED_CONSTRAINTS_ARRAY(...) FOR_EACH_VA(NAME_CONSTRAINT_ARRAY,__VA_ARGS__)
152cabdff1aSopenharmony_ci#endif
153cabdff1aSopenharmony_ci
154cabdff1aSopenharmony_ci#endif /* AVUTIL_X86_ASM_H */
155