OSDN Git Service

Merge commit 'e435beb1ea5380a90774dbf51fdc8c941e486551'
[android-x86/external-ffmpeg.git] / libavutil / intreadwrite.h
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
19 #ifndef AVUTIL_INTREADWRITE_H
20 #define AVUTIL_INTREADWRITE_H
21
22 #include <stdint.h>
23 #include "libavutil/avconfig.h"
24 #include "attributes.h"
25 #include "bswap.h"
26
27 typedef union {
28     uint64_t u64;
29     uint32_t u32[2];
30     uint16_t u16[4];
31     uint8_t  u8 [8];
32     double   f64;
33     float    f32[2];
34 } av_alias av_alias64;
35
36 typedef union {
37     uint32_t u32;
38     uint16_t u16[2];
39     uint8_t  u8 [4];
40     float    f32;
41 } av_alias av_alias32;
42
43 typedef union {
44     uint16_t u16;
45     uint8_t  u8 [2];
46 } av_alias av_alias16;
47
48 /*
49  * Arch-specific headers can provide any combination of
50  * AV_[RW][BLN](16|24|32|48|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
51  * Preprocessor symbols must be defined, even if these are implemented
52  * as inline functions.
53  *
54  * R/W means read/write, B/L/N means big/little/native endianness.
55  * The following macros require aligned access, compared to their
56  * unaligned variants: AV_(COPY|SWAP|ZERO)(64|128), AV_[RW]N[8-64]A.
57  * Incorrect usage may range from abysmal performance to crash
58  * depending on the platform.
59  *
60  * The unaligned variants are AV_[RW][BLN][8-64] and AV_COPY*U.
61  */
62
63 #ifdef HAVE_AV_CONFIG_H
64
65 #include "config.h"
66
67 #if   ARCH_ARM
68 #   include "arm/intreadwrite.h"
69 #elif ARCH_AVR32
70 #   include "avr32/intreadwrite.h"
71 #elif ARCH_MIPS
72 #   include "mips/intreadwrite.h"
73 #elif ARCH_PPC
74 #   include "ppc/intreadwrite.h"
75 #elif ARCH_TOMI
76 #   include "tomi/intreadwrite.h"
77 #elif ARCH_X86
78 #   include "x86/intreadwrite.h"
79 #endif
80
81 #endif /* HAVE_AV_CONFIG_H */
82
83 /*
84  * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
85  */
86
87 #if AV_HAVE_BIGENDIAN
88
89 #   if    defined(AV_RN16) && !defined(AV_RB16)
90 #       define AV_RB16(p) AV_RN16(p)
91 #   elif !defined(AV_RN16) &&  defined(AV_RB16)
92 #       define AV_RN16(p) AV_RB16(p)
93 #   endif
94
95 #   if    defined(AV_WN16) && !defined(AV_WB16)
96 #       define AV_WB16(p, v) AV_WN16(p, v)
97 #   elif !defined(AV_WN16) &&  defined(AV_WB16)
98 #       define AV_WN16(p, v) AV_WB16(p, v)
99 #   endif
100
101 #   if    defined(AV_RN24) && !defined(AV_RB24)
102 #       define AV_RB24(p) AV_RN24(p)
103 #   elif !defined(AV_RN24) &&  defined(AV_RB24)
104 #       define AV_RN24(p) AV_RB24(p)
105 #   endif
106
107 #   if    defined(AV_WN24) && !defined(AV_WB24)
108 #       define AV_WB24(p, v) AV_WN24(p, v)
109 #   elif !defined(AV_WN24) &&  defined(AV_WB24)
110 #       define AV_WN24(p, v) AV_WB24(p, v)
111 #   endif
112
113 #   if    defined(AV_RN32) && !defined(AV_RB32)
114 #       define AV_RB32(p) AV_RN32(p)
115 #   elif !defined(AV_RN32) &&  defined(AV_RB32)
116 #       define AV_RN32(p) AV_RB32(p)
117 #   endif
118
119 #   if    defined(AV_WN32) && !defined(AV_WB32)
120 #       define AV_WB32(p, v) AV_WN32(p, v)
121 #   elif !defined(AV_WN32) &&  defined(AV_WB32)
122 #       define AV_WN32(p, v) AV_WB32(p, v)
123 #   endif
124
125 #   if    defined(AV_RN48) && !defined(AV_RB48)
126 #       define AV_RB48(p) AV_RN48(p)
127 #   elif !defined(AV_RN48) &&  defined(AV_RB48)
128 #       define AV_RN48(p) AV_RB48(p)
129 #   endif
130
131 #   if    defined(AV_WN48) && !defined(AV_WB48)
132 #       define AV_WB48(p, v) AV_WN48(p, v)
133 #   elif !defined(AV_WN48) &&  defined(AV_WB48)
134 #       define AV_WN48(p, v) AV_WB48(p, v)
135 #   endif
136
137 #   if    defined(AV_RN64) && !defined(AV_RB64)
138 #       define AV_RB64(p) AV_RN64(p)
139 #   elif !defined(AV_RN64) &&  defined(AV_RB64)
140 #       define AV_RN64(p) AV_RB64(p)
141 #   endif
142
143 #   if    defined(AV_WN64) && !defined(AV_WB64)
144 #       define AV_WB64(p, v) AV_WN64(p, v)
145 #   elif !defined(AV_WN64) &&  defined(AV_WB64)
146 #       define AV_WN64(p, v) AV_WB64(p, v)
147 #   endif
148
149 #else /* AV_HAVE_BIGENDIAN */
150
151 #   if    defined(AV_RN16) && !defined(AV_RL16)
152 #       define AV_RL16(p) AV_RN16(p)
153 #   elif !defined(AV_RN16) &&  defined(AV_RL16)
154 #       define AV_RN16(p) AV_RL16(p)
155 #   endif
156
157 #   if    defined(AV_WN16) && !defined(AV_WL16)
158 #       define AV_WL16(p, v) AV_WN16(p, v)
159 #   elif !defined(AV_WN16) &&  defined(AV_WL16)
160 #       define AV_WN16(p, v) AV_WL16(p, v)
161 #   endif
162
163 #   if    defined(AV_RN24) && !defined(AV_RL24)
164 #       define AV_RL24(p) AV_RN24(p)
165 #   elif !defined(AV_RN24) &&  defined(AV_RL24)
166 #       define AV_RN24(p) AV_RL24(p)
167 #   endif
168
169 #   if    defined(AV_WN24) && !defined(AV_WL24)
170 #       define AV_WL24(p, v) AV_WN24(p, v)
171 #   elif !defined(AV_WN24) &&  defined(AV_WL24)
172 #       define AV_WN24(p, v) AV_WL24(p, v)
173 #   endif
174
175 #   if    defined(AV_RN32) && !defined(AV_RL32)
176 #       define AV_RL32(p) AV_RN32(p)
177 #   elif !defined(AV_RN32) &&  defined(AV_RL32)
178 #       define AV_RN32(p) AV_RL32(p)
179 #   endif
180
181 #   if    defined(AV_WN32) && !defined(AV_WL32)
182 #       define AV_WL32(p, v) AV_WN32(p, v)
183 #   elif !defined(AV_WN32) &&  defined(AV_WL32)
184 #       define AV_WN32(p, v) AV_WL32(p, v)
185 #   endif
186
187 #   if    defined(AV_RN48) && !defined(AV_RL48)
188 #       define AV_RL48(p) AV_RN48(p)
189 #   elif !defined(AV_RN48) &&  defined(AV_RL48)
190 #       define AV_RN48(p) AV_RL48(p)
191 #   endif
192
193 #   if    defined(AV_WN48) && !defined(AV_WL48)
194 #       define AV_WL48(p, v) AV_WN48(p, v)
195 #   elif !defined(AV_WN48) &&  defined(AV_WL48)
196 #       define AV_WN48(p, v) AV_WL48(p, v)
197 #   endif
198
199 #   if    defined(AV_RN64) && !defined(AV_RL64)
200 #       define AV_RL64(p) AV_RN64(p)
201 #   elif !defined(AV_RN64) &&  defined(AV_RL64)
202 #       define AV_RN64(p) AV_RL64(p)
203 #   endif
204
205 #   if    defined(AV_WN64) && !defined(AV_WL64)
206 #       define AV_WL64(p, v) AV_WN64(p, v)
207 #   elif !defined(AV_WN64) &&  defined(AV_WL64)
208 #       define AV_WN64(p, v) AV_WL64(p, v)
209 #   endif
210
211 #endif /* !AV_HAVE_BIGENDIAN */
212
213 /*
214  * Define AV_[RW]N helper macros to simplify definitions not provided
215  * by per-arch headers.
216  */
217
218 #if defined(__GNUC__) && !defined(__TI_COMPILER_VERSION__)
219
220 union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
221 union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
222 union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
223
224 #   define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
225 #   define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
226
227 #elif defined(__DECC)
228
229 #   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
230 #   define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
231
232 #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_X64)) && AV_HAVE_FAST_UNALIGNED
233
234 #   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
235 #   define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
236
237 #elif AV_HAVE_FAST_UNALIGNED
238
239 #   define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
240 #   define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
241
242 #else
243
244 #ifndef AV_RB16
245 #   define AV_RB16(x)                           \
246     ((((const uint8_t*)(x))[0] << 8) |          \
247       ((const uint8_t*)(x))[1])
248 #endif
249 #ifndef AV_WB16
250 #   define AV_WB16(p, val) do {                 \
251         uint16_t d = (val);                     \
252         ((uint8_t*)(p))[1] = (d);               \
253         ((uint8_t*)(p))[0] = (d)>>8;            \
254     } while(0)
255 #endif
256
257 #ifndef AV_RL16
258 #   define AV_RL16(x)                           \
259     ((((const uint8_t*)(x))[1] << 8) |          \
260       ((const uint8_t*)(x))[0])
261 #endif
262 #ifndef AV_WL16
263 #   define AV_WL16(p, val) do {                 \
264         uint16_t d = (val);                     \
265         ((uint8_t*)(p))[0] = (d);               \
266         ((uint8_t*)(p))[1] = (d)>>8;            \
267     } while(0)
268 #endif
269
270 #ifndef AV_RB32
271 #   define AV_RB32(x)                                \
272     (((uint32_t)((const uint8_t*)(x))[0] << 24) |    \
273                (((const uint8_t*)(x))[1] << 16) |    \
274                (((const uint8_t*)(x))[2] <<  8) |    \
275                 ((const uint8_t*)(x))[3])
276 #endif
277 #ifndef AV_WB32
278 #   define AV_WB32(p, val) do {                 \
279         uint32_t d = (val);                     \
280         ((uint8_t*)(p))[3] = (d);               \
281         ((uint8_t*)(p))[2] = (d)>>8;            \
282         ((uint8_t*)(p))[1] = (d)>>16;           \
283         ((uint8_t*)(p))[0] = (d)>>24;           \
284     } while(0)
285 #endif
286
287 #ifndef AV_RL32
288 #   define AV_RL32(x)                                \
289     (((uint32_t)((const uint8_t*)(x))[3] << 24) |    \
290                (((const uint8_t*)(x))[2] << 16) |    \
291                (((const uint8_t*)(x))[1] <<  8) |    \
292                 ((const uint8_t*)(x))[0])
293 #endif
294 #ifndef AV_WL32
295 #   define AV_WL32(p, val) do {                 \
296         uint32_t d = (val);                     \
297         ((uint8_t*)(p))[0] = (d);               \
298         ((uint8_t*)(p))[1] = (d)>>8;            \
299         ((uint8_t*)(p))[2] = (d)>>16;           \
300         ((uint8_t*)(p))[3] = (d)>>24;           \
301     } while(0)
302 #endif
303
304 #ifndef AV_RB64
305 #   define AV_RB64(x)                                   \
306     (((uint64_t)((const uint8_t*)(x))[0] << 56) |       \
307      ((uint64_t)((const uint8_t*)(x))[1] << 48) |       \
308      ((uint64_t)((const uint8_t*)(x))[2] << 40) |       \
309      ((uint64_t)((const uint8_t*)(x))[3] << 32) |       \
310      ((uint64_t)((const uint8_t*)(x))[4] << 24) |       \
311      ((uint64_t)((const uint8_t*)(x))[5] << 16) |       \
312      ((uint64_t)((const uint8_t*)(x))[6] <<  8) |       \
313       (uint64_t)((const uint8_t*)(x))[7])
314 #endif
315 #ifndef AV_WB64
316 #   define AV_WB64(p, val) do {                 \
317         uint64_t d = (val);                     \
318         ((uint8_t*)(p))[7] = (d);               \
319         ((uint8_t*)(p))[6] = (d)>>8;            \
320         ((uint8_t*)(p))[5] = (d)>>16;           \
321         ((uint8_t*)(p))[4] = (d)>>24;           \
322         ((uint8_t*)(p))[3] = (d)>>32;           \
323         ((uint8_t*)(p))[2] = (d)>>40;           \
324         ((uint8_t*)(p))[1] = (d)>>48;           \
325         ((uint8_t*)(p))[0] = (d)>>56;           \
326     } while(0)
327 #endif
328
329 #ifndef AV_RL64
330 #   define AV_RL64(x)                                   \
331     (((uint64_t)((const uint8_t*)(x))[7] << 56) |       \
332      ((uint64_t)((const uint8_t*)(x))[6] << 48) |       \
333      ((uint64_t)((const uint8_t*)(x))[5] << 40) |       \
334      ((uint64_t)((const uint8_t*)(x))[4] << 32) |       \
335      ((uint64_t)((const uint8_t*)(x))[3] << 24) |       \
336      ((uint64_t)((const uint8_t*)(x))[2] << 16) |       \
337      ((uint64_t)((const uint8_t*)(x))[1] <<  8) |       \
338       (uint64_t)((const uint8_t*)(x))[0])
339 #endif
340 #ifndef AV_WL64
341 #   define AV_WL64(p, val) do {                 \
342         uint64_t d = (val);                     \
343         ((uint8_t*)(p))[0] = (d);               \
344         ((uint8_t*)(p))[1] = (d)>>8;            \
345         ((uint8_t*)(p))[2] = (d)>>16;           \
346         ((uint8_t*)(p))[3] = (d)>>24;           \
347         ((uint8_t*)(p))[4] = (d)>>32;           \
348         ((uint8_t*)(p))[5] = (d)>>40;           \
349         ((uint8_t*)(p))[6] = (d)>>48;           \
350         ((uint8_t*)(p))[7] = (d)>>56;           \
351     } while(0)
352 #endif
353
354 #if AV_HAVE_BIGENDIAN
355 #   define AV_RN(s, p)    AV_RB##s(p)
356 #   define AV_WN(s, p, v) AV_WB##s(p, v)
357 #else
358 #   define AV_RN(s, p)    AV_RL##s(p)
359 #   define AV_WN(s, p, v) AV_WL##s(p, v)
360 #endif
361
362 #endif /* HAVE_FAST_UNALIGNED */
363
364 #ifndef AV_RN16
365 #   define AV_RN16(p) AV_RN(16, p)
366 #endif
367
368 #ifndef AV_RN32
369 #   define AV_RN32(p) AV_RN(32, p)
370 #endif
371
372 #ifndef AV_RN64
373 #   define AV_RN64(p) AV_RN(64, p)
374 #endif
375
376 #ifndef AV_WN16
377 #   define AV_WN16(p, v) AV_WN(16, p, v)
378 #endif
379
380 #ifndef AV_WN32
381 #   define AV_WN32(p, v) AV_WN(32, p, v)
382 #endif
383
384 #ifndef AV_WN64
385 #   define AV_WN64(p, v) AV_WN(64, p, v)
386 #endif
387
388 #if AV_HAVE_BIGENDIAN
389 #   define AV_RB(s, p)    AV_RN##s(p)
390 #   define AV_WB(s, p, v) AV_WN##s(p, v)
391 #   define AV_RL(s, p)    av_bswap##s(AV_RN##s(p))
392 #   define AV_WL(s, p, v) AV_WN##s(p, av_bswap##s(v))
393 #else
394 #   define AV_RB(s, p)    av_bswap##s(AV_RN##s(p))
395 #   define AV_WB(s, p, v) AV_WN##s(p, av_bswap##s(v))
396 #   define AV_RL(s, p)    AV_RN##s(p)
397 #   define AV_WL(s, p, v) AV_WN##s(p, v)
398 #endif
399
400 #define AV_RB8(x)     (((const uint8_t*)(x))[0])
401 #define AV_WB8(p, d)  do { ((uint8_t*)(p))[0] = (d); } while(0)
402
403 #define AV_RL8(x)     AV_RB8(x)
404 #define AV_WL8(p, d)  AV_WB8(p, d)
405
406 #ifndef AV_RB16
407 #   define AV_RB16(p)    AV_RB(16, p)
408 #endif
409 #ifndef AV_WB16
410 #   define AV_WB16(p, v) AV_WB(16, p, v)
411 #endif
412
413 #ifndef AV_RL16
414 #   define AV_RL16(p)    AV_RL(16, p)
415 #endif
416 #ifndef AV_WL16
417 #   define AV_WL16(p, v) AV_WL(16, p, v)
418 #endif
419
420 #ifndef AV_RB32
421 #   define AV_RB32(p)    AV_RB(32, p)
422 #endif
423 #ifndef AV_WB32
424 #   define AV_WB32(p, v) AV_WB(32, p, v)
425 #endif
426
427 #ifndef AV_RL32
428 #   define AV_RL32(p)    AV_RL(32, p)
429 #endif
430 #ifndef AV_WL32
431 #   define AV_WL32(p, v) AV_WL(32, p, v)
432 #endif
433
434 #ifndef AV_RB64
435 #   define AV_RB64(p)    AV_RB(64, p)
436 #endif
437 #ifndef AV_WB64
438 #   define AV_WB64(p, v) AV_WB(64, p, v)
439 #endif
440
441 #ifndef AV_RL64
442 #   define AV_RL64(p)    AV_RL(64, p)
443 #endif
444 #ifndef AV_WL64
445 #   define AV_WL64(p, v) AV_WL(64, p, v)
446 #endif
447
448 #ifndef AV_RB24
449 #   define AV_RB24(x)                           \
450     ((((const uint8_t*)(x))[0] << 16) |         \
451      (((const uint8_t*)(x))[1] <<  8) |         \
452       ((const uint8_t*)(x))[2])
453 #endif
454 #ifndef AV_WB24
455 #   define AV_WB24(p, d) do {                   \
456         ((uint8_t*)(p))[2] = (d);               \
457         ((uint8_t*)(p))[1] = (d)>>8;            \
458         ((uint8_t*)(p))[0] = (d)>>16;           \
459     } while(0)
460 #endif
461
462 #ifndef AV_RL24
463 #   define AV_RL24(x)                           \
464     ((((const uint8_t*)(x))[2] << 16) |         \
465      (((const uint8_t*)(x))[1] <<  8) |         \
466       ((const uint8_t*)(x))[0])
467 #endif
468 #ifndef AV_WL24
469 #   define AV_WL24(p, d) do {                   \
470         ((uint8_t*)(p))[0] = (d);               \
471         ((uint8_t*)(p))[1] = (d)>>8;            \
472         ((uint8_t*)(p))[2] = (d)>>16;           \
473     } while(0)
474 #endif
475
476 #ifndef AV_RB48
477 #   define AV_RB48(x)                                     \
478     (((uint64_t)((const uint8_t*)(x))[0] << 40) |         \
479      ((uint64_t)((const uint8_t*)(x))[1] << 32) |         \
480      ((uint64_t)((const uint8_t*)(x))[2] << 24) |         \
481      ((uint64_t)((const uint8_t*)(x))[3] << 16) |         \
482      ((uint64_t)((const uint8_t*)(x))[4] <<  8) |         \
483       (uint64_t)((const uint8_t*)(x))[5])
484 #endif
485 #ifndef AV_WB48
486 #   define AV_WB48(p, darg) do {                \
487         uint64_t d = (darg);                    \
488         ((uint8_t*)(p))[5] = (d);               \
489         ((uint8_t*)(p))[4] = (d)>>8;            \
490         ((uint8_t*)(p))[3] = (d)>>16;           \
491         ((uint8_t*)(p))[2] = (d)>>24;           \
492         ((uint8_t*)(p))[1] = (d)>>32;           \
493         ((uint8_t*)(p))[0] = (d)>>40;           \
494     } while(0)
495 #endif
496
497 #ifndef AV_RL48
498 #   define AV_RL48(x)                                     \
499     (((uint64_t)((const uint8_t*)(x))[5] << 40) |         \
500      ((uint64_t)((const uint8_t*)(x))[4] << 32) |         \
501      ((uint64_t)((const uint8_t*)(x))[3] << 24) |         \
502      ((uint64_t)((const uint8_t*)(x))[2] << 16) |         \
503      ((uint64_t)((const uint8_t*)(x))[1] <<  8) |         \
504       (uint64_t)((const uint8_t*)(x))[0])
505 #endif
506 #ifndef AV_WL48
507 #   define AV_WL48(p, darg) do {                \
508         uint64_t d = (darg);                    \
509         ((uint8_t*)(p))[0] = (d);               \
510         ((uint8_t*)(p))[1] = (d)>>8;            \
511         ((uint8_t*)(p))[2] = (d)>>16;           \
512         ((uint8_t*)(p))[3] = (d)>>24;           \
513         ((uint8_t*)(p))[4] = (d)>>32;           \
514         ((uint8_t*)(p))[5] = (d)>>40;           \
515     } while(0)
516 #endif
517
518 /*
519  * The AV_[RW]NA macros access naturally aligned data
520  * in a type-safe way.
521  */
522
523 #define AV_RNA(s, p)    (((const av_alias##s*)(p))->u##s)
524 #define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
525
526 #ifndef AV_RN16A
527 #   define AV_RN16A(p) AV_RNA(16, p)
528 #endif
529
530 #ifndef AV_RN32A
531 #   define AV_RN32A(p) AV_RNA(32, p)
532 #endif
533
534 #ifndef AV_RN64A
535 #   define AV_RN64A(p) AV_RNA(64, p)
536 #endif
537
538 #ifndef AV_WN16A
539 #   define AV_WN16A(p, v) AV_WNA(16, p, v)
540 #endif
541
542 #ifndef AV_WN32A
543 #   define AV_WN32A(p, v) AV_WNA(32, p, v)
544 #endif
545
546 #ifndef AV_WN64A
547 #   define AV_WN64A(p, v) AV_WNA(64, p, v)
548 #endif
549
550 /*
551  * The AV_COPYxxU macros are suitable for copying data to/from unaligned
552  * memory locations.
553  */
554
555 #define AV_COPYU(n, d, s) AV_WN##n(d, AV_RN##n(s));
556
557 #ifndef AV_COPY16U
558 #   define AV_COPY16U(d, s) AV_COPYU(16, d, s)
559 #endif
560
561 #ifndef AV_COPY32U
562 #   define AV_COPY32U(d, s) AV_COPYU(32, d, s)
563 #endif
564
565 #ifndef AV_COPY64U
566 #   define AV_COPY64U(d, s) AV_COPYU(64, d, s)
567 #endif
568
569 #ifndef AV_COPY128U
570 #   define AV_COPY128U(d, s)                                    \
571     do {                                                        \
572         AV_COPY64U(d, s);                                       \
573         AV_COPY64U((char *)(d) + 8, (const char *)(s) + 8);     \
574     } while(0)
575 #endif
576
577 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
578  * naturally aligned. They may be implemented using MMX,
579  * so emms_c() must be called before using any float code
580  * afterwards.
581  */
582
583 #define AV_COPY(n, d, s) \
584     (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
585
586 #ifndef AV_COPY16
587 #   define AV_COPY16(d, s) AV_COPY(16, d, s)
588 #endif
589
590 #ifndef AV_COPY32
591 #   define AV_COPY32(d, s) AV_COPY(32, d, s)
592 #endif
593
594 #ifndef AV_COPY64
595 #   define AV_COPY64(d, s) AV_COPY(64, d, s)
596 #endif
597
598 #ifndef AV_COPY128
599 #   define AV_COPY128(d, s)                    \
600     do {                                       \
601         AV_COPY64(d, s);                       \
602         AV_COPY64((char*)(d)+8, (char*)(s)+8); \
603     } while(0)
604 #endif
605
606 #define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
607
608 #ifndef AV_SWAP64
609 #   define AV_SWAP64(a, b) AV_SWAP(64, a, b)
610 #endif
611
612 #define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
613
614 #ifndef AV_ZERO16
615 #   define AV_ZERO16(d) AV_ZERO(16, d)
616 #endif
617
618 #ifndef AV_ZERO32
619 #   define AV_ZERO32(d) AV_ZERO(32, d)
620 #endif
621
622 #ifndef AV_ZERO64
623 #   define AV_ZERO64(d) AV_ZERO(64, d)
624 #endif
625
626 #ifndef AV_ZERO128
627 #   define AV_ZERO128(d)         \
628     do {                         \
629         AV_ZERO64(d);            \
630         AV_ZERO64((char*)(d)+8); \
631     } while(0)
632 #endif
633
634 #endif /* AVUTIL_INTREADWRITE_H */