intreadwrite.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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__)
  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(_MSC_VER) && (defined(_M_ARM) || defined(_M_X64) || defined(_M_ARM64)) && AV_HAVE_FAST_UNALIGNED
  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 AV_HAVE_FAST_UNALIGNED
  192. # define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
  193. # define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
  194. #else
  195. #ifndef AV_RB16
  196. # define AV_RB16(x) \
  197. ((((const uint8_t*)(x))[0] << 8) | \
  198. ((const uint8_t*)(x))[1])
  199. #endif
  200. #ifndef AV_WB16
  201. # define AV_WB16(p, val) do { \
  202. uint16_t d = (val); \
  203. ((uint8_t*)(p))[1] = (d); \
  204. ((uint8_t*)(p))[0] = (d)>>8; \
  205. } while(0)
  206. #endif
  207. #ifndef AV_RL16
  208. # define AV_RL16(x) \
  209. ((((const uint8_t*)(x))[1] << 8) | \
  210. ((const uint8_t*)(x))[0])
  211. #endif
  212. #ifndef AV_WL16
  213. # define AV_WL16(p, val) do { \
  214. uint16_t d = (val); \
  215. ((uint8_t*)(p))[0] = (d); \
  216. ((uint8_t*)(p))[1] = (d)>>8; \
  217. } while(0)
  218. #endif
  219. #ifndef AV_RB32
  220. # define AV_RB32(x) \
  221. (((uint32_t)((const uint8_t*)(x))[0] << 24) | \
  222. (((const uint8_t*)(x))[1] << 16) | \
  223. (((const uint8_t*)(x))[2] << 8) | \
  224. ((const uint8_t*)(x))[3])
  225. #endif
  226. #ifndef AV_WB32
  227. # define AV_WB32(p, val) do { \
  228. uint32_t d = (val); \
  229. ((uint8_t*)(p))[3] = (d); \
  230. ((uint8_t*)(p))[2] = (d)>>8; \
  231. ((uint8_t*)(p))[1] = (d)>>16; \
  232. ((uint8_t*)(p))[0] = (d)>>24; \
  233. } while(0)
  234. #endif
  235. #ifndef AV_RL32
  236. # define AV_RL32(x) \
  237. (((uint32_t)((const uint8_t*)(x))[3] << 24) | \
  238. (((const uint8_t*)(x))[2] << 16) | \
  239. (((const uint8_t*)(x))[1] << 8) | \
  240. ((const uint8_t*)(x))[0])
  241. #endif
  242. #ifndef AV_WL32
  243. # define AV_WL32(p, val) do { \
  244. uint32_t d = (val); \
  245. ((uint8_t*)(p))[0] = (d); \
  246. ((uint8_t*)(p))[1] = (d)>>8; \
  247. ((uint8_t*)(p))[2] = (d)>>16; \
  248. ((uint8_t*)(p))[3] = (d)>>24; \
  249. } while(0)
  250. #endif
  251. #ifndef AV_RB64
  252. # define AV_RB64(x) \
  253. (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
  254. ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
  255. ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
  256. ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
  257. ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
  258. ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
  259. ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
  260. (uint64_t)((const uint8_t*)(x))[7])
  261. #endif
  262. #ifndef AV_WB64
  263. # define AV_WB64(p, val) do { \
  264. uint64_t d = (val); \
  265. ((uint8_t*)(p))[7] = (d); \
  266. ((uint8_t*)(p))[6] = (d)>>8; \
  267. ((uint8_t*)(p))[5] = (d)>>16; \
  268. ((uint8_t*)(p))[4] = (d)>>24; \
  269. ((uint8_t*)(p))[3] = (d)>>32; \
  270. ((uint8_t*)(p))[2] = (d)>>40; \
  271. ((uint8_t*)(p))[1] = (d)>>48; \
  272. ((uint8_t*)(p))[0] = (d)>>56; \
  273. } while(0)
  274. #endif
  275. #ifndef AV_RL64
  276. # define AV_RL64(x) \
  277. (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
  278. ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
  279. ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
  280. ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
  281. ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
  282. ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
  283. ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
  284. (uint64_t)((const uint8_t*)(x))[0])
  285. #endif
  286. #ifndef AV_WL64
  287. # define AV_WL64(p, val) do { \
  288. uint64_t d = (val); \
  289. ((uint8_t*)(p))[0] = (d); \
  290. ((uint8_t*)(p))[1] = (d)>>8; \
  291. ((uint8_t*)(p))[2] = (d)>>16; \
  292. ((uint8_t*)(p))[3] = (d)>>24; \
  293. ((uint8_t*)(p))[4] = (d)>>32; \
  294. ((uint8_t*)(p))[5] = (d)>>40; \
  295. ((uint8_t*)(p))[6] = (d)>>48; \
  296. ((uint8_t*)(p))[7] = (d)>>56; \
  297. } while(0)
  298. #endif
  299. #if AV_HAVE_BIGENDIAN
  300. # define AV_RN(s, p) AV_RB##s(p)
  301. # define AV_WN(s, p, v) AV_WB##s(p, v)
  302. #else
  303. # define AV_RN(s, p) AV_RL##s(p)
  304. # define AV_WN(s, p, v) AV_WL##s(p, v)
  305. #endif
  306. #endif /* HAVE_FAST_UNALIGNED */
  307. #ifndef AV_RN16
  308. # define AV_RN16(p) AV_RN(16, p)
  309. #endif
  310. #ifndef AV_RN32
  311. # define AV_RN32(p) AV_RN(32, p)
  312. #endif
  313. #ifndef AV_RN64
  314. # define AV_RN64(p) AV_RN(64, p)
  315. #endif
  316. #ifndef AV_WN16
  317. # define AV_WN16(p, v) AV_WN(16, p, v)
  318. #endif
  319. #ifndef AV_WN32
  320. # define AV_WN32(p, v) AV_WN(32, p, v)
  321. #endif
  322. #ifndef AV_WN64
  323. # define AV_WN64(p, v) AV_WN(64, p, v)
  324. #endif
  325. #if AV_HAVE_BIGENDIAN
  326. # define AV_RB(s, p) AV_RN##s(p)
  327. # define AV_WB(s, p, v) AV_WN##s(p, v)
  328. # define AV_RL(s, p) av_bswap##s(AV_RN##s(p))
  329. # define AV_WL(s, p, v) AV_WN##s(p, av_bswap##s(v))
  330. #else
  331. # define AV_RB(s, p) av_bswap##s(AV_RN##s(p))
  332. # define AV_WB(s, p, v) AV_WN##s(p, av_bswap##s(v))
  333. # define AV_RL(s, p) AV_RN##s(p)
  334. # define AV_WL(s, p, v) AV_WN##s(p, v)
  335. #endif
  336. #define AV_RB8(x) (((const uint8_t*)(x))[0])
  337. #define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
  338. #define AV_RL8(x) AV_RB8(x)
  339. #define AV_WL8(p, d) AV_WB8(p, d)
  340. #ifndef AV_RB16
  341. # define AV_RB16(p) AV_RB(16, p)
  342. #endif
  343. #ifndef AV_WB16
  344. # define AV_WB16(p, v) AV_WB(16, p, v)
  345. #endif
  346. #ifndef AV_RL16
  347. # define AV_RL16(p) AV_RL(16, p)
  348. #endif
  349. #ifndef AV_WL16
  350. # define AV_WL16(p, v) AV_WL(16, p, v)
  351. #endif
  352. #ifndef AV_RB32
  353. # define AV_RB32(p) AV_RB(32, p)
  354. #endif
  355. #ifndef AV_WB32
  356. # define AV_WB32(p, v) AV_WB(32, p, v)
  357. #endif
  358. #ifndef AV_RL32
  359. # define AV_RL32(p) AV_RL(32, p)
  360. #endif
  361. #ifndef AV_WL32
  362. # define AV_WL32(p, v) AV_WL(32, p, v)
  363. #endif
  364. #ifndef AV_RB64
  365. # define AV_RB64(p) AV_RB(64, p)
  366. #endif
  367. #ifndef AV_WB64
  368. # define AV_WB64(p, v) AV_WB(64, p, v)
  369. #endif
  370. #ifndef AV_RL64
  371. # define AV_RL64(p) AV_RL(64, p)
  372. #endif
  373. #ifndef AV_WL64
  374. # define AV_WL64(p, v) AV_WL(64, p, v)
  375. #endif
  376. #ifndef AV_RB24
  377. # define AV_RB24(x) \
  378. ((((const uint8_t*)(x))[0] << 16) | \
  379. (((const uint8_t*)(x))[1] << 8) | \
  380. ((const uint8_t*)(x))[2])
  381. #endif
  382. #ifndef AV_WB24
  383. # define AV_WB24(p, d) do { \
  384. ((uint8_t*)(p))[2] = (d); \
  385. ((uint8_t*)(p))[1] = (d)>>8; \
  386. ((uint8_t*)(p))[0] = (d)>>16; \
  387. } while(0)
  388. #endif
  389. #ifndef AV_RL24
  390. # define AV_RL24(x) \
  391. ((((const uint8_t*)(x))[2] << 16) | \
  392. (((const uint8_t*)(x))[1] << 8) | \
  393. ((const uint8_t*)(x))[0])
  394. #endif
  395. #ifndef AV_WL24
  396. # define AV_WL24(p, d) do { \
  397. ((uint8_t*)(p))[0] = (d); \
  398. ((uint8_t*)(p))[1] = (d)>>8; \
  399. ((uint8_t*)(p))[2] = (d)>>16; \
  400. } while(0)
  401. #endif
  402. #ifndef AV_RB48
  403. # define AV_RB48(x) \
  404. (((uint64_t)((const uint8_t*)(x))[0] << 40) | \
  405. ((uint64_t)((const uint8_t*)(x))[1] << 32) | \
  406. ((uint64_t)((const uint8_t*)(x))[2] << 24) | \
  407. ((uint64_t)((const uint8_t*)(x))[3] << 16) | \
  408. ((uint64_t)((const uint8_t*)(x))[4] << 8) | \
  409. (uint64_t)((const uint8_t*)(x))[5])
  410. #endif
  411. #ifndef AV_WB48
  412. # define AV_WB48(p, darg) do { \
  413. uint64_t d = (darg); \
  414. ((uint8_t*)(p))[5] = (d); \
  415. ((uint8_t*)(p))[4] = (d)>>8; \
  416. ((uint8_t*)(p))[3] = (d)>>16; \
  417. ((uint8_t*)(p))[2] = (d)>>24; \
  418. ((uint8_t*)(p))[1] = (d)>>32; \
  419. ((uint8_t*)(p))[0] = (d)>>40; \
  420. } while(0)
  421. #endif
  422. #ifndef AV_RL48
  423. # define AV_RL48(x) \
  424. (((uint64_t)((const uint8_t*)(x))[5] << 40) | \
  425. ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
  426. ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
  427. ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
  428. ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
  429. (uint64_t)((const uint8_t*)(x))[0])
  430. #endif
  431. #ifndef AV_WL48
  432. # define AV_WL48(p, darg) do { \
  433. uint64_t d = (darg); \
  434. ((uint8_t*)(p))[0] = (d); \
  435. ((uint8_t*)(p))[1] = (d)>>8; \
  436. ((uint8_t*)(p))[2] = (d)>>16; \
  437. ((uint8_t*)(p))[3] = (d)>>24; \
  438. ((uint8_t*)(p))[4] = (d)>>32; \
  439. ((uint8_t*)(p))[5] = (d)>>40; \
  440. } while(0)
  441. #endif
  442. /*
  443. * The AV_[RW]NA macros access naturally aligned data
  444. * in a type-safe way.
  445. */
  446. #define AV_RNA(s, p) (((const av_alias##s*)(p))->u##s)
  447. #define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
  448. #ifndef AV_RN16A
  449. # define AV_RN16A(p) AV_RNA(16, p)
  450. #endif
  451. #ifndef AV_RN32A
  452. # define AV_RN32A(p) AV_RNA(32, p)
  453. #endif
  454. #ifndef AV_RN64A
  455. # define AV_RN64A(p) AV_RNA(64, p)
  456. #endif
  457. #ifndef AV_WN16A
  458. # define AV_WN16A(p, v) AV_WNA(16, p, v)
  459. #endif
  460. #ifndef AV_WN32A
  461. # define AV_WN32A(p, v) AV_WNA(32, p, v)
  462. #endif
  463. #ifndef AV_WN64A
  464. # define AV_WN64A(p, v) AV_WNA(64, p, v)
  465. #endif
  466. #if AV_HAVE_BIGENDIAN
  467. # define AV_RLA(s, p) av_bswap##s(AV_RN##s##A(p))
  468. # define AV_WLA(s, p, v) AV_WN##s##A(p, av_bswap##s(v))
  469. #else
  470. # define AV_RLA(s, p) AV_RN##s##A(p)
  471. # define AV_WLA(s, p, v) AV_WN##s##A(p, v)
  472. #endif
  473. #ifndef AV_RL64A
  474. # define AV_RL64A(p) AV_RLA(64, p)
  475. #endif
  476. #ifndef AV_WL64A
  477. # define AV_WL64A(p, v) AV_WLA(64, p, v)
  478. #endif
  479. /*
  480. * The AV_COPYxxU macros are suitable for copying data to/from unaligned
  481. * memory locations.
  482. */
  483. #define AV_COPYU(n, d, s) AV_WN##n(d, AV_RN##n(s));
  484. #ifndef AV_COPY16U
  485. # define AV_COPY16U(d, s) AV_COPYU(16, d, s)
  486. #endif
  487. #ifndef AV_COPY32U
  488. # define AV_COPY32U(d, s) AV_COPYU(32, d, s)
  489. #endif
  490. #ifndef AV_COPY64U
  491. # define AV_COPY64U(d, s) AV_COPYU(64, d, s)
  492. #endif
  493. #ifndef AV_COPY128U
  494. # define AV_COPY128U(d, s) \
  495. do { \
  496. AV_COPY64U(d, s); \
  497. AV_COPY64U((char *)(d) + 8, (const char *)(s) + 8); \
  498. } while(0)
  499. #endif
  500. /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
  501. * naturally aligned. They may be implemented using MMX,
  502. * so emms_c() must be called before using any float code
  503. * afterwards.
  504. */
  505. #define AV_COPY(n, d, s) \
  506. (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
  507. #ifndef AV_COPY16
  508. # define AV_COPY16(d, s) AV_COPY(16, d, s)
  509. #endif
  510. #ifndef AV_COPY32
  511. # define AV_COPY32(d, s) AV_COPY(32, d, s)
  512. #endif
  513. #ifndef AV_COPY64
  514. # define AV_COPY64(d, s) AV_COPY(64, d, s)
  515. #endif
  516. #ifndef AV_COPY128
  517. # define AV_COPY128(d, s) \
  518. do { \
  519. AV_COPY64(d, s); \
  520. AV_COPY64((char*)(d)+8, (char*)(s)+8); \
  521. } while(0)
  522. #endif
  523. #define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
  524. #ifndef AV_SWAP64
  525. # define AV_SWAP64(a, b) AV_SWAP(64, a, b)
  526. #endif
  527. #define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
  528. #ifndef AV_ZERO16
  529. # define AV_ZERO16(d) AV_ZERO(16, d)
  530. #endif
  531. #ifndef AV_ZERO32
  532. # define AV_ZERO32(d) AV_ZERO(32, d)
  533. #endif
  534. #ifndef AV_ZERO64
  535. # define AV_ZERO64(d) AV_ZERO(64, d)
  536. #endif
  537. #ifndef AV_ZERO128
  538. # define AV_ZERO128(d) \
  539. do { \
  540. AV_ZERO64(d); \
  541. AV_ZERO64((char*)(d)+8); \
  542. } while(0)
  543. #endif
  544. #endif /* AVUTIL_INTREADWRITE_H */