FFmpeg
mem_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVUTIL_MEM_INTERNAL_H
22 #define AVUTIL_MEM_INTERNAL_H
23 
24 #include "config.h"
25 
26 #include <stdint.h>
27 
28 #include "attributes.h"
29 #include "macros.h"
30 #include "mem.h"
31 #include "version.h"
32 
33 #if !FF_API_DECLARE_ALIGNED
34 /**
35  * @def DECLARE_ALIGNED(n,t,v)
36  * Declare a variable that is aligned in memory.
37  *
38  * @code{.c}
39  * DECLARE_ALIGNED(16, uint16_t, aligned_int) = 42;
40  * DECLARE_ALIGNED(32, uint8_t, aligned_array)[128];
41  *
42  * // The default-alignment equivalent would be
43  * uint16_t aligned_int = 42;
44  * uint8_t aligned_array[128];
45  * @endcode
46  *
47  * @param n Minimum alignment in bytes
48  * @param t Type of the variable (or array element)
49  * @param v Name of the variable
50  */
51 
52 /**
53  * @def DECLARE_ASM_ALIGNED(n,t,v)
54  * Declare an aligned variable appropriate for use in inline assembly code.
55  *
56  * @code{.c}
57  * DECLARE_ASM_ALIGNED(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
58  * @endcode
59  *
60  * @param n Minimum alignment in bytes
61  * @param t Type of the variable (or array element)
62  * @param v Name of the variable
63  */
64 
65 /**
66  * @def DECLARE_ASM_CONST(n,t,v)
67  * Declare a static constant aligned variable appropriate for use in inline
68  * assembly code.
69  *
70  * @code{.c}
71  * DECLARE_ASM_CONST(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
72  * @endcode
73  *
74  * @param n Minimum alignment in bytes
75  * @param t Type of the variable (or array element)
76  * @param v Name of the variable
77  */
78 
79 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
80  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
81  #define DECLARE_ASM_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
82  #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
83 #elif defined(__DJGPP__)
84  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (FFMIN(n, 16)))) v
85  #define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
86  #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
87 #elif defined(__GNUC__) || defined(__clang__)
88  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
89  #define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (n))) v
90  #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
91 #elif defined(_MSC_VER)
92  #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
93  #define DECLARE_ASM_ALIGNED(n,t,v) __declspec(align(n)) t v
94  #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
95 #else
96  #define DECLARE_ALIGNED(n,t,v) t v
97  #define DECLARE_ASM_ALIGNED(n,t,v) t v
98  #define DECLARE_ASM_CONST(n,t,v) static const t v
99 #endif
100 #endif
101 
102 // Some broken preprocessors need a second expansion
103 // to be forced to tokenize __VA_ARGS__
104 #define E1(x) x
105 
106 #define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \
107  uint8_t la_##v[sizeof(t s o) + (a)]; \
108  t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
109 
110 #define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \
111  DECLARE_ALIGNED(a, t, la_##v) s o; \
112  t (*v) o = la_##v
113 
114 #define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_##a(t, v, __VA_ARGS__)
115 
116 #if HAVE_LOCAL_ALIGNED
117 # define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_D(4, t, v, __VA_ARGS__,,))
118 #else
119 # define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_A(4, t, v, __VA_ARGS__,,))
120 #endif
121 
122 #if HAVE_LOCAL_ALIGNED
123 # define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
124 #else
125 # define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_A(8, t, v, __VA_ARGS__,,))
126 #endif
127 
128 #if HAVE_LOCAL_ALIGNED
129 # define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
130 #else
131 # define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_A(16, t, v, __VA_ARGS__,,))
132 #endif
133 
134 #if HAVE_LOCAL_ALIGNED
135 # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
136 #else
137 # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
138 #endif
139 
140 #endif /* AVUTIL_MEM_INTERNAL_H */
macros.h
attributes.h
version.h
mem.h