intreadwrite.h 18 KB

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