intreadwrite.h 18 KB

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