intreadwrite.h 18 KB

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