rotate_neon64.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * Copyright 2014 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/rotate_row.h"
  11. #include "libyuv/row.h"
  12. #include "libyuv/basic_types.h"
  13. #ifdef __cplusplus
  14. namespace libyuv {
  15. extern "C" {
  16. #endif
  17. // This module is for GCC Neon armv8 64 bit.
  18. #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
  19. static uvec8 kVTbl4x4Transpose = {0, 4, 8, 12, 1, 5, 9, 13,
  20. 2, 6, 10, 14, 3, 7, 11, 15};
  21. void TransposeWx8_NEON(const uint8* src,
  22. int src_stride,
  23. uint8* dst,
  24. int dst_stride,
  25. int width) {
  26. const uint8* src_temp;
  27. asm volatile(
  28. // loops are on blocks of 8. loop will stop when
  29. // counter gets to or below 0. starting the counter
  30. // at w-8 allow for this
  31. "sub %w3, %w3, #8 \n"
  32. // handle 8x8 blocks. this should be the majority of the plane
  33. "1: \n"
  34. "mov %0, %1 \n"
  35. "ld1 {v0.8b}, [%0], %5 \n"
  36. "ld1 {v1.8b}, [%0], %5 \n"
  37. "ld1 {v2.8b}, [%0], %5 \n"
  38. "ld1 {v3.8b}, [%0], %5 \n"
  39. "ld1 {v4.8b}, [%0], %5 \n"
  40. "ld1 {v5.8b}, [%0], %5 \n"
  41. "ld1 {v6.8b}, [%0], %5 \n"
  42. "ld1 {v7.8b}, [%0] \n"
  43. "trn2 v16.8b, v0.8b, v1.8b \n"
  44. "trn1 v17.8b, v0.8b, v1.8b \n"
  45. "trn2 v18.8b, v2.8b, v3.8b \n"
  46. "trn1 v19.8b, v2.8b, v3.8b \n"
  47. "trn2 v20.8b, v4.8b, v5.8b \n"
  48. "trn1 v21.8b, v4.8b, v5.8b \n"
  49. "trn2 v22.8b, v6.8b, v7.8b \n"
  50. "trn1 v23.8b, v6.8b, v7.8b \n"
  51. "trn2 v3.4h, v17.4h, v19.4h \n"
  52. "trn1 v1.4h, v17.4h, v19.4h \n"
  53. "trn2 v2.4h, v16.4h, v18.4h \n"
  54. "trn1 v0.4h, v16.4h, v18.4h \n"
  55. "trn2 v7.4h, v21.4h, v23.4h \n"
  56. "trn1 v5.4h, v21.4h, v23.4h \n"
  57. "trn2 v6.4h, v20.4h, v22.4h \n"
  58. "trn1 v4.4h, v20.4h, v22.4h \n"
  59. "trn2 v21.2s, v1.2s, v5.2s \n"
  60. "trn1 v17.2s, v1.2s, v5.2s \n"
  61. "trn2 v20.2s, v0.2s, v4.2s \n"
  62. "trn1 v16.2s, v0.2s, v4.2s \n"
  63. "trn2 v23.2s, v3.2s, v7.2s \n"
  64. "trn1 v19.2s, v3.2s, v7.2s \n"
  65. "trn2 v22.2s, v2.2s, v6.2s \n"
  66. "trn1 v18.2s, v2.2s, v6.2s \n"
  67. "mov %0, %2 \n"
  68. "st1 {v17.8b}, [%0], %6 \n"
  69. "st1 {v16.8b}, [%0], %6 \n"
  70. "st1 {v19.8b}, [%0], %6 \n"
  71. "st1 {v18.8b}, [%0], %6 \n"
  72. "st1 {v21.8b}, [%0], %6 \n"
  73. "st1 {v20.8b}, [%0], %6 \n"
  74. "st1 {v23.8b}, [%0], %6 \n"
  75. "st1 {v22.8b}, [%0] \n"
  76. "add %1, %1, #8 \n" // src += 8
  77. "add %2, %2, %6, lsl #3 \n" // dst += 8 * dst_stride
  78. "subs %w3, %w3, #8 \n" // w -= 8
  79. "b.ge 1b \n"
  80. // add 8 back to counter. if the result is 0 there are
  81. // no residuals.
  82. "adds %w3, %w3, #8 \n"
  83. "b.eq 4f \n"
  84. // some residual, so between 1 and 7 lines left to transpose
  85. "cmp %w3, #2 \n"
  86. "b.lt 3f \n"
  87. "cmp %w3, #4 \n"
  88. "b.lt 2f \n"
  89. // 4x8 block
  90. "mov %0, %1 \n"
  91. "ld1 {v0.s}[0], [%0], %5 \n"
  92. "ld1 {v0.s}[1], [%0], %5 \n"
  93. "ld1 {v0.s}[2], [%0], %5 \n"
  94. "ld1 {v0.s}[3], [%0], %5 \n"
  95. "ld1 {v1.s}[0], [%0], %5 \n"
  96. "ld1 {v1.s}[1], [%0], %5 \n"
  97. "ld1 {v1.s}[2], [%0], %5 \n"
  98. "ld1 {v1.s}[3], [%0] \n"
  99. "mov %0, %2 \n"
  100. "ld1 {v2.16b}, [%4] \n"
  101. "tbl v3.16b, {v0.16b}, v2.16b \n"
  102. "tbl v0.16b, {v1.16b}, v2.16b \n"
  103. // TODO(frkoenig): Rework shuffle above to
  104. // write out with 4 instead of 8 writes.
  105. "st1 {v3.s}[0], [%0], %6 \n"
  106. "st1 {v3.s}[1], [%0], %6 \n"
  107. "st1 {v3.s}[2], [%0], %6 \n"
  108. "st1 {v3.s}[3], [%0] \n"
  109. "add %0, %2, #4 \n"
  110. "st1 {v0.s}[0], [%0], %6 \n"
  111. "st1 {v0.s}[1], [%0], %6 \n"
  112. "st1 {v0.s}[2], [%0], %6 \n"
  113. "st1 {v0.s}[3], [%0] \n"
  114. "add %1, %1, #4 \n" // src += 4
  115. "add %2, %2, %6, lsl #2 \n" // dst += 4 * dst_stride
  116. "subs %w3, %w3, #4 \n" // w -= 4
  117. "b.eq 4f \n"
  118. // some residual, check to see if it includes a 2x8 block,
  119. // or less
  120. "cmp %w3, #2 \n"
  121. "b.lt 3f \n"
  122. // 2x8 block
  123. "2: \n"
  124. "mov %0, %1 \n"
  125. "ld1 {v0.h}[0], [%0], %5 \n"
  126. "ld1 {v1.h}[0], [%0], %5 \n"
  127. "ld1 {v0.h}[1], [%0], %5 \n"
  128. "ld1 {v1.h}[1], [%0], %5 \n"
  129. "ld1 {v0.h}[2], [%0], %5 \n"
  130. "ld1 {v1.h}[2], [%0], %5 \n"
  131. "ld1 {v0.h}[3], [%0], %5 \n"
  132. "ld1 {v1.h}[3], [%0] \n"
  133. "trn2 v2.8b, v0.8b, v1.8b \n"
  134. "trn1 v3.8b, v0.8b, v1.8b \n"
  135. "mov %0, %2 \n"
  136. "st1 {v3.8b}, [%0], %6 \n"
  137. "st1 {v2.8b}, [%0] \n"
  138. "add %1, %1, #2 \n" // src += 2
  139. "add %2, %2, %6, lsl #1 \n" // dst += 2 * dst_stride
  140. "subs %w3, %w3, #2 \n" // w -= 2
  141. "b.eq 4f \n"
  142. // 1x8 block
  143. "3: \n"
  144. "ld1 {v0.b}[0], [%1], %5 \n"
  145. "ld1 {v0.b}[1], [%1], %5 \n"
  146. "ld1 {v0.b}[2], [%1], %5 \n"
  147. "ld1 {v0.b}[3], [%1], %5 \n"
  148. "ld1 {v0.b}[4], [%1], %5 \n"
  149. "ld1 {v0.b}[5], [%1], %5 \n"
  150. "ld1 {v0.b}[6], [%1], %5 \n"
  151. "ld1 {v0.b}[7], [%1] \n"
  152. "st1 {v0.8b}, [%2] \n"
  153. "4: \n"
  154. : "=&r"(src_temp), // %0
  155. "+r"(src), // %1
  156. "+r"(dst), // %2
  157. "+r"(width) // %3
  158. : "r"(&kVTbl4x4Transpose), // %4
  159. "r"(static_cast<ptrdiff_t>(src_stride)), // %5
  160. "r"(static_cast<ptrdiff_t>(dst_stride)) // %6
  161. : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16",
  162. "v17", "v18", "v19", "v20", "v21", "v22", "v23");
  163. }
  164. static uint8 kVTbl4x4TransposeDi[32] = {
  165. 0, 16, 32, 48, 2, 18, 34, 50, 4, 20, 36, 52, 6, 22, 38, 54,
  166. 1, 17, 33, 49, 3, 19, 35, 51, 5, 21, 37, 53, 7, 23, 39, 55};
  167. void TransposeUVWx8_NEON(const uint8* src,
  168. int src_stride,
  169. uint8* dst_a,
  170. int dst_stride_a,
  171. uint8* dst_b,
  172. int dst_stride_b,
  173. int width) {
  174. const uint8* src_temp;
  175. asm volatile(
  176. // loops are on blocks of 8. loop will stop when
  177. // counter gets to or below 0. starting the counter
  178. // at w-8 allow for this
  179. "sub %w4, %w4, #8 \n"
  180. // handle 8x8 blocks. this should be the majority of the plane
  181. "1: \n"
  182. "mov %0, %1 \n"
  183. "ld1 {v0.16b}, [%0], %5 \n"
  184. "ld1 {v1.16b}, [%0], %5 \n"
  185. "ld1 {v2.16b}, [%0], %5 \n"
  186. "ld1 {v3.16b}, [%0], %5 \n"
  187. "ld1 {v4.16b}, [%0], %5 \n"
  188. "ld1 {v5.16b}, [%0], %5 \n"
  189. "ld1 {v6.16b}, [%0], %5 \n"
  190. "ld1 {v7.16b}, [%0] \n"
  191. "trn1 v16.16b, v0.16b, v1.16b \n"
  192. "trn2 v17.16b, v0.16b, v1.16b \n"
  193. "trn1 v18.16b, v2.16b, v3.16b \n"
  194. "trn2 v19.16b, v2.16b, v3.16b \n"
  195. "trn1 v20.16b, v4.16b, v5.16b \n"
  196. "trn2 v21.16b, v4.16b, v5.16b \n"
  197. "trn1 v22.16b, v6.16b, v7.16b \n"
  198. "trn2 v23.16b, v6.16b, v7.16b \n"
  199. "trn1 v0.8h, v16.8h, v18.8h \n"
  200. "trn2 v1.8h, v16.8h, v18.8h \n"
  201. "trn1 v2.8h, v20.8h, v22.8h \n"
  202. "trn2 v3.8h, v20.8h, v22.8h \n"
  203. "trn1 v4.8h, v17.8h, v19.8h \n"
  204. "trn2 v5.8h, v17.8h, v19.8h \n"
  205. "trn1 v6.8h, v21.8h, v23.8h \n"
  206. "trn2 v7.8h, v21.8h, v23.8h \n"
  207. "trn1 v16.4s, v0.4s, v2.4s \n"
  208. "trn2 v17.4s, v0.4s, v2.4s \n"
  209. "trn1 v18.4s, v1.4s, v3.4s \n"
  210. "trn2 v19.4s, v1.4s, v3.4s \n"
  211. "trn1 v20.4s, v4.4s, v6.4s \n"
  212. "trn2 v21.4s, v4.4s, v6.4s \n"
  213. "trn1 v22.4s, v5.4s, v7.4s \n"
  214. "trn2 v23.4s, v5.4s, v7.4s \n"
  215. "mov %0, %2 \n"
  216. "st1 {v16.d}[0], [%0], %6 \n"
  217. "st1 {v18.d}[0], [%0], %6 \n"
  218. "st1 {v17.d}[0], [%0], %6 \n"
  219. "st1 {v19.d}[0], [%0], %6 \n"
  220. "st1 {v16.d}[1], [%0], %6 \n"
  221. "st1 {v18.d}[1], [%0], %6 \n"
  222. "st1 {v17.d}[1], [%0], %6 \n"
  223. "st1 {v19.d}[1], [%0] \n"
  224. "mov %0, %3 \n"
  225. "st1 {v20.d}[0], [%0], %7 \n"
  226. "st1 {v22.d}[0], [%0], %7 \n"
  227. "st1 {v21.d}[0], [%0], %7 \n"
  228. "st1 {v23.d}[0], [%0], %7 \n"
  229. "st1 {v20.d}[1], [%0], %7 \n"
  230. "st1 {v22.d}[1], [%0], %7 \n"
  231. "st1 {v21.d}[1], [%0], %7 \n"
  232. "st1 {v23.d}[1], [%0] \n"
  233. "add %1, %1, #16 \n" // src += 8*2
  234. "add %2, %2, %6, lsl #3 \n" // dst_a += 8 *
  235. // dst_stride_a
  236. "add %3, %3, %7, lsl #3 \n" // dst_b += 8 *
  237. // dst_stride_b
  238. "subs %w4, %w4, #8 \n" // w -= 8
  239. "b.ge 1b \n"
  240. // add 8 back to counter. if the result is 0 there are
  241. // no residuals.
  242. "adds %w4, %w4, #8 \n"
  243. "b.eq 4f \n"
  244. // some residual, so between 1 and 7 lines left to transpose
  245. "cmp %w4, #2 \n"
  246. "b.lt 3f \n"
  247. "cmp %w4, #4 \n"
  248. "b.lt 2f \n"
  249. // TODO(frkoenig): Clean this up
  250. // 4x8 block
  251. "mov %0, %1 \n"
  252. "ld1 {v0.8b}, [%0], %5 \n"
  253. "ld1 {v1.8b}, [%0], %5 \n"
  254. "ld1 {v2.8b}, [%0], %5 \n"
  255. "ld1 {v3.8b}, [%0], %5 \n"
  256. "ld1 {v4.8b}, [%0], %5 \n"
  257. "ld1 {v5.8b}, [%0], %5 \n"
  258. "ld1 {v6.8b}, [%0], %5 \n"
  259. "ld1 {v7.8b}, [%0] \n"
  260. "ld1 {v30.16b}, [%8], #16 \n"
  261. "ld1 {v31.16b}, [%8] \n"
  262. "tbl v16.16b, {v0.16b, v1.16b, v2.16b, v3.16b}, v30.16b \n"
  263. "tbl v17.16b, {v0.16b, v1.16b, v2.16b, v3.16b}, v31.16b \n"
  264. "tbl v18.16b, {v4.16b, v5.16b, v6.16b, v7.16b}, v30.16b \n"
  265. "tbl v19.16b, {v4.16b, v5.16b, v6.16b, v7.16b}, v31.16b \n"
  266. "mov %0, %2 \n"
  267. "st1 {v16.s}[0], [%0], %6 \n"
  268. "st1 {v16.s}[1], [%0], %6 \n"
  269. "st1 {v16.s}[2], [%0], %6 \n"
  270. "st1 {v16.s}[3], [%0], %6 \n"
  271. "add %0, %2, #4 \n"
  272. "st1 {v18.s}[0], [%0], %6 \n"
  273. "st1 {v18.s}[1], [%0], %6 \n"
  274. "st1 {v18.s}[2], [%0], %6 \n"
  275. "st1 {v18.s}[3], [%0] \n"
  276. "mov %0, %3 \n"
  277. "st1 {v17.s}[0], [%0], %7 \n"
  278. "st1 {v17.s}[1], [%0], %7 \n"
  279. "st1 {v17.s}[2], [%0], %7 \n"
  280. "st1 {v17.s}[3], [%0], %7 \n"
  281. "add %0, %3, #4 \n"
  282. "st1 {v19.s}[0], [%0], %7 \n"
  283. "st1 {v19.s}[1], [%0], %7 \n"
  284. "st1 {v19.s}[2], [%0], %7 \n"
  285. "st1 {v19.s}[3], [%0] \n"
  286. "add %1, %1, #8 \n" // src += 4 * 2
  287. "add %2, %2, %6, lsl #2 \n" // dst_a += 4 *
  288. // dst_stride_a
  289. "add %3, %3, %7, lsl #2 \n" // dst_b += 4 *
  290. // dst_stride_b
  291. "subs %w4, %w4, #4 \n" // w -= 4
  292. "b.eq 4f \n"
  293. // some residual, check to see if it includes a 2x8 block,
  294. // or less
  295. "cmp %w4, #2 \n"
  296. "b.lt 3f \n"
  297. // 2x8 block
  298. "2: \n"
  299. "mov %0, %1 \n"
  300. "ld2 {v0.h, v1.h}[0], [%0], %5 \n"
  301. "ld2 {v2.h, v3.h}[0], [%0], %5 \n"
  302. "ld2 {v0.h, v1.h}[1], [%0], %5 \n"
  303. "ld2 {v2.h, v3.h}[1], [%0], %5 \n"
  304. "ld2 {v0.h, v1.h}[2], [%0], %5 \n"
  305. "ld2 {v2.h, v3.h}[2], [%0], %5 \n"
  306. "ld2 {v0.h, v1.h}[3], [%0], %5 \n"
  307. "ld2 {v2.h, v3.h}[3], [%0] \n"
  308. "trn1 v4.8b, v0.8b, v2.8b \n"
  309. "trn2 v5.8b, v0.8b, v2.8b \n"
  310. "trn1 v6.8b, v1.8b, v3.8b \n"
  311. "trn2 v7.8b, v1.8b, v3.8b \n"
  312. "mov %0, %2 \n"
  313. "st1 {v4.d}[0], [%0], %6 \n"
  314. "st1 {v6.d}[0], [%0] \n"
  315. "mov %0, %3 \n"
  316. "st1 {v5.d}[0], [%0], %7 \n"
  317. "st1 {v7.d}[0], [%0] \n"
  318. "add %1, %1, #4 \n" // src += 2 * 2
  319. "add %2, %2, %6, lsl #1 \n" // dst_a += 2 *
  320. // dst_stride_a
  321. "add %3, %3, %7, lsl #1 \n" // dst_b += 2 *
  322. // dst_stride_b
  323. "subs %w4, %w4, #2 \n" // w -= 2
  324. "b.eq 4f \n"
  325. // 1x8 block
  326. "3: \n"
  327. "ld2 {v0.b, v1.b}[0], [%1], %5 \n"
  328. "ld2 {v0.b, v1.b}[1], [%1], %5 \n"
  329. "ld2 {v0.b, v1.b}[2], [%1], %5 \n"
  330. "ld2 {v0.b, v1.b}[3], [%1], %5 \n"
  331. "ld2 {v0.b, v1.b}[4], [%1], %5 \n"
  332. "ld2 {v0.b, v1.b}[5], [%1], %5 \n"
  333. "ld2 {v0.b, v1.b}[6], [%1], %5 \n"
  334. "ld2 {v0.b, v1.b}[7], [%1] \n"
  335. "st1 {v0.d}[0], [%2] \n"
  336. "st1 {v1.d}[0], [%3] \n"
  337. "4: \n"
  338. : "=&r"(src_temp), // %0
  339. "+r"(src), // %1
  340. "+r"(dst_a), // %2
  341. "+r"(dst_b), // %3
  342. "+r"(width) // %4
  343. : "r"(static_cast<ptrdiff_t>(src_stride)), // %5
  344. "r"(static_cast<ptrdiff_t>(dst_stride_a)), // %6
  345. "r"(static_cast<ptrdiff_t>(dst_stride_b)), // %7
  346. "r"(&kVTbl4x4TransposeDi) // %8
  347. : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16",
  348. "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v30", "v31");
  349. }
  350. #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
  351. #ifdef __cplusplus
  352. } // extern "C"
  353. } // namespace libyuv
  354. #endif