19 #ifndef AVUTIL_INTREADWRITE_H
20 #define AVUTIL_INTREADWRITE_H
23 #include "libavutil/avconfig.h"
63 #ifdef HAVE_AV_CONFIG_H
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
218 #if defined(__GNUC__) && !defined(__TI_COMPILER_VERSION__)
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))
227 #elif defined(__DECC)
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))
232 #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_X64)) && AV_HAVE_FAST_UNALIGNED
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))
237 #elif AV_HAVE_FAST_UNALIGNED
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))
245 # define AV_RB16(x) \
246 ((((const uint8_t*)(x))[0] << 8) | \
247 ((const uint8_t*)(x))[1])
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; \
258 # define AV_RL16(x) \
259 ((((const uint8_t*)(x))[1] << 8) | \
260 ((const uint8_t*)(x))[0])
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; \
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])
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; \
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])
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; \
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])
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; \
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])
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; \
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)
358 # define AV_RN(s, p) AV_RL##s(p)
359 # define AV_WN(s, p, v) AV_WL##s(p, v)
365 # define AV_RN16(p) AV_RN(16, p)
369 # define AV_RN32(p) AV_RN(32, p)
373 # define AV_RN64(p) AV_RN(64, p)
377 # define AV_WN16(p, v) AV_WN(16, p, v)
381 # define AV_WN32(p, v) AV_WN(32, p, v)
385 # define AV_WN64(p, v) AV_WN(64, p, v)
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))
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)
400 #define AV_RB8(x) (((const uint8_t*)(x))[0])
401 #define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
403 #define AV_RL8(x) AV_RB8(x)
404 #define AV_WL8(p, d) AV_WB8(p, d)
407 # define AV_RB16(p) AV_RB(16, p)
410 # define AV_WB16(p, v) AV_WB(16, p, v)
414 # define AV_RL16(p) AV_RL(16, p)
417 # define AV_WL16(p, v) AV_WL(16, p, v)
421 # define AV_RB32(p) AV_RB(32, p)
424 # define AV_WB32(p, v) AV_WB(32, p, v)
428 # define AV_RL32(p) AV_RL(32, p)
431 # define AV_WL32(p, v) AV_WL(32, p, v)
435 # define AV_RB64(p) AV_RB(64, p)
438 # define AV_WB64(p, v) AV_WB(64, p, v)
442 # define AV_RL64(p) AV_RL(64, p)
445 # define AV_WL64(p, v) AV_WL(64, p, v)
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])
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; \
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])
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; \
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])
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; \
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])
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; \
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))
527 # define AV_RN16A(p) AV_RNA(16, p)
531 # define AV_RN32A(p) AV_RNA(32, p)
535 # define AV_RN64A(p) AV_RNA(64, p)
539 # define AV_WN16A(p, v) AV_WNA(16, p, v)
543 # define AV_WN32A(p, v) AV_WNA(32, p, v)
547 # define AV_WN64A(p, v) AV_WNA(64, p, v)
555 #define AV_COPYU(n, d, s) AV_WN##n(d, AV_RN##n(s));
558 # define AV_COPY16U(d, s) AV_COPYU(16, d, s)
562 # define AV_COPY32U(d, s) AV_COPYU(32, d, s)
566 # define AV_COPY64U(d, s) AV_COPYU(64, d, s)
570 # define AV_COPY128U(d, s) \
573 AV_COPY64U((char *)(d) + 8, (const char *)(s) + 8); \
583 #define AV_COPY(n, d, s) \
584 (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
587 # define AV_COPY16(d, s) AV_COPY(16, d, s)
591 # define AV_COPY32(d, s) AV_COPY(32, d, s)
595 # define AV_COPY64(d, s) AV_COPY(64, d, s)
599 # define AV_COPY128(d, s) \
602 AV_COPY64((char*)(d)+8, (char*)(s)+8); \
606 #define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
609 # define AV_SWAP64(a, b) AV_SWAP(64, a, b)
612 #define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
615 # define AV_ZERO16(d) AV_ZERO(16, d)
619 # define AV_ZERO32(d) AV_ZERO(32, d)
623 # define AV_ZERO64(d) AV_ZERO(64, d)
627 # define AV_ZERO128(d) \
630 AV_ZERO64((char*)(d)+8); \
Macro definitions for various function/variable attributes.