rotate_gcc.cc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * Copyright 2015 The LibYuv Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "libyuv/row.h"
  11. #include "libyuv/rotate_row.h"
  12. #ifdef __cplusplus
  13. namespace libyuv {
  14. extern "C" {
  15. #endif
  16. // This module is for GCC x86 and x64.
  17. #if !defined(LIBYUV_DISABLE_X86) && \
  18. (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
  19. // Transpose 8x8. 32 or 64 bit, but not NaCL for 64 bit.
  20. #if defined(HAS_TRANSPOSEWX8_SSSE3)
  21. void TransposeWx8_SSSE3(const uint8* src, int src_stride,
  22. uint8* dst, int dst_stride, int width) {
  23. asm volatile (
  24. // Read in the data from the source pointer.
  25. // First round of bit swap.
  26. LABELALIGN
  27. "1: \n"
  28. "movq (%0),%%xmm0 \n"
  29. "movq (%0,%3),%%xmm1 \n"
  30. "lea (%0,%3,2),%0 \n"
  31. "punpcklbw %%xmm1,%%xmm0 \n"
  32. "movq (%0),%%xmm2 \n"
  33. "movdqa %%xmm0,%%xmm1 \n"
  34. "palignr $0x8,%%xmm1,%%xmm1 \n"
  35. "movq (%0,%3),%%xmm3 \n"
  36. "lea (%0,%3,2),%0 \n"
  37. "punpcklbw %%xmm3,%%xmm2 \n"
  38. "movdqa %%xmm2,%%xmm3 \n"
  39. "movq (%0),%%xmm4 \n"
  40. "palignr $0x8,%%xmm3,%%xmm3 \n"
  41. "movq (%0,%3),%%xmm5 \n"
  42. "lea (%0,%3,2),%0 \n"
  43. "punpcklbw %%xmm5,%%xmm4 \n"
  44. "movdqa %%xmm4,%%xmm5 \n"
  45. "movq (%0),%%xmm6 \n"
  46. "palignr $0x8,%%xmm5,%%xmm5 \n"
  47. "movq (%0,%3),%%xmm7 \n"
  48. "lea (%0,%3,2),%0 \n"
  49. "punpcklbw %%xmm7,%%xmm6 \n"
  50. "neg %3 \n"
  51. "movdqa %%xmm6,%%xmm7 \n"
  52. "lea 0x8(%0,%3,8),%0 \n"
  53. "palignr $0x8,%%xmm7,%%xmm7 \n"
  54. "neg %3 \n"
  55. // Second round of bit swap.
  56. "punpcklwd %%xmm2,%%xmm0 \n"
  57. "punpcklwd %%xmm3,%%xmm1 \n"
  58. "movdqa %%xmm0,%%xmm2 \n"
  59. "movdqa %%xmm1,%%xmm3 \n"
  60. "palignr $0x8,%%xmm2,%%xmm2 \n"
  61. "palignr $0x8,%%xmm3,%%xmm3 \n"
  62. "punpcklwd %%xmm6,%%xmm4 \n"
  63. "punpcklwd %%xmm7,%%xmm5 \n"
  64. "movdqa %%xmm4,%%xmm6 \n"
  65. "movdqa %%xmm5,%%xmm7 \n"
  66. "palignr $0x8,%%xmm6,%%xmm6 \n"
  67. "palignr $0x8,%%xmm7,%%xmm7 \n"
  68. // Third round of bit swap.
  69. // Write to the destination pointer.
  70. "punpckldq %%xmm4,%%xmm0 \n"
  71. "movq %%xmm0,(%1) \n"
  72. "movdqa %%xmm0,%%xmm4 \n"
  73. "palignr $0x8,%%xmm4,%%xmm4 \n"
  74. "movq %%xmm4,(%1,%4) \n"
  75. "lea (%1,%4,2),%1 \n"
  76. "punpckldq %%xmm6,%%xmm2 \n"
  77. "movdqa %%xmm2,%%xmm6 \n"
  78. "movq %%xmm2,(%1) \n"
  79. "palignr $0x8,%%xmm6,%%xmm6 \n"
  80. "punpckldq %%xmm5,%%xmm1 \n"
  81. "movq %%xmm6,(%1,%4) \n"
  82. "lea (%1,%4,2),%1 \n"
  83. "movdqa %%xmm1,%%xmm5 \n"
  84. "movq %%xmm1,(%1) \n"
  85. "palignr $0x8,%%xmm5,%%xmm5 \n"
  86. "movq %%xmm5,(%1,%4) \n"
  87. "lea (%1,%4,2),%1 \n"
  88. "punpckldq %%xmm7,%%xmm3 \n"
  89. "movq %%xmm3,(%1) \n"
  90. "movdqa %%xmm3,%%xmm7 \n"
  91. "palignr $0x8,%%xmm7,%%xmm7 \n"
  92. "sub $0x8,%2 \n"
  93. "movq %%xmm7,(%1,%4) \n"
  94. "lea (%1,%4,2),%1 \n"
  95. "jg 1b \n"
  96. : "+r"(src), // %0
  97. "+r"(dst), // %1
  98. "+r"(width) // %2
  99. : "r"((intptr_t)(src_stride)), // %3
  100. "r"((intptr_t)(dst_stride)) // %4
  101. : "memory", "cc",
  102. "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
  103. );
  104. }
  105. #endif // defined(HAS_TRANSPOSEWX8_SSSE3)
  106. // Transpose 16x8. 64 bit
  107. #if defined(HAS_TRANSPOSEWX8_FAST_SSSE3)
  108. void TransposeWx8_Fast_SSSE3(const uint8* src, int src_stride,
  109. uint8* dst, int dst_stride, int width) {
  110. asm volatile (
  111. // Read in the data from the source pointer.
  112. // First round of bit swap.
  113. LABELALIGN
  114. "1: \n"
  115. "movdqu (%0),%%xmm0 \n"
  116. "movdqu (%0,%3),%%xmm1 \n"
  117. "lea (%0,%3,2),%0 \n"
  118. "movdqa %%xmm0,%%xmm8 \n"
  119. "punpcklbw %%xmm1,%%xmm0 \n"
  120. "punpckhbw %%xmm1,%%xmm8 \n"
  121. "movdqu (%0),%%xmm2 \n"
  122. "movdqa %%xmm0,%%xmm1 \n"
  123. "movdqa %%xmm8,%%xmm9 \n"
  124. "palignr $0x8,%%xmm1,%%xmm1 \n"
  125. "palignr $0x8,%%xmm9,%%xmm9 \n"
  126. "movdqu (%0,%3),%%xmm3 \n"
  127. "lea (%0,%3,2),%0 \n"
  128. "movdqa %%xmm2,%%xmm10 \n"
  129. "punpcklbw %%xmm3,%%xmm2 \n"
  130. "punpckhbw %%xmm3,%%xmm10 \n"
  131. "movdqa %%xmm2,%%xmm3 \n"
  132. "movdqa %%xmm10,%%xmm11 \n"
  133. "movdqu (%0),%%xmm4 \n"
  134. "palignr $0x8,%%xmm3,%%xmm3 \n"
  135. "palignr $0x8,%%xmm11,%%xmm11 \n"
  136. "movdqu (%0,%3),%%xmm5 \n"
  137. "lea (%0,%3,2),%0 \n"
  138. "movdqa %%xmm4,%%xmm12 \n"
  139. "punpcklbw %%xmm5,%%xmm4 \n"
  140. "punpckhbw %%xmm5,%%xmm12 \n"
  141. "movdqa %%xmm4,%%xmm5 \n"
  142. "movdqa %%xmm12,%%xmm13 \n"
  143. "movdqu (%0),%%xmm6 \n"
  144. "palignr $0x8,%%xmm5,%%xmm5 \n"
  145. "palignr $0x8,%%xmm13,%%xmm13 \n"
  146. "movdqu (%0,%3),%%xmm7 \n"
  147. "lea (%0,%3,2),%0 \n"
  148. "movdqa %%xmm6,%%xmm14 \n"
  149. "punpcklbw %%xmm7,%%xmm6 \n"
  150. "punpckhbw %%xmm7,%%xmm14 \n"
  151. "neg %3 \n"
  152. "movdqa %%xmm6,%%xmm7 \n"
  153. "movdqa %%xmm14,%%xmm15 \n"
  154. "lea 0x10(%0,%3,8),%0 \n"
  155. "palignr $0x8,%%xmm7,%%xmm7 \n"
  156. "palignr $0x8,%%xmm15,%%xmm15 \n"
  157. "neg %3 \n"
  158. // Second round of bit swap.
  159. "punpcklwd %%xmm2,%%xmm0 \n"
  160. "punpcklwd %%xmm3,%%xmm1 \n"
  161. "movdqa %%xmm0,%%xmm2 \n"
  162. "movdqa %%xmm1,%%xmm3 \n"
  163. "palignr $0x8,%%xmm2,%%xmm2 \n"
  164. "palignr $0x8,%%xmm3,%%xmm3 \n"
  165. "punpcklwd %%xmm6,%%xmm4 \n"
  166. "punpcklwd %%xmm7,%%xmm5 \n"
  167. "movdqa %%xmm4,%%xmm6 \n"
  168. "movdqa %%xmm5,%%xmm7 \n"
  169. "palignr $0x8,%%xmm6,%%xmm6 \n"
  170. "palignr $0x8,%%xmm7,%%xmm7 \n"
  171. "punpcklwd %%xmm10,%%xmm8 \n"
  172. "punpcklwd %%xmm11,%%xmm9 \n"
  173. "movdqa %%xmm8,%%xmm10 \n"
  174. "movdqa %%xmm9,%%xmm11 \n"
  175. "palignr $0x8,%%xmm10,%%xmm10 \n"
  176. "palignr $0x8,%%xmm11,%%xmm11 \n"
  177. "punpcklwd %%xmm14,%%xmm12 \n"
  178. "punpcklwd %%xmm15,%%xmm13 \n"
  179. "movdqa %%xmm12,%%xmm14 \n"
  180. "movdqa %%xmm13,%%xmm15 \n"
  181. "palignr $0x8,%%xmm14,%%xmm14 \n"
  182. "palignr $0x8,%%xmm15,%%xmm15 \n"
  183. // Third round of bit swap.
  184. // Write to the destination pointer.
  185. "punpckldq %%xmm4,%%xmm0 \n"
  186. "movq %%xmm0,(%1) \n"
  187. "movdqa %%xmm0,%%xmm4 \n"
  188. "palignr $0x8,%%xmm4,%%xmm4 \n"
  189. "movq %%xmm4,(%1,%4) \n"
  190. "lea (%1,%4,2),%1 \n"
  191. "punpckldq %%xmm6,%%xmm2 \n"
  192. "movdqa %%xmm2,%%xmm6 \n"
  193. "movq %%xmm2,(%1) \n"
  194. "palignr $0x8,%%xmm6,%%xmm6 \n"
  195. "punpckldq %%xmm5,%%xmm1 \n"
  196. "movq %%xmm6,(%1,%4) \n"
  197. "lea (%1,%4,2),%1 \n"
  198. "movdqa %%xmm1,%%xmm5 \n"
  199. "movq %%xmm1,(%1) \n"
  200. "palignr $0x8,%%xmm5,%%xmm5 \n"
  201. "movq %%xmm5,(%1,%4) \n"
  202. "lea (%1,%4,2),%1 \n"
  203. "punpckldq %%xmm7,%%xmm3 \n"
  204. "movq %%xmm3,(%1) \n"
  205. "movdqa %%xmm3,%%xmm7 \n"
  206. "palignr $0x8,%%xmm7,%%xmm7 \n"
  207. "movq %%xmm7,(%1,%4) \n"
  208. "lea (%1,%4,2),%1 \n"
  209. "punpckldq %%xmm12,%%xmm8 \n"
  210. "movq %%xmm8,(%1) \n"
  211. "movdqa %%xmm8,%%xmm12 \n"
  212. "palignr $0x8,%%xmm12,%%xmm12 \n"
  213. "movq %%xmm12,(%1,%4) \n"
  214. "lea (%1,%4,2),%1 \n"
  215. "punpckldq %%xmm14,%%xmm10 \n"
  216. "movdqa %%xmm10,%%xmm14 \n"
  217. "movq %%xmm10,(%1) \n"
  218. "palignr $0x8,%%xmm14,%%xmm14 \n"
  219. "punpckldq %%xmm13,%%xmm9 \n"
  220. "movq %%xmm14,(%1,%4) \n"
  221. "lea (%1,%4,2),%1 \n"
  222. "movdqa %%xmm9,%%xmm13 \n"
  223. "movq %%xmm9,(%1) \n"
  224. "palignr $0x8,%%xmm13,%%xmm13 \n"
  225. "movq %%xmm13,(%1,%4) \n"
  226. "lea (%1,%4,2),%1 \n"
  227. "punpckldq %%xmm15,%%xmm11 \n"
  228. "movq %%xmm11,(%1) \n"
  229. "movdqa %%xmm11,%%xmm15 \n"
  230. "palignr $0x8,%%xmm15,%%xmm15 \n"
  231. "sub $0x10,%2 \n"
  232. "movq %%xmm15,(%1,%4) \n"
  233. "lea (%1,%4,2),%1 \n"
  234. "jg 1b \n"
  235. : "+r"(src), // %0
  236. "+r"(dst), // %1
  237. "+r"(width) // %2
  238. : "r"((intptr_t)(src_stride)), // %3
  239. "r"((intptr_t)(dst_stride)) // %4
  240. : "memory", "cc",
  241. "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
  242. "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
  243. );
  244. }
  245. #endif // defined(HAS_TRANSPOSEWX8_FAST_SSSE3)
  246. // Transpose UV 8x8. 64 bit.
  247. #if defined(HAS_TRANSPOSEUVWX8_SSE2)
  248. void TransposeUVWx8_SSE2(const uint8* src, int src_stride,
  249. uint8* dst_a, int dst_stride_a,
  250. uint8* dst_b, int dst_stride_b, int width) {
  251. asm volatile (
  252. // Read in the data from the source pointer.
  253. // First round of bit swap.
  254. LABELALIGN
  255. "1: \n"
  256. "movdqu (%0),%%xmm0 \n"
  257. "movdqu (%0,%4),%%xmm1 \n"
  258. "lea (%0,%4,2),%0 \n"
  259. "movdqa %%xmm0,%%xmm8 \n"
  260. "punpcklbw %%xmm1,%%xmm0 \n"
  261. "punpckhbw %%xmm1,%%xmm8 \n"
  262. "movdqa %%xmm8,%%xmm1 \n"
  263. "movdqu (%0),%%xmm2 \n"
  264. "movdqu (%0,%4),%%xmm3 \n"
  265. "lea (%0,%4,2),%0 \n"
  266. "movdqa %%xmm2,%%xmm8 \n"
  267. "punpcklbw %%xmm3,%%xmm2 \n"
  268. "punpckhbw %%xmm3,%%xmm8 \n"
  269. "movdqa %%xmm8,%%xmm3 \n"
  270. "movdqu (%0),%%xmm4 \n"
  271. "movdqu (%0,%4),%%xmm5 \n"
  272. "lea (%0,%4,2),%0 \n"
  273. "movdqa %%xmm4,%%xmm8 \n"
  274. "punpcklbw %%xmm5,%%xmm4 \n"
  275. "punpckhbw %%xmm5,%%xmm8 \n"
  276. "movdqa %%xmm8,%%xmm5 \n"
  277. "movdqu (%0),%%xmm6 \n"
  278. "movdqu (%0,%4),%%xmm7 \n"
  279. "lea (%0,%4,2),%0 \n"
  280. "movdqa %%xmm6,%%xmm8 \n"
  281. "punpcklbw %%xmm7,%%xmm6 \n"
  282. "neg %4 \n"
  283. "lea 0x10(%0,%4,8),%0 \n"
  284. "punpckhbw %%xmm7,%%xmm8 \n"
  285. "movdqa %%xmm8,%%xmm7 \n"
  286. "neg %4 \n"
  287. // Second round of bit swap.
  288. "movdqa %%xmm0,%%xmm8 \n"
  289. "movdqa %%xmm1,%%xmm9 \n"
  290. "punpckhwd %%xmm2,%%xmm8 \n"
  291. "punpckhwd %%xmm3,%%xmm9 \n"
  292. "punpcklwd %%xmm2,%%xmm0 \n"
  293. "punpcklwd %%xmm3,%%xmm1 \n"
  294. "movdqa %%xmm8,%%xmm2 \n"
  295. "movdqa %%xmm9,%%xmm3 \n"
  296. "movdqa %%xmm4,%%xmm8 \n"
  297. "movdqa %%xmm5,%%xmm9 \n"
  298. "punpckhwd %%xmm6,%%xmm8 \n"
  299. "punpckhwd %%xmm7,%%xmm9 \n"
  300. "punpcklwd %%xmm6,%%xmm4 \n"
  301. "punpcklwd %%xmm7,%%xmm5 \n"
  302. "movdqa %%xmm8,%%xmm6 \n"
  303. "movdqa %%xmm9,%%xmm7 \n"
  304. // Third round of bit swap.
  305. // Write to the destination pointer.
  306. "movdqa %%xmm0,%%xmm8 \n"
  307. "punpckldq %%xmm4,%%xmm0 \n"
  308. "movlpd %%xmm0,(%1) \n" // Write back U channel
  309. "movhpd %%xmm0,(%2) \n" // Write back V channel
  310. "punpckhdq %%xmm4,%%xmm8 \n"
  311. "movlpd %%xmm8,(%1,%5) \n"
  312. "lea (%1,%5,2),%1 \n"
  313. "movhpd %%xmm8,(%2,%6) \n"
  314. "lea (%2,%6,2),%2 \n"
  315. "movdqa %%xmm2,%%xmm8 \n"
  316. "punpckldq %%xmm6,%%xmm2 \n"
  317. "movlpd %%xmm2,(%1) \n"
  318. "movhpd %%xmm2,(%2) \n"
  319. "punpckhdq %%xmm6,%%xmm8 \n"
  320. "movlpd %%xmm8,(%1,%5) \n"
  321. "lea (%1,%5,2),%1 \n"
  322. "movhpd %%xmm8,(%2,%6) \n"
  323. "lea (%2,%6,2),%2 \n"
  324. "movdqa %%xmm1,%%xmm8 \n"
  325. "punpckldq %%xmm5,%%xmm1 \n"
  326. "movlpd %%xmm1,(%1) \n"
  327. "movhpd %%xmm1,(%2) \n"
  328. "punpckhdq %%xmm5,%%xmm8 \n"
  329. "movlpd %%xmm8,(%1,%5) \n"
  330. "lea (%1,%5,2),%1 \n"
  331. "movhpd %%xmm8,(%2,%6) \n"
  332. "lea (%2,%6,2),%2 \n"
  333. "movdqa %%xmm3,%%xmm8 \n"
  334. "punpckldq %%xmm7,%%xmm3 \n"
  335. "movlpd %%xmm3,(%1) \n"
  336. "movhpd %%xmm3,(%2) \n"
  337. "punpckhdq %%xmm7,%%xmm8 \n"
  338. "sub $0x8,%3 \n"
  339. "movlpd %%xmm8,(%1,%5) \n"
  340. "lea (%1,%5,2),%1 \n"
  341. "movhpd %%xmm8,(%2,%6) \n"
  342. "lea (%2,%6,2),%2 \n"
  343. "jg 1b \n"
  344. : "+r"(src), // %0
  345. "+r"(dst_a), // %1
  346. "+r"(dst_b), // %2
  347. "+r"(width) // %3
  348. : "r"((intptr_t)(src_stride)), // %4
  349. "r"((intptr_t)(dst_stride_a)), // %5
  350. "r"((intptr_t)(dst_stride_b)) // %6
  351. : "memory", "cc",
  352. "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
  353. "xmm8", "xmm9"
  354. );
  355. }
  356. #endif // defined(HAS_TRANSPOSEUVWX8_SSE2)
  357. #endif // defined(__x86_64__) || defined(__i386__)
  358. #ifdef __cplusplus
  359. } // extern "C"
  360. } // namespace libyuv
  361. #endif