| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of FFmpeg. | 2 * This file is part of FFmpeg. |
| 3 * | 3 * |
| 4 * FFmpeg is free software; you can redistribute it and/or | 4 * FFmpeg is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Lesser General Public | 5 * modify it under the terms of the GNU Lesser General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2.1 of the License, or (at your option) any later version. | 7 * version 2.1 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * FFmpeg is distributed in the hope that it will be useful, | 9 * FFmpeg is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Lesser General Public License for more details. | 12 * Lesser General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Lesser General Public | 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 | 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 | 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 #ifndef AVUTIL_INTREADWRITE_H | 19 #ifndef AVUTIL_INTREADWRITE_H |
| 20 #define AVUTIL_INTREADWRITE_H | 20 #define AVUTIL_INTREADWRITE_H |
| 21 | 21 |
| 22 #include <stdint.h> | 22 #include <stdint.h> |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "bswap.h" | 24 #include "bswap.h" |
| 25 #include "common.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; |
| 25 | 47 |
| 26 /* | 48 /* |
| 27 * Arch-specific headers can provide any combination of | 49 * Arch-specific headers can provide any combination of |
| 28 * AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros. | 50 * AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros. |
| 29 * Preprocessor symbols must be defined, even if these are implemented | 51 * Preprocessor symbols must be defined, even if these are implemented |
| 30 * as inline functions. | 52 * as inline functions. |
| 31 */ | 53 */ |
| 32 | 54 |
| 33 #if ARCH_ARM | 55 #if ARCH_ARM |
| 34 # include "arm/intreadwrite.h" | 56 # include "arm/intreadwrite.h" |
| 35 #elif ARCH_AVR32 | 57 #elif ARCH_AVR32 |
| 36 # include "avr32/intreadwrite.h" | 58 # include "avr32/intreadwrite.h" |
| 37 #elif ARCH_MIPS | 59 #elif ARCH_MIPS |
| 38 # include "mips/intreadwrite.h" | 60 # include "mips/intreadwrite.h" |
| 39 #elif ARCH_PPC | 61 #elif ARCH_PPC |
| 40 # include "ppc/intreadwrite.h" | 62 # include "ppc/intreadwrite.h" |
| 63 #elif ARCH_TOMI |
| 64 # include "tomi/intreadwrite.h" |
| 41 #elif ARCH_X86 | 65 #elif ARCH_X86 |
| 42 # include "x86/intreadwrite.h" | 66 # include "x86/intreadwrite.h" |
| 43 #endif | 67 #endif |
| 44 | 68 |
| 45 /* | 69 /* |
| 46 * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers. | 70 * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers. |
| 47 */ | 71 */ |
| 48 | 72 |
| 49 #if HAVE_BIGENDIAN | 73 #if HAVE_BIGENDIAN |
| 50 | 74 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 172 |
| 149 #endif /* !HAVE_BIGENDIAN */ | 173 #endif /* !HAVE_BIGENDIAN */ |
| 150 | 174 |
| 151 /* | 175 /* |
| 152 * Define AV_[RW]N helper macros to simplify definitions not provided | 176 * Define AV_[RW]N helper macros to simplify definitions not provided |
| 153 * by per-arch headers. | 177 * by per-arch headers. |
| 154 */ | 178 */ |
| 155 | 179 |
| 156 #if HAVE_ATTRIBUTE_PACKED | 180 #if HAVE_ATTRIBUTE_PACKED |
| 157 | 181 |
| 158 struct unaligned_64 { uint64_t l; } __attribute__((packed)); | 182 union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias; |
| 159 struct unaligned_32 { uint32_t l; } __attribute__((packed)); | 183 union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias; |
| 160 struct unaligned_16 { uint16_t l; } __attribute__((packed)); | 184 union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias; |
| 161 | 185 |
| 162 # define AV_RN(s, p) (((const struct unaligned_##s *) (p))->l) | 186 # define AV_RN(s, p) (((const union unaligned_##s *) (p))->l) |
| 163 # define AV_WN(s, p, v) ((((struct unaligned_##s *) (p))->l) = (v)) | 187 # define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v)) |
| 164 | 188 |
| 165 #elif defined(__DECC) | 189 #elif defined(__DECC) |
| 166 | 190 |
| 167 # define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p))) | 191 # define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p))) |
| 168 # define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v)) | 192 # define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v)) |
| 169 | 193 |
| 170 #elif HAVE_FAST_UNALIGNED | 194 #elif HAVE_FAST_UNALIGNED |
| 171 | 195 |
| 172 # define AV_RN(s, p) (*((const uint##s##_t*)(p))) | 196 # define AV_RN(s, p) (((const av_alias##s*)(p))->u##s) |
| 173 # define AV_WN(s, p, v) (*((uint##s##_t*)(p)) = (v)) | 197 # define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v)) |
| 174 | 198 |
| 175 #else | 199 #else |
| 176 | 200 |
| 177 #ifndef AV_RB16 | 201 #ifndef AV_RB16 |
| 178 # define AV_RB16(x) \ | 202 # define AV_RB16(x) \ |
| 179 ((((const uint8_t*)(x))[0] << 8) | \ | 203 ((((const uint8_t*)(x))[0] << 8) | \ |
| 180 ((const uint8_t*)(x))[1]) | 204 ((const uint8_t*)(x))[1]) |
| 181 #endif | 205 #endif |
| 182 #ifndef AV_WB16 | 206 #ifndef AV_WB16 |
| 183 # define AV_WB16(p, d) do { \ | 207 # define AV_WB16(p, d) do { \ |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 ((const uint8_t*)(x))[0]) | 417 ((const uint8_t*)(x))[0]) |
| 394 #endif | 418 #endif |
| 395 #ifndef AV_WL24 | 419 #ifndef AV_WL24 |
| 396 # define AV_WL24(p, d) do { \ | 420 # define AV_WL24(p, d) do { \ |
| 397 ((uint8_t*)(p))[0] = (d); \ | 421 ((uint8_t*)(p))[0] = (d); \ |
| 398 ((uint8_t*)(p))[1] = (d)>>8; \ | 422 ((uint8_t*)(p))[1] = (d)>>8; \ |
| 399 ((uint8_t*)(p))[2] = (d)>>16; \ | 423 ((uint8_t*)(p))[2] = (d)>>16; \ |
| 400 } while(0) | 424 } while(0) |
| 401 #endif | 425 #endif |
| 402 | 426 |
| 427 /* |
| 428 * The AV_[RW]NA macros access naturally aligned data |
| 429 * in a type-safe way. |
| 430 */ |
| 431 |
| 432 #define AV_RNA(s, p) (((const av_alias##s*)(p))->u##s) |
| 433 #define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v)) |
| 434 |
| 435 #ifndef AV_RN16A |
| 436 # define AV_RN16A(p) AV_RNA(16, p) |
| 437 #endif |
| 438 |
| 439 #ifndef AV_RN32A |
| 440 # define AV_RN32A(p) AV_RNA(32, p) |
| 441 #endif |
| 442 |
| 443 #ifndef AV_RN64A |
| 444 # define AV_RN64A(p) AV_RNA(64, p) |
| 445 #endif |
| 446 |
| 447 #ifndef AV_WN16A |
| 448 # define AV_WN16A(p, v) AV_WNA(16, p, v) |
| 449 #endif |
| 450 |
| 451 #ifndef AV_WN32A |
| 452 # define AV_WN32A(p, v) AV_WNA(32, p, v) |
| 453 #endif |
| 454 |
| 455 #ifndef AV_WN64A |
| 456 # define AV_WN64A(p, v) AV_WNA(64, p, v) |
| 457 #endif |
| 458 |
| 403 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be | 459 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be |
| 404 * naturally aligned. They may be implemented using MMX, | 460 * naturally aligned. They may be implemented using MMX, |
| 405 * so emms_c() must be called before using any float code | 461 * so emms_c() must be called before using any float code |
| 406 * afterwards. | 462 * afterwards. |
| 407 */ | 463 */ |
| 408 | 464 |
| 409 #define AV_COPY(n, d, s) (*(uint##n##_t*)(d) = *(const uint##n##_t*)(s)) | 465 #define AV_COPY(n, d, s) \ |
| 466 (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n) |
| 467 |
| 468 #ifndef AV_COPY16 |
| 469 # define AV_COPY16(d, s) AV_COPY(16, d, s) |
| 470 #endif |
| 410 | 471 |
| 411 #ifndef AV_COPY32 | 472 #ifndef AV_COPY32 |
| 412 # define AV_COPY32(d, s) AV_COPY(32, d, s) | 473 # define AV_COPY32(d, s) AV_COPY(32, d, s) |
| 413 #endif | 474 #endif |
| 414 | 475 |
| 415 #ifndef AV_COPY64 | 476 #ifndef AV_COPY64 |
| 416 # define AV_COPY64(d, s) AV_COPY(64, d, s) | 477 # define AV_COPY64(d, s) AV_COPY(64, d, s) |
| 417 #endif | 478 #endif |
| 418 | 479 |
| 419 #ifndef AV_COPY128 | 480 #ifndef AV_COPY128 |
| 420 # define AV_COPY128(d, s) \ | 481 # define AV_COPY128(d, s) \ |
| 421 do { \ | 482 do { \ |
| 422 AV_COPY64(d, s); \ | 483 AV_COPY64(d, s); \ |
| 423 AV_COPY64((char*)(d)+8, (char*)(s)+8); \ | 484 AV_COPY64((char*)(d)+8, (char*)(s)+8); \ |
| 424 } while(0) | 485 } while(0) |
| 425 #endif | 486 #endif |
| 426 | 487 |
| 427 #define AV_SWAP(n, a, b) FFSWAP(uint##n##_t, *(uint##n##_t*)(a), *(uint##n##_t*)
(b)) | 488 #define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)
(b)) |
| 428 | 489 |
| 429 #ifndef AV_SWAP64 | 490 #ifndef AV_SWAP64 |
| 430 # define AV_SWAP64(a, b) AV_SWAP(64, a, b) | 491 # define AV_SWAP64(a, b) AV_SWAP(64, a, b) |
| 431 #endif | 492 #endif |
| 432 | 493 |
| 433 #define AV_ZERO(n, d) (*(uint##n##_t*)(d) = 0) | 494 #define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0) |
| 495 |
| 496 #ifndef AV_ZERO16 |
| 497 # define AV_ZERO16(d) AV_ZERO(16, d) |
| 498 #endif |
| 499 |
| 500 #ifndef AV_ZERO32 |
| 501 # define AV_ZERO32(d) AV_ZERO(32, d) |
| 502 #endif |
| 434 | 503 |
| 435 #ifndef AV_ZERO64 | 504 #ifndef AV_ZERO64 |
| 436 # define AV_ZERO64(d) AV_ZERO(64, d) | 505 # define AV_ZERO64(d) AV_ZERO(64, d) |
| 437 #endif | 506 #endif |
| 438 | 507 |
| 439 #ifndef AV_ZERO128 | 508 #ifndef AV_ZERO128 |
| 440 # define AV_ZERO128(d) \ | 509 # define AV_ZERO128(d) \ |
| 441 do { \ | 510 do { \ |
| 442 AV_ZERO64(d); \ | 511 AV_ZERO64(d); \ |
| 443 AV_ZERO64((char*)(d)+8); \ | 512 AV_ZERO64((char*)(d)+8); \ |
| 444 } while(0) | 513 } while(0) |
| 445 #endif | 514 #endif |
| 446 | 515 |
| 447 #endif /* AVUTIL_INTREADWRITE_H */ | 516 #endif /* AVUTIL_INTREADWRITE_H */ |
| OLD | NEW |