00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef AVUTIL_INTREADWRITE_H
00020 #define AVUTIL_INTREADWRITE_H
00021
00022 #include <stdint.h>
00023 #include "libavutil/avconfig.h"
00024 #include "attributes.h"
00025 #include "bswap.h"
00026
00027 typedef union {
00028 uint64_t u64;
00029 uint32_t u32[2];
00030 uint16_t u16[4];
00031 uint8_t u8 [8];
00032 double f64;
00033 float f32[2];
00034 } av_alias av_alias64;
00035
00036 typedef union {
00037 uint32_t u32;
00038 uint16_t u16[2];
00039 uint8_t u8 [4];
00040 float f32;
00041 } av_alias av_alias32;
00042
00043 typedef union {
00044 uint16_t u16;
00045 uint8_t u8 [2];
00046 } av_alias av_alias16;
00047
00048
00049
00050
00051
00052
00053
00054
00055 #ifdef HAVE_AV_CONFIG_H
00056
00057 #include "config.h"
00058
00059 #if ARCH_ARM
00060 # include "arm/intreadwrite.h"
00061 #elif ARCH_AVR32
00062 # include "avr32/intreadwrite.h"
00063 #elif ARCH_MIPS
00064 # include "mips/intreadwrite.h"
00065 #elif ARCH_PPC
00066 # include "ppc/intreadwrite.h"
00067 #elif ARCH_TOMI
00068 # include "tomi/intreadwrite.h"
00069 #elif ARCH_X86
00070 # include "x86/intreadwrite.h"
00071 #endif
00072
00073 #endif
00074
00075
00076
00077
00078
00079 #if AV_HAVE_BIGENDIAN
00080
00081 # if defined(AV_RN16) && !defined(AV_RB16)
00082 # define AV_RB16(p) AV_RN16(p)
00083 # elif !defined(AV_RN16) && defined(AV_RB16)
00084 # define AV_RN16(p) AV_RB16(p)
00085 # endif
00086
00087 # if defined(AV_WN16) && !defined(AV_WB16)
00088 # define AV_WB16(p, v) AV_WN16(p, v)
00089 # elif !defined(AV_WN16) && defined(AV_WB16)
00090 # define AV_WN16(p, v) AV_WB16(p, v)
00091 # endif
00092
00093 # if defined(AV_RN24) && !defined(AV_RB24)
00094 # define AV_RB24(p) AV_RN24(p)
00095 # elif !defined(AV_RN24) && defined(AV_RB24)
00096 # define AV_RN24(p) AV_RB24(p)
00097 # endif
00098
00099 # if defined(AV_WN24) && !defined(AV_WB24)
00100 # define AV_WB24(p, v) AV_WN24(p, v)
00101 # elif !defined(AV_WN24) && defined(AV_WB24)
00102 # define AV_WN24(p, v) AV_WB24(p, v)
00103 # endif
00104
00105 # if defined(AV_RN32) && !defined(AV_RB32)
00106 # define AV_RB32(p) AV_RN32(p)
00107 # elif !defined(AV_RN32) && defined(AV_RB32)
00108 # define AV_RN32(p) AV_RB32(p)
00109 # endif
00110
00111 # if defined(AV_WN32) && !defined(AV_WB32)
00112 # define AV_WB32(p, v) AV_WN32(p, v)
00113 # elif !defined(AV_WN32) && defined(AV_WB32)
00114 # define AV_WN32(p, v) AV_WB32(p, v)
00115 # endif
00116
00117 # if defined(AV_RN64) && !defined(AV_RB64)
00118 # define AV_RB64(p) AV_RN64(p)
00119 # elif !defined(AV_RN64) && defined(AV_RB64)
00120 # define AV_RN64(p) AV_RB64(p)
00121 # endif
00122
00123 # if defined(AV_WN64) && !defined(AV_WB64)
00124 # define AV_WB64(p, v) AV_WN64(p, v)
00125 # elif !defined(AV_WN64) && defined(AV_WB64)
00126 # define AV_WN64(p, v) AV_WB64(p, v)
00127 # endif
00128
00129 #else
00130
00131 # if defined(AV_RN16) && !defined(AV_RL16)
00132 # define AV_RL16(p) AV_RN16(p)
00133 # elif !defined(AV_RN16) && defined(AV_RL16)
00134 # define AV_RN16(p) AV_RL16(p)
00135 # endif
00136
00137 # if defined(AV_WN16) && !defined(AV_WL16)
00138 # define AV_WL16(p, v) AV_WN16(p, v)
00139 # elif !defined(AV_WN16) && defined(AV_WL16)
00140 # define AV_WN16(p, v) AV_WL16(p, v)
00141 # endif
00142
00143 # if defined(AV_RN24) && !defined(AV_RL24)
00144 # define AV_RL24(p) AV_RN24(p)
00145 # elif !defined(AV_RN24) && defined(AV_RL24)
00146 # define AV_RN24(p) AV_RL24(p)
00147 # endif
00148
00149 # if defined(AV_WN24) && !defined(AV_WL24)
00150 # define AV_WL24(p, v) AV_WN24(p, v)
00151 # elif !defined(AV_WN24) && defined(AV_WL24)
00152 # define AV_WN24(p, v) AV_WL24(p, v)
00153 # endif
00154
00155 # if defined(AV_RN32) && !defined(AV_RL32)
00156 # define AV_RL32(p) AV_RN32(p)
00157 # elif !defined(AV_RN32) && defined(AV_RL32)
00158 # define AV_RN32(p) AV_RL32(p)
00159 # endif
00160
00161 # if defined(AV_WN32) && !defined(AV_WL32)
00162 # define AV_WL32(p, v) AV_WN32(p, v)
00163 # elif !defined(AV_WN32) && defined(AV_WL32)
00164 # define AV_WN32(p, v) AV_WL32(p, v)
00165 # endif
00166
00167 # if defined(AV_RN64) && !defined(AV_RL64)
00168 # define AV_RL64(p) AV_RN64(p)
00169 # elif !defined(AV_RN64) && defined(AV_RL64)
00170 # define AV_RN64(p) AV_RL64(p)
00171 # endif
00172
00173 # if defined(AV_WN64) && !defined(AV_WL64)
00174 # define AV_WL64(p, v) AV_WN64(p, v)
00175 # elif !defined(AV_WN64) && defined(AV_WL64)
00176 # define AV_WN64(p, v) AV_WL64(p, v)
00177 # endif
00178
00179 #endif
00180
00181
00182
00183
00184
00185
00186 #if defined(__GNUC__) && !defined(__TI_COMPILER_VERSION__)
00187
00188 union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
00189 union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
00190 union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
00191
00192 # define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
00193 # define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
00194
00195 #elif defined(__DECC)
00196
00197 # define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
00198 # define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
00199
00200 #elif AV_HAVE_FAST_UNALIGNED
00201
00202 # define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
00203 # define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
00204
00205 #else
00206
00207 #ifndef AV_RB16
00208 # define AV_RB16(x) \
00209 ((((const uint8_t*)(x))[0] << 8) | \
00210 ((const uint8_t*)(x))[1])
00211 #endif
00212 #ifndef AV_WB16
00213 # define AV_WB16(p, darg) do { \
00214 unsigned d = (darg); \
00215 ((uint8_t*)(p))[1] = (d); \
00216 ((uint8_t*)(p))[0] = (d)>>8; \
00217 } while(0)
00218 #endif
00219
00220 #ifndef AV_RL16
00221 # define AV_RL16(x) \
00222 ((((const uint8_t*)(x))[1] << 8) | \
00223 ((const uint8_t*)(x))[0])
00224 #endif
00225 #ifndef AV_WL16
00226 # define AV_WL16(p, darg) do { \
00227 unsigned d = (darg); \
00228 ((uint8_t*)(p))[0] = (d); \
00229 ((uint8_t*)(p))[1] = (d)>>8; \
00230 } while(0)
00231 #endif
00232
00233 #ifndef AV_RB32
00234 # define AV_RB32(x) \
00235 (((uint32_t)((const uint8_t*)(x))[0] << 24) | \
00236 (((const uint8_t*)(x))[1] << 16) | \
00237 (((const uint8_t*)(x))[2] << 8) | \
00238 ((const uint8_t*)(x))[3])
00239 #endif
00240 #ifndef AV_WB32
00241 # define AV_WB32(p, darg) do { \
00242 unsigned d = (darg); \
00243 ((uint8_t*)(p))[3] = (d); \
00244 ((uint8_t*)(p))[2] = (d)>>8; \
00245 ((uint8_t*)(p))[1] = (d)>>16; \
00246 ((uint8_t*)(p))[0] = (d)>>24; \
00247 } while(0)
00248 #endif
00249
00250 #ifndef AV_RL32
00251 # define AV_RL32(x) \
00252 (((uint32_t)((const uint8_t*)(x))[3] << 24) | \
00253 (((const uint8_t*)(x))[2] << 16) | \
00254 (((const uint8_t*)(x))[1] << 8) | \
00255 ((const uint8_t*)(x))[0])
00256 #endif
00257 #ifndef AV_WL32
00258 # define AV_WL32(p, darg) do { \
00259 unsigned d = (darg); \
00260 ((uint8_t*)(p))[0] = (d); \
00261 ((uint8_t*)(p))[1] = (d)>>8; \
00262 ((uint8_t*)(p))[2] = (d)>>16; \
00263 ((uint8_t*)(p))[3] = (d)>>24; \
00264 } while(0)
00265 #endif
00266
00267 #ifndef AV_RB64
00268 # define AV_RB64(x) \
00269 (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
00270 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
00271 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
00272 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
00273 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
00274 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
00275 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
00276 (uint64_t)((const uint8_t*)(x))[7])
00277 #endif
00278 #ifndef AV_WB64
00279 # define AV_WB64(p, darg) do { \
00280 uint64_t d = (darg); \
00281 ((uint8_t*)(p))[7] = (d); \
00282 ((uint8_t*)(p))[6] = (d)>>8; \
00283 ((uint8_t*)(p))[5] = (d)>>16; \
00284 ((uint8_t*)(p))[4] = (d)>>24; \
00285 ((uint8_t*)(p))[3] = (d)>>32; \
00286 ((uint8_t*)(p))[2] = (d)>>40; \
00287 ((uint8_t*)(p))[1] = (d)>>48; \
00288 ((uint8_t*)(p))[0] = (d)>>56; \
00289 } while(0)
00290 #endif
00291
00292 #ifndef AV_RL64
00293 # define AV_RL64(x) \
00294 (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
00295 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
00296 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
00297 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
00298 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
00299 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
00300 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
00301 (uint64_t)((const uint8_t*)(x))[0])
00302 #endif
00303 #ifndef AV_WL64
00304 # define AV_WL64(p, darg) do { \
00305 uint64_t d = (darg); \
00306 ((uint8_t*)(p))[0] = (d); \
00307 ((uint8_t*)(p))[1] = (d)>>8; \
00308 ((uint8_t*)(p))[2] = (d)>>16; \
00309 ((uint8_t*)(p))[3] = (d)>>24; \
00310 ((uint8_t*)(p))[4] = (d)>>32; \
00311 ((uint8_t*)(p))[5] = (d)>>40; \
00312 ((uint8_t*)(p))[6] = (d)>>48; \
00313 ((uint8_t*)(p))[7] = (d)>>56; \
00314 } while(0)
00315 #endif
00316
00317 #if AV_HAVE_BIGENDIAN
00318 # define AV_RN(s, p) AV_RB##s(p)
00319 # define AV_WN(s, p, v) AV_WB##s(p, v)
00320 #else
00321 # define AV_RN(s, p) AV_RL##s(p)
00322 # define AV_WN(s, p, v) AV_WL##s(p, v)
00323 #endif
00324
00325 #endif
00326
00327 #ifndef AV_RN16
00328 # define AV_RN16(p) AV_RN(16, p)
00329 #endif
00330
00331 #ifndef AV_RN32
00332 # define AV_RN32(p) AV_RN(32, p)
00333 #endif
00334
00335 #ifndef AV_RN64
00336 # define AV_RN64(p) AV_RN(64, p)
00337 #endif
00338
00339 #ifndef AV_WN16
00340 # define AV_WN16(p, v) AV_WN(16, p, v)
00341 #endif
00342
00343 #ifndef AV_WN32
00344 # define AV_WN32(p, v) AV_WN(32, p, v)
00345 #endif
00346
00347 #ifndef AV_WN64
00348 # define AV_WN64(p, v) AV_WN(64, p, v)
00349 #endif
00350
00351 #if AV_HAVE_BIGENDIAN
00352 # define AV_RB(s, p) AV_RN##s(p)
00353 # define AV_WB(s, p, v) AV_WN##s(p, v)
00354 # define AV_RL(s, p) av_bswap##s(AV_RN##s(p))
00355 # define AV_WL(s, p, v) AV_WN##s(p, av_bswap##s(v))
00356 #else
00357 # define AV_RB(s, p) av_bswap##s(AV_RN##s(p))
00358 # define AV_WB(s, p, v) AV_WN##s(p, av_bswap##s(v))
00359 # define AV_RL(s, p) AV_RN##s(p)
00360 # define AV_WL(s, p, v) AV_WN##s(p, v)
00361 #endif
00362
00363 #define AV_RB8(x) (((const uint8_t*)(x))[0])
00364 #define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
00365
00366 #define AV_RL8(x) AV_RB8(x)
00367 #define AV_WL8(p, d) AV_WB8(p, d)
00368
00369 #ifndef AV_RB16
00370 # define AV_RB16(p) AV_RB(16, p)
00371 #endif
00372 #ifndef AV_WB16
00373 # define AV_WB16(p, v) AV_WB(16, p, v)
00374 #endif
00375
00376 #ifndef AV_RL16
00377 # define AV_RL16(p) AV_RL(16, p)
00378 #endif
00379 #ifndef AV_WL16
00380 # define AV_WL16(p, v) AV_WL(16, p, v)
00381 #endif
00382
00383 #ifndef AV_RB32
00384 # define AV_RB32(p) AV_RB(32, p)
00385 #endif
00386 #ifndef AV_WB32
00387 # define AV_WB32(p, v) AV_WB(32, p, v)
00388 #endif
00389
00390 #ifndef AV_RL32
00391 # define AV_RL32(p) AV_RL(32, p)
00392 #endif
00393 #ifndef AV_WL32
00394 # define AV_WL32(p, v) AV_WL(32, p, v)
00395 #endif
00396
00397 #ifndef AV_RB64
00398 # define AV_RB64(p) AV_RB(64, p)
00399 #endif
00400 #ifndef AV_WB64
00401 # define AV_WB64(p, v) AV_WB(64, p, v)
00402 #endif
00403
00404 #ifndef AV_RL64
00405 # define AV_RL64(p) AV_RL(64, p)
00406 #endif
00407 #ifndef AV_WL64
00408 # define AV_WL64(p, v) AV_WL(64, p, v)
00409 #endif
00410
00411 #ifndef AV_RB24
00412 # define AV_RB24(x) \
00413 ((((const uint8_t*)(x))[0] << 16) | \
00414 (((const uint8_t*)(x))[1] << 8) | \
00415 ((const uint8_t*)(x))[2])
00416 #endif
00417 #ifndef AV_WB24
00418 # define AV_WB24(p, d) do { \
00419 ((uint8_t*)(p))[2] = (d); \
00420 ((uint8_t*)(p))[1] = (d)>>8; \
00421 ((uint8_t*)(p))[0] = (d)>>16; \
00422 } while(0)
00423 #endif
00424
00425 #ifndef AV_RL24
00426 # define AV_RL24(x) \
00427 ((((const uint8_t*)(x))[2] << 16) | \
00428 (((const uint8_t*)(x))[1] << 8) | \
00429 ((const uint8_t*)(x))[0])
00430 #endif
00431 #ifndef AV_WL24
00432 # define AV_WL24(p, d) do { \
00433 ((uint8_t*)(p))[0] = (d); \
00434 ((uint8_t*)(p))[1] = (d)>>8; \
00435 ((uint8_t*)(p))[2] = (d)>>16; \
00436 } while(0)
00437 #endif
00438
00439
00440
00441
00442
00443
00444 #define AV_RNA(s, p) (((const av_alias##s*)(p))->u##s)
00445 #define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
00446
00447 #ifndef AV_RN16A
00448 # define AV_RN16A(p) AV_RNA(16, p)
00449 #endif
00450
00451 #ifndef AV_RN32A
00452 # define AV_RN32A(p) AV_RNA(32, p)
00453 #endif
00454
00455 #ifndef AV_RN64A
00456 # define AV_RN64A(p) AV_RNA(64, p)
00457 #endif
00458
00459 #ifndef AV_WN16A
00460 # define AV_WN16A(p, v) AV_WNA(16, p, v)
00461 #endif
00462
00463 #ifndef AV_WN32A
00464 # define AV_WN32A(p, v) AV_WNA(32, p, v)
00465 #endif
00466
00467 #ifndef AV_WN64A
00468 # define AV_WN64A(p, v) AV_WNA(64, p, v)
00469 #endif
00470
00471
00472
00473
00474
00475
00476 #define AV_COPYU(n, d, s) AV_WN##n(d, AV_RN##n(s));
00477
00478 #ifndef AV_COPY16U
00479 # define AV_COPY16U(d, s) AV_COPYU(16, d, s)
00480 #endif
00481
00482 #ifndef AV_COPY32U
00483 # define AV_COPY32U(d, s) AV_COPYU(32, d, s)
00484 #endif
00485
00486 #ifndef AV_COPY64U
00487 # define AV_COPY64U(d, s) AV_COPYU(64, d, s)
00488 #endif
00489
00490 #ifndef AV_COPY128U
00491 # define AV_COPY128U(d, s) \
00492 do { \
00493 AV_COPY64U(d, s); \
00494 AV_COPY64U((char *)(d) + 8, (const char *)(s) + 8); \
00495 } while(0)
00496 #endif
00497
00498
00499
00500
00501
00502
00503
00504 #define AV_COPY(n, d, s) \
00505 (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
00506
00507 #ifndef AV_COPY16
00508 # define AV_COPY16(d, s) AV_COPY(16, d, s)
00509 #endif
00510
00511 #ifndef AV_COPY32
00512 # define AV_COPY32(d, s) AV_COPY(32, d, s)
00513 #endif
00514
00515 #ifndef AV_COPY64
00516 # define AV_COPY64(d, s) AV_COPY(64, d, s)
00517 #endif
00518
00519 #ifndef AV_COPY128
00520 # define AV_COPY128(d, s) \
00521 do { \
00522 AV_COPY64(d, s); \
00523 AV_COPY64((char*)(d)+8, (char*)(s)+8); \
00524 } while(0)
00525 #endif
00526
00527 #define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
00528
00529 #ifndef AV_SWAP64
00530 # define AV_SWAP64(a, b) AV_SWAP(64, a, b)
00531 #endif
00532
00533 #define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
00534
00535 #ifndef AV_ZERO16
00536 # define AV_ZERO16(d) AV_ZERO(16, d)
00537 #endif
00538
00539 #ifndef AV_ZERO32
00540 # define AV_ZERO32(d) AV_ZERO(32, d)
00541 #endif
00542
00543 #ifndef AV_ZERO64
00544 # define AV_ZERO64(d) AV_ZERO(64, d)
00545 #endif
00546
00547 #ifndef AV_ZERO128
00548 # define AV_ZERO128(d) \
00549 do { \
00550 AV_ZERO64(d); \
00551 AV_ZERO64((char*)(d)+8); \
00552 } while(0)
00553 #endif
00554
00555 #endif