1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 module ffmpeg.libavutil.intreadwrite;
19 extern (C) @nogc nothrow:
20 
21 union av_alias64
22 {
23     ulong u64;
24     uint[2] u32;
25     ushort[4] u16;
26     ubyte[8] u8;
27     double f64;
28     float[2] f32;
29 }
30 
31 union av_alias32
32 {
33     uint u32;
34     ushort[2] u16;
35     ubyte[4] u8;
36     float f32;
37 }
38 
39 union av_alias16
40 {
41     ushort u16;
42     ubyte[2] u8;
43 }
44 
45 /*
46  * Arch-specific headers can provide any combination of
47  * AV_[RW][BLN](16|24|32|48|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
48  * Preprocessor symbols must be defined, even if these are implemented
49  * as inline functions.
50  *
51  * R/W means read/write, B/L/N means big/little/native endianness.
52  * The following macros require aligned access, compared to their
53  * unaligned variants: AV_(COPY|SWAP|ZERO)(64|128), AV_[RW]N[8-64]A.
54  * Incorrect usage may range from abysmal performance to crash
55  * depending on the platform.
56  *
57  * The unaligned variants are AV_[RW][BLN][8-64] and AV_COPY*U.
58  */
59 
60 /* HAVE_AV_CONFIG_H */
61 
62 /*
63  * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
64  */
65 
66 /* AV_HAVE_BIGENDIAN */
67 
68 /* !AV_HAVE_BIGENDIAN */
69 
70 /*
71  * Define AV_[RW]N helper macros to simplify definitions not provided
72  * by per-arch headers.
73  */
74 
75 /* HAVE_FAST_UNALIGNED */
76 
77 extern (D) auto AV_RN16(T)(auto ref T p)
78 {
79     return AV_RN(16, p);
80 }
81 
82 extern (D) auto AV_RN32(T)(auto ref T p)
83 {
84     return AV_RN(32, p);
85 }
86 
87 extern (D) auto AV_RN64(T)(auto ref T p)
88 {
89     return AV_RN(64, p);
90 }
91 
92 extern (D) auto AV_WN16(T0, T1)(auto ref T0 p, auto ref T1 v)
93 {
94     return AV_WN(16, p, v);
95 }
96 
97 extern (D) auto AV_WN32(T0, T1)(auto ref T0 p, auto ref T1 v)
98 {
99     return AV_WN(32, p, v);
100 }
101 
102 extern (D) auto AV_WN64(T0, T1)(auto ref T0 p, auto ref T1 v)
103 {
104     return AV_WN(64, p, v);
105 }
106 
107 extern (D) auto AV_RB8(T)(auto ref T x)
108 {
109     return (cast(const(ubyte)*) x)[0];
110 }
111 
112 alias AV_RL8 = AV_RB8;
113 //alias AV_WL8 = AV_WB8;
114 
115 extern (D) auto AV_RB16(T)(auto ref T p)
116 {
117     return AV_RB(16, p);
118 }
119 
120 extern (D) auto AV_WB16(T0, T1)(auto ref T0 p, auto ref T1 v)
121 {
122     return AV_WB(16, p, v);
123 }
124 
125 extern (D) auto AV_RL16(T)(auto ref T p)
126 {
127     return AV_RL(16, p);
128 }
129 
130 extern (D) auto AV_WL16(T0, T1)(auto ref T0 p, auto ref T1 v)
131 {
132     return AV_WL(16, p, v);
133 }
134 
135 extern (D) auto AV_RB32(T)(auto ref T p)
136 {
137     return AV_RB(32, p);
138 }
139 
140 extern (D) auto AV_WB32(T0, T1)(auto ref T0 p, auto ref T1 v)
141 {
142     return AV_WB(32, p, v);
143 }
144 
145 extern (D) auto AV_RL32(T)(auto ref T p)
146 {
147     return AV_RL(32, p);
148 }
149 
150 extern (D) auto AV_WL32(T0, T1)(auto ref T0 p, auto ref T1 v)
151 {
152     return AV_WL(32, p, v);
153 }
154 
155 extern (D) auto AV_RB64(T)(auto ref T p)
156 {
157     return AV_RB(64, p);
158 }
159 
160 extern (D) auto AV_WB64(T0, T1)(auto ref T0 p, auto ref T1 v)
161 {
162     return AV_WB(64, p, v);
163 }
164 
165 extern (D) auto AV_RL64(T)(auto ref T p)
166 {
167     return AV_RL(64, p);
168 }
169 
170 extern (D) auto AV_WL64(T0, T1)(auto ref T0 p, auto ref T1 v)
171 {
172     return AV_WL(64, p, v);
173 }
174 
175 extern (D) auto AV_RB24(T)(auto ref T x)
176 {
177     return ((cast(const(ubyte)*) x)[0] << 16) | ((cast(const(ubyte)*) x)[1] << 8) | (cast(const(ubyte)*) x)[2];
178 }
179 
180 extern (D) auto AV_RL24(T)(auto ref T x)
181 {
182     return ((cast(const(ubyte)*) x)[2] << 16) | ((cast(const(ubyte)*) x)[1] << 8) | (cast(const(ubyte)*) x)[0];
183 }
184 
185 extern (D) auto AV_RB48(T)(auto ref T x)
186 {
187     return (cast(ulong) (cast(const(ubyte)*) x)[0] << 40) | (cast(ulong) (cast(const(ubyte)*) x)[1] << 32) | (cast(ulong) (cast(const(ubyte)*) x)[2] << 24) | (cast(ulong) (cast(const(ubyte)*) x)[3] << 16) | (cast(ulong) (cast(const(ubyte)*) x)[4] << 8) | cast(ulong) (cast(const(ubyte)*) x)[5];
188 }
189 
190 extern (D) auto AV_RL48(T)(auto ref T x)
191 {
192     return (cast(ulong) (cast(const(ubyte)*) x)[5] << 40) | (cast(ulong) (cast(const(ubyte)*) x)[4] << 32) | (cast(ulong) (cast(const(ubyte)*) x)[3] << 24) | (cast(ulong) (cast(const(ubyte)*) x)[2] << 16) | (cast(ulong) (cast(const(ubyte)*) x)[1] << 8) | cast(ulong) (cast(const(ubyte)*) x)[0];
193 }
194 
195 /*
196  * The AV_[RW]NA macros access naturally aligned data
197  * in a type-safe way.
198  */
199 
200 extern (D) auto AV_RN16A(T)(auto ref T p)
201 {
202     return AV_RNA(16, p);
203 }
204 
205 extern (D) auto AV_RN32A(T)(auto ref T p)
206 {
207     return AV_RNA(32, p);
208 }
209 
210 extern (D) auto AV_RN64A(T)(auto ref T p)
211 {
212     return AV_RNA(64, p);
213 }
214 
215 extern (D) auto AV_WN16A(T0, T1)(auto ref T0 p, auto ref T1 v)
216 {
217     return AV_WNA(16, p, v);
218 }
219 
220 extern (D) auto AV_WN32A(T0, T1)(auto ref T0 p, auto ref T1 v)
221 {
222     return AV_WNA(32, p, v);
223 }
224 
225 extern (D) auto AV_WN64A(T0, T1)(auto ref T0 p, auto ref T1 v)
226 {
227     return AV_WNA(64, p, v);
228 }
229 
230 extern (D) auto AV_RL64A(T)(auto ref T p)
231 {
232     return AV_RLA(64, p);
233 }
234 
235 extern (D) auto AV_WL64A(T0, T1)(auto ref T0 p, auto ref T1 v)
236 {
237     return AV_WLA(64, p, v);
238 }
239 
240 /*
241  * The AV_COPYxxU macros are suitable for copying data to/from unaligned
242  * memory locations.
243  */
244 
245 extern (D) auto AV_COPY16U(T0, T1)(auto ref T0 d, auto ref T1 s)
246 {
247     return AV_COPYU(16, d, s);
248 }
249 
250 extern (D) auto AV_COPY32U(T0, T1)(auto ref T0 d, auto ref T1 s)
251 {
252     return AV_COPYU(32, d, s);
253 }
254 
255 extern (D) auto AV_COPY64U(T0, T1)(auto ref T0 d, auto ref T1 s)
256 {
257     return AV_COPYU(64, d, s);
258 }
259 
260 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
261  * naturally aligned. They may be implemented using MMX,
262  * so emms_c() must be called before using any float code
263  * afterwards.
264  */
265 
266 extern (D) auto AV_COPY16(T0, T1)(auto ref T0 d, auto ref T1 s)
267 {
268     return AV_COPY(16, d, s);
269 }
270 
271 extern (D) auto AV_COPY32(T0, T1)(auto ref T0 d, auto ref T1 s)
272 {
273     return AV_COPY(32, d, s);
274 }
275 
276 extern (D) auto AV_COPY64(T0, T1)(auto ref T0 d, auto ref T1 s)
277 {
278     return AV_COPY(64, d, s);
279 }
280 
281 extern (D) auto AV_SWAP64(T0, T1)(auto ref T0 a, auto ref T1 b)
282 {
283     return AV_SWAP(64, a, b);
284 }
285 
286 extern (D) auto AV_ZERO16(T)(auto ref T d)
287 {
288     return AV_ZERO(16, d);
289 }
290 
291 extern (D) auto AV_ZERO32(T)(auto ref T d)
292 {
293     return AV_ZERO(32, d);
294 }
295 
296 extern (D) auto AV_ZERO64(T)(auto ref T d)
297 {
298     return AV_ZERO(64, d);
299 }
300 
301 /* AVUTIL_INTREADWRITE_H */