scale_neon64.cc 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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/row.h"
  11. #include "libyuv/scale.h"
  12. #include "libyuv/scale_row.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. // Read 32x1 throw away even pixels, and write 16x1.
  20. void ScaleRowDown2_NEON(const uint8_t* src_ptr,
  21. ptrdiff_t src_stride,
  22. uint8_t* dst,
  23. int dst_width) {
  24. (void)src_stride;
  25. asm volatile(
  26. "1: \n"
  27. // load even pixels into v0, odd into v1
  28. "ld2 {v0.16b,v1.16b}, [%0], #32 \n"
  29. "subs %w2, %w2, #16 \n" // 16 processed per loop
  30. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  31. "st1 {v1.16b}, [%1], #16 \n" // store odd pixels
  32. "b.gt 1b \n"
  33. : "+r"(src_ptr), // %0
  34. "+r"(dst), // %1
  35. "+r"(dst_width) // %2
  36. :
  37. : "v0", "v1" // Clobber List
  38. );
  39. }
  40. // Read 32x1 average down and write 16x1.
  41. void ScaleRowDown2Linear_NEON(const uint8_t* src_ptr,
  42. ptrdiff_t src_stride,
  43. uint8_t* dst,
  44. int dst_width) {
  45. (void)src_stride;
  46. asm volatile(
  47. "1: \n"
  48. // load even pixels into v0, odd into v1
  49. "ld2 {v0.16b,v1.16b}, [%0], #32 \n"
  50. "subs %w2, %w2, #16 \n" // 16 processed per loop
  51. "urhadd v0.16b, v0.16b, v1.16b \n" // rounding half add
  52. "st1 {v0.16b}, [%1], #16 \n"
  53. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  54. "b.gt 1b \n"
  55. : "+r"(src_ptr), // %0
  56. "+r"(dst), // %1
  57. "+r"(dst_width) // %2
  58. :
  59. : "v0", "v1" // Clobber List
  60. );
  61. }
  62. // Read 32x2 average down and write 16x1.
  63. void ScaleRowDown2Box_NEON(const uint8_t* src_ptr,
  64. ptrdiff_t src_stride,
  65. uint8_t* dst,
  66. int dst_width) {
  67. asm volatile(
  68. // change the stride to row 2 pointer
  69. "add %1, %1, %0 \n"
  70. "1: \n"
  71. "ld1 {v0.16b, v1.16b}, [%0], #32 \n" // load row 1 and post inc
  72. "ld1 {v2.16b, v3.16b}, [%1], #32 \n" // load row 2 and post inc
  73. "subs %w3, %w3, #16 \n" // 16 processed per loop
  74. "uaddlp v0.8h, v0.16b \n" // row 1 add adjacent
  75. "uaddlp v1.8h, v1.16b \n"
  76. "uadalp v0.8h, v2.16b \n" // += row 2 add adjacent
  77. "uadalp v1.8h, v3.16b \n"
  78. "rshrn v0.8b, v0.8h, #2 \n" // round and pack
  79. "rshrn2 v0.16b, v1.8h, #2 \n"
  80. "st1 {v0.16b}, [%2], #16 \n"
  81. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  82. "prfm pldl1keep, [%1, 448] \n"
  83. "b.gt 1b \n"
  84. : "+r"(src_ptr), // %0
  85. "+r"(src_stride), // %1
  86. "+r"(dst), // %2
  87. "+r"(dst_width) // %3
  88. :
  89. : "v0", "v1", "v2", "v3" // Clobber List
  90. );
  91. }
  92. void ScaleRowDown4_NEON(const uint8_t* src_ptr,
  93. ptrdiff_t src_stride,
  94. uint8_t* dst_ptr,
  95. int dst_width) {
  96. (void)src_stride;
  97. asm volatile(
  98. "1: \n"
  99. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0
  100. "subs %w2, %w2, #8 \n" // 8 processed per loop
  101. "st1 {v2.8b}, [%1], #8 \n"
  102. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  103. "b.gt 1b \n"
  104. : "+r"(src_ptr), // %0
  105. "+r"(dst_ptr), // %1
  106. "+r"(dst_width) // %2
  107. :
  108. : "v0", "v1", "v2", "v3", "memory", "cc");
  109. }
  110. void ScaleRowDown4Box_NEON(const uint8_t* src_ptr,
  111. ptrdiff_t src_stride,
  112. uint8_t* dst_ptr,
  113. int dst_width) {
  114. const uint8_t* src_ptr1 = src_ptr + src_stride;
  115. const uint8_t* src_ptr2 = src_ptr + src_stride * 2;
  116. const uint8_t* src_ptr3 = src_ptr + src_stride * 3;
  117. asm volatile(
  118. "1: \n"
  119. "ld1 {v0.16b}, [%0], #16 \n" // load up 16x4
  120. "ld1 {v1.16b}, [%2], #16 \n"
  121. "ld1 {v2.16b}, [%3], #16 \n"
  122. "ld1 {v3.16b}, [%4], #16 \n"
  123. "subs %w5, %w5, #4 \n"
  124. "uaddlp v0.8h, v0.16b \n"
  125. "uadalp v0.8h, v1.16b \n"
  126. "uadalp v0.8h, v2.16b \n"
  127. "uadalp v0.8h, v3.16b \n"
  128. "addp v0.8h, v0.8h, v0.8h \n"
  129. "rshrn v0.8b, v0.8h, #4 \n" // divide by 16 w/rounding
  130. "st1 {v0.s}[0], [%1], #4 \n"
  131. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  132. "prfm pldl1keep, [%2, 448] \n"
  133. "prfm pldl1keep, [%3, 448] \n"
  134. "prfm pldl1keep, [%4, 448] \n"
  135. "b.gt 1b \n"
  136. : "+r"(src_ptr), // %0
  137. "+r"(dst_ptr), // %1
  138. "+r"(src_ptr1), // %2
  139. "+r"(src_ptr2), // %3
  140. "+r"(src_ptr3), // %4
  141. "+r"(dst_width) // %5
  142. :
  143. : "v0", "v1", "v2", "v3", "memory", "cc");
  144. }
  145. // Down scale from 4 to 3 pixels. Use the neon multilane read/write
  146. // to load up the every 4th pixel into a 4 different registers.
  147. // Point samples 32 pixels to 24 pixels.
  148. void ScaleRowDown34_NEON(const uint8_t* src_ptr,
  149. ptrdiff_t src_stride,
  150. uint8_t* dst_ptr,
  151. int dst_width) {
  152. (void)src_stride;
  153. asm volatile(
  154. "1: \n"
  155. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0
  156. "subs %w2, %w2, #24 \n"
  157. "orr v2.16b, v3.16b, v3.16b \n" // order v0,v1,v2
  158. "st3 {v0.8b,v1.8b,v2.8b}, [%1], #24 \n"
  159. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  160. "b.gt 1b \n"
  161. : "+r"(src_ptr), // %0
  162. "+r"(dst_ptr), // %1
  163. "+r"(dst_width) // %2
  164. :
  165. : "v0", "v1", "v2", "v3", "memory", "cc");
  166. }
  167. void ScaleRowDown34_0_Box_NEON(const uint8_t* src_ptr,
  168. ptrdiff_t src_stride,
  169. uint8_t* dst_ptr,
  170. int dst_width) {
  171. asm volatile(
  172. "movi v20.8b, #3 \n"
  173. "add %3, %3, %0 \n"
  174. "1: \n"
  175. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0
  176. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%3], #32 \n" // src line 1
  177. "subs %w2, %w2, #24 \n"
  178. // filter src line 0 with src line 1
  179. // expand chars to shorts to allow for room
  180. // when adding lines together
  181. "ushll v16.8h, v4.8b, #0 \n"
  182. "ushll v17.8h, v5.8b, #0 \n"
  183. "ushll v18.8h, v6.8b, #0 \n"
  184. "ushll v19.8h, v7.8b, #0 \n"
  185. // 3 * line_0 + line_1
  186. "umlal v16.8h, v0.8b, v20.8b \n"
  187. "umlal v17.8h, v1.8b, v20.8b \n"
  188. "umlal v18.8h, v2.8b, v20.8b \n"
  189. "umlal v19.8h, v3.8b, v20.8b \n"
  190. // (3 * line_0 + line_1) >> 2
  191. "uqrshrn v0.8b, v16.8h, #2 \n"
  192. "uqrshrn v1.8b, v17.8h, #2 \n"
  193. "uqrshrn v2.8b, v18.8h, #2 \n"
  194. "uqrshrn v3.8b, v19.8h, #2 \n"
  195. // a0 = (src[0] * 3 + s[1] * 1) >> 2
  196. "ushll v16.8h, v1.8b, #0 \n"
  197. "umlal v16.8h, v0.8b, v20.8b \n"
  198. "uqrshrn v0.8b, v16.8h, #2 \n"
  199. // a1 = (src[1] * 1 + s[2] * 1) >> 1
  200. "urhadd v1.8b, v1.8b, v2.8b \n"
  201. // a2 = (src[2] * 1 + s[3] * 3) >> 2
  202. "ushll v16.8h, v2.8b, #0 \n"
  203. "umlal v16.8h, v3.8b, v20.8b \n"
  204. "uqrshrn v2.8b, v16.8h, #2 \n"
  205. "st3 {v0.8b,v1.8b,v2.8b}, [%1], #24 \n"
  206. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  207. "prfm pldl1keep, [%3, 448] \n"
  208. "b.gt 1b \n"
  209. : "+r"(src_ptr), // %0
  210. "+r"(dst_ptr), // %1
  211. "+r"(dst_width), // %2
  212. "+r"(src_stride) // %3
  213. :
  214. : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18",
  215. "v19", "v20", "memory", "cc");
  216. }
  217. void ScaleRowDown34_1_Box_NEON(const uint8_t* src_ptr,
  218. ptrdiff_t src_stride,
  219. uint8_t* dst_ptr,
  220. int dst_width) {
  221. asm volatile(
  222. "movi v20.8b, #3 \n"
  223. "add %3, %3, %0 \n"
  224. "1: \n"
  225. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0
  226. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%3], #32 \n" // src line 1
  227. "subs %w2, %w2, #24 \n"
  228. // average src line 0 with src line 1
  229. "urhadd v0.8b, v0.8b, v4.8b \n"
  230. "urhadd v1.8b, v1.8b, v5.8b \n"
  231. "urhadd v2.8b, v2.8b, v6.8b \n"
  232. "urhadd v3.8b, v3.8b, v7.8b \n"
  233. // a0 = (src[0] * 3 + s[1] * 1) >> 2
  234. "ushll v4.8h, v1.8b, #0 \n"
  235. "umlal v4.8h, v0.8b, v20.8b \n"
  236. "uqrshrn v0.8b, v4.8h, #2 \n"
  237. // a1 = (src[1] * 1 + s[2] * 1) >> 1
  238. "urhadd v1.8b, v1.8b, v2.8b \n"
  239. // a2 = (src[2] * 1 + s[3] * 3) >> 2
  240. "ushll v4.8h, v2.8b, #0 \n"
  241. "umlal v4.8h, v3.8b, v20.8b \n"
  242. "uqrshrn v2.8b, v4.8h, #2 \n"
  243. "st3 {v0.8b,v1.8b,v2.8b}, [%1], #24 \n"
  244. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  245. "prfm pldl1keep, [%3, 448] \n"
  246. "b.gt 1b \n"
  247. : "+r"(src_ptr), // %0
  248. "+r"(dst_ptr), // %1
  249. "+r"(dst_width), // %2
  250. "+r"(src_stride) // %3
  251. :
  252. : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", "memory", "cc");
  253. }
  254. static const uvec8 kShuf38 = {0, 3, 6, 8, 11, 14, 16, 19,
  255. 22, 24, 27, 30, 0, 0, 0, 0};
  256. static const uvec8 kShuf38_2 = {0, 16, 32, 2, 18, 33, 4, 20,
  257. 34, 6, 22, 35, 0, 0, 0, 0};
  258. static const vec16 kMult38_Div6 = {65536 / 12, 65536 / 12, 65536 / 12,
  259. 65536 / 12, 65536 / 12, 65536 / 12,
  260. 65536 / 12, 65536 / 12};
  261. static const vec16 kMult38_Div9 = {65536 / 18, 65536 / 18, 65536 / 18,
  262. 65536 / 18, 65536 / 18, 65536 / 18,
  263. 65536 / 18, 65536 / 18};
  264. // 32 -> 12
  265. void ScaleRowDown38_NEON(const uint8_t* src_ptr,
  266. ptrdiff_t src_stride,
  267. uint8_t* dst_ptr,
  268. int dst_width) {
  269. (void)src_stride;
  270. asm volatile(
  271. "ld1 {v3.16b}, [%3] \n"
  272. "1: \n"
  273. "ld1 {v0.16b,v1.16b}, [%0], #32 \n"
  274. "subs %w2, %w2, #12 \n"
  275. "tbl v2.16b, {v0.16b,v1.16b}, v3.16b \n"
  276. "st1 {v2.8b}, [%1], #8 \n"
  277. "st1 {v2.s}[2], [%1], #4 \n"
  278. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  279. "b.gt 1b \n"
  280. : "+r"(src_ptr), // %0
  281. "+r"(dst_ptr), // %1
  282. "+r"(dst_width) // %2
  283. : "r"(&kShuf38) // %3
  284. : "v0", "v1", "v2", "v3", "memory", "cc");
  285. }
  286. // 32x3 -> 12x1
  287. void OMITFP ScaleRowDown38_3_Box_NEON(const uint8_t* src_ptr,
  288. ptrdiff_t src_stride,
  289. uint8_t* dst_ptr,
  290. int dst_width) {
  291. const uint8_t* src_ptr1 = src_ptr + src_stride * 2;
  292. ptrdiff_t tmp_src_stride = src_stride;
  293. asm volatile(
  294. "ld1 {v29.8h}, [%5] \n"
  295. "ld1 {v30.16b}, [%6] \n"
  296. "ld1 {v31.8h}, [%7] \n"
  297. "add %2, %2, %0 \n"
  298. "1: \n"
  299. // 00 40 01 41 02 42 03 43
  300. // 10 50 11 51 12 52 13 53
  301. // 20 60 21 61 22 62 23 63
  302. // 30 70 31 71 32 72 33 73
  303. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n"
  304. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%2], #32 \n"
  305. "ld4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%3], #32 \n"
  306. "subs %w4, %w4, #12 \n"
  307. // Shuffle the input data around to get align the data
  308. // so adjacent data can be added. 0,1 - 2,3 - 4,5 - 6,7
  309. // 00 10 01 11 02 12 03 13
  310. // 40 50 41 51 42 52 43 53
  311. "trn1 v20.8b, v0.8b, v1.8b \n"
  312. "trn2 v21.8b, v0.8b, v1.8b \n"
  313. "trn1 v22.8b, v4.8b, v5.8b \n"
  314. "trn2 v23.8b, v4.8b, v5.8b \n"
  315. "trn1 v24.8b, v16.8b, v17.8b \n"
  316. "trn2 v25.8b, v16.8b, v17.8b \n"
  317. // 20 30 21 31 22 32 23 33
  318. // 60 70 61 71 62 72 63 73
  319. "trn1 v0.8b, v2.8b, v3.8b \n"
  320. "trn2 v1.8b, v2.8b, v3.8b \n"
  321. "trn1 v4.8b, v6.8b, v7.8b \n"
  322. "trn2 v5.8b, v6.8b, v7.8b \n"
  323. "trn1 v16.8b, v18.8b, v19.8b \n"
  324. "trn2 v17.8b, v18.8b, v19.8b \n"
  325. // 00+10 01+11 02+12 03+13
  326. // 40+50 41+51 42+52 43+53
  327. "uaddlp v20.4h, v20.8b \n"
  328. "uaddlp v21.4h, v21.8b \n"
  329. "uaddlp v22.4h, v22.8b \n"
  330. "uaddlp v23.4h, v23.8b \n"
  331. "uaddlp v24.4h, v24.8b \n"
  332. "uaddlp v25.4h, v25.8b \n"
  333. // 60+70 61+71 62+72 63+73
  334. "uaddlp v1.4h, v1.8b \n"
  335. "uaddlp v5.4h, v5.8b \n"
  336. "uaddlp v17.4h, v17.8b \n"
  337. // combine source lines
  338. "add v20.4h, v20.4h, v22.4h \n"
  339. "add v21.4h, v21.4h, v23.4h \n"
  340. "add v20.4h, v20.4h, v24.4h \n"
  341. "add v21.4h, v21.4h, v25.4h \n"
  342. "add v2.4h, v1.4h, v5.4h \n"
  343. "add v2.4h, v2.4h, v17.4h \n"
  344. // dst_ptr[3] = (s[6 + st * 0] + s[7 + st * 0]
  345. // + s[6 + st * 1] + s[7 + st * 1]
  346. // + s[6 + st * 2] + s[7 + st * 2]) / 6
  347. "sqrdmulh v2.8h, v2.8h, v29.8h \n"
  348. "xtn v2.8b, v2.8h \n"
  349. // Shuffle 2,3 reg around so that 2 can be added to the
  350. // 0,1 reg and 3 can be added to the 4,5 reg. This
  351. // requires expanding from u8 to u16 as the 0,1 and 4,5
  352. // registers are already expanded. Then do transposes
  353. // to get aligned.
  354. // xx 20 xx 30 xx 21 xx 31 xx 22 xx 32 xx 23 xx 33
  355. "ushll v16.8h, v16.8b, #0 \n"
  356. "uaddl v0.8h, v0.8b, v4.8b \n"
  357. // combine source lines
  358. "add v0.8h, v0.8h, v16.8h \n"
  359. // xx 20 xx 21 xx 22 xx 23
  360. // xx 30 xx 31 xx 32 xx 33
  361. "trn1 v1.8h, v0.8h, v0.8h \n"
  362. "trn2 v4.8h, v0.8h, v0.8h \n"
  363. "xtn v0.4h, v1.4s \n"
  364. "xtn v4.4h, v4.4s \n"
  365. // 0+1+2, 3+4+5
  366. "add v20.8h, v20.8h, v0.8h \n"
  367. "add v21.8h, v21.8h, v4.8h \n"
  368. // Need to divide, but can't downshift as the the value
  369. // isn't a power of 2. So multiply by 65536 / n
  370. // and take the upper 16 bits.
  371. "sqrdmulh v0.8h, v20.8h, v31.8h \n"
  372. "sqrdmulh v1.8h, v21.8h, v31.8h \n"
  373. // Align for table lookup, vtbl requires registers to be adjacent
  374. "tbl v3.16b, {v0.16b, v1.16b, v2.16b}, v30.16b \n"
  375. "st1 {v3.8b}, [%1], #8 \n"
  376. "st1 {v3.s}[2], [%1], #4 \n"
  377. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  378. "prfm pldl1keep, [%2, 448] \n"
  379. "prfm pldl1keep, [%3, 448] \n"
  380. "b.gt 1b \n"
  381. : "+r"(src_ptr), // %0
  382. "+r"(dst_ptr), // %1
  383. "+r"(tmp_src_stride), // %2
  384. "+r"(src_ptr1), // %3
  385. "+r"(dst_width) // %4
  386. : "r"(&kMult38_Div6), // %5
  387. "r"(&kShuf38_2), // %6
  388. "r"(&kMult38_Div9) // %7
  389. : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18",
  390. "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v29", "v30", "v31",
  391. "memory", "cc");
  392. }
  393. // 32x2 -> 12x1
  394. void ScaleRowDown38_2_Box_NEON(const uint8_t* src_ptr,
  395. ptrdiff_t src_stride,
  396. uint8_t* dst_ptr,
  397. int dst_width) {
  398. // TODO(fbarchard): use src_stride directly for clang 3.5+.
  399. ptrdiff_t tmp_src_stride = src_stride;
  400. asm volatile(
  401. "ld1 {v30.8h}, [%4] \n"
  402. "ld1 {v31.16b}, [%5] \n"
  403. "add %2, %2, %0 \n"
  404. "1: \n"
  405. // 00 40 01 41 02 42 03 43
  406. // 10 50 11 51 12 52 13 53
  407. // 20 60 21 61 22 62 23 63
  408. // 30 70 31 71 32 72 33 73
  409. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n"
  410. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%2], #32 \n"
  411. "subs %w3, %w3, #12 \n"
  412. // Shuffle the input data around to get align the data
  413. // so adjacent data can be added. 0,1 - 2,3 - 4,5 - 6,7
  414. // 00 10 01 11 02 12 03 13
  415. // 40 50 41 51 42 52 43 53
  416. "trn1 v16.8b, v0.8b, v1.8b \n"
  417. "trn2 v17.8b, v0.8b, v1.8b \n"
  418. "trn1 v18.8b, v4.8b, v5.8b \n"
  419. "trn2 v19.8b, v4.8b, v5.8b \n"
  420. // 20 30 21 31 22 32 23 33
  421. // 60 70 61 71 62 72 63 73
  422. "trn1 v0.8b, v2.8b, v3.8b \n"
  423. "trn2 v1.8b, v2.8b, v3.8b \n"
  424. "trn1 v4.8b, v6.8b, v7.8b \n"
  425. "trn2 v5.8b, v6.8b, v7.8b \n"
  426. // 00+10 01+11 02+12 03+13
  427. // 40+50 41+51 42+52 43+53
  428. "uaddlp v16.4h, v16.8b \n"
  429. "uaddlp v17.4h, v17.8b \n"
  430. "uaddlp v18.4h, v18.8b \n"
  431. "uaddlp v19.4h, v19.8b \n"
  432. // 60+70 61+71 62+72 63+73
  433. "uaddlp v1.4h, v1.8b \n"
  434. "uaddlp v5.4h, v5.8b \n"
  435. // combine source lines
  436. "add v16.4h, v16.4h, v18.4h \n"
  437. "add v17.4h, v17.4h, v19.4h \n"
  438. "add v2.4h, v1.4h, v5.4h \n"
  439. // dst_ptr[3] = (s[6] + s[7] + s[6+st] + s[7+st]) / 4
  440. "uqrshrn v2.8b, v2.8h, #2 \n"
  441. // Shuffle 2,3 reg around so that 2 can be added to the
  442. // 0,1 reg and 3 can be added to the 4,5 reg. This
  443. // requires expanding from u8 to u16 as the 0,1 and 4,5
  444. // registers are already expanded. Then do transposes
  445. // to get aligned.
  446. // xx 20 xx 30 xx 21 xx 31 xx 22 xx 32 xx 23 xx 33
  447. // combine source lines
  448. "uaddl v0.8h, v0.8b, v4.8b \n"
  449. // xx 20 xx 21 xx 22 xx 23
  450. // xx 30 xx 31 xx 32 xx 33
  451. "trn1 v1.8h, v0.8h, v0.8h \n"
  452. "trn2 v4.8h, v0.8h, v0.8h \n"
  453. "xtn v0.4h, v1.4s \n"
  454. "xtn v4.4h, v4.4s \n"
  455. // 0+1+2, 3+4+5
  456. "add v16.8h, v16.8h, v0.8h \n"
  457. "add v17.8h, v17.8h, v4.8h \n"
  458. // Need to divide, but can't downshift as the the value
  459. // isn't a power of 2. So multiply by 65536 / n
  460. // and take the upper 16 bits.
  461. "sqrdmulh v0.8h, v16.8h, v30.8h \n"
  462. "sqrdmulh v1.8h, v17.8h, v30.8h \n"
  463. // Align for table lookup, vtbl requires registers to
  464. // be adjacent
  465. "tbl v3.16b, {v0.16b, v1.16b, v2.16b}, v31.16b \n"
  466. "st1 {v3.8b}, [%1], #8 \n"
  467. "st1 {v3.s}[2], [%1], #4 \n"
  468. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  469. "prfm pldl1keep, [%2, 448] \n"
  470. "b.gt 1b \n"
  471. : "+r"(src_ptr), // %0
  472. "+r"(dst_ptr), // %1
  473. "+r"(tmp_src_stride), // %2
  474. "+r"(dst_width) // %3
  475. : "r"(&kMult38_Div6), // %4
  476. "r"(&kShuf38_2) // %5
  477. : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18",
  478. "v19", "v30", "v31", "memory", "cc");
  479. }
  480. // Add a row of bytes to a row of shorts. Used for box filter.
  481. // Reads 16 bytes and accumulates to 16 shorts at a time.
  482. void ScaleAddRow_NEON(const uint8_t* src_ptr,
  483. uint16_t* dst_ptr,
  484. int src_width) {
  485. asm volatile(
  486. "1: \n"
  487. "ld1 {v1.8h, v2.8h}, [%1] \n" // load accumulator
  488. "ld1 {v0.16b}, [%0], #16 \n" // load 16 bytes
  489. "uaddw2 v2.8h, v2.8h, v0.16b \n" // add
  490. "uaddw v1.8h, v1.8h, v0.8b \n"
  491. "st1 {v1.8h, v2.8h}, [%1], #32 \n" // store accumulator
  492. "subs %w2, %w2, #16 \n" // 16 processed per loop
  493. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  494. "b.gt 1b \n"
  495. : "+r"(src_ptr), // %0
  496. "+r"(dst_ptr), // %1
  497. "+r"(src_width) // %2
  498. :
  499. : "memory", "cc", "v0", "v1", "v2" // Clobber List
  500. );
  501. }
  502. // TODO(Yang Zhang): Investigate less load instructions for
  503. // the x/dx stepping
  504. #define LOAD2_DATA8_LANE(n) \
  505. "lsr %5, %3, #16 \n" \
  506. "add %6, %1, %5 \n" \
  507. "add %3, %3, %4 \n" \
  508. "ld2 {v4.b, v5.b}[" #n "], [%6] \n"
  509. // The NEON version mimics this formula (from row_common.cc):
  510. // #define BLENDER(a, b, f) (uint8_t)((int)(a) +
  511. // ((((int)((f)) * ((int)(b) - (int)(a))) + 0x8000) >> 16))
  512. void ScaleFilterCols_NEON(uint8_t* dst_ptr,
  513. const uint8_t* src_ptr,
  514. int dst_width,
  515. int x,
  516. int dx) {
  517. int dx_offset[4] = {0, 1, 2, 3};
  518. int* tmp = dx_offset;
  519. const uint8_t* src_tmp = src_ptr;
  520. int64_t x64 = (int64_t)x; // NOLINT
  521. int64_t dx64 = (int64_t)dx; // NOLINT
  522. asm volatile (
  523. "dup v0.4s, %w3 \n" // x
  524. "dup v1.4s, %w4 \n" // dx
  525. "ld1 {v2.4s}, [%5] \n" // 0 1 2 3
  526. "shl v3.4s, v1.4s, #2 \n" // 4 * dx
  527. "mul v1.4s, v1.4s, v2.4s \n"
  528. // x , x + 1 * dx, x + 2 * dx, x + 3 * dx
  529. "add v1.4s, v1.4s, v0.4s \n"
  530. // x + 4 * dx, x + 5 * dx, x + 6 * dx, x + 7 * dx
  531. "add v2.4s, v1.4s, v3.4s \n"
  532. "shl v0.4s, v3.4s, #1 \n" // 8 * dx
  533. "1: \n"
  534. LOAD2_DATA8_LANE(0)
  535. LOAD2_DATA8_LANE(1)
  536. LOAD2_DATA8_LANE(2)
  537. LOAD2_DATA8_LANE(3)
  538. LOAD2_DATA8_LANE(4)
  539. LOAD2_DATA8_LANE(5)
  540. LOAD2_DATA8_LANE(6)
  541. LOAD2_DATA8_LANE(7)
  542. "mov v6.16b, v1.16b \n"
  543. "mov v7.16b, v2.16b \n"
  544. "uzp1 v6.8h, v6.8h, v7.8h \n"
  545. "ushll v4.8h, v4.8b, #0 \n"
  546. "ushll v5.8h, v5.8b, #0 \n"
  547. "ssubl v16.4s, v5.4h, v4.4h \n"
  548. "ssubl2 v17.4s, v5.8h, v4.8h \n"
  549. "ushll v7.4s, v6.4h, #0 \n"
  550. "ushll2 v6.4s, v6.8h, #0 \n"
  551. "mul v16.4s, v16.4s, v7.4s \n"
  552. "mul v17.4s, v17.4s, v6.4s \n"
  553. "rshrn v6.4h, v16.4s, #16 \n"
  554. "rshrn2 v6.8h, v17.4s, #16 \n"
  555. "add v4.8h, v4.8h, v6.8h \n"
  556. "xtn v4.8b, v4.8h \n"
  557. "st1 {v4.8b}, [%0], #8 \n" // store pixels
  558. "add v1.4s, v1.4s, v0.4s \n"
  559. "add v2.4s, v2.4s, v0.4s \n"
  560. "subs %w2, %w2, #8 \n" // 8 processed per loop
  561. "b.gt 1b \n"
  562. : "+r"(dst_ptr), // %0
  563. "+r"(src_ptr), // %1
  564. "+r"(dst_width), // %2
  565. "+r"(x64), // %3
  566. "+r"(dx64), // %4
  567. "+r"(tmp), // %5
  568. "+r"(src_tmp) // %6
  569. :
  570. : "memory", "cc", "v0", "v1", "v2", "v3",
  571. "v4", "v5", "v6", "v7", "v16", "v17"
  572. );
  573. }
  574. #undef LOAD2_DATA8_LANE
  575. // 16x2 -> 16x1
  576. void ScaleFilterRows_NEON(uint8_t* dst_ptr,
  577. const uint8_t* src_ptr,
  578. ptrdiff_t src_stride,
  579. int dst_width,
  580. int source_y_fraction) {
  581. int y_fraction = 256 - source_y_fraction;
  582. asm volatile(
  583. "cmp %w4, #0 \n"
  584. "b.eq 100f \n"
  585. "add %2, %2, %1 \n"
  586. "cmp %w4, #64 \n"
  587. "b.eq 75f \n"
  588. "cmp %w4, #128 \n"
  589. "b.eq 50f \n"
  590. "cmp %w4, #192 \n"
  591. "b.eq 25f \n"
  592. "dup v5.8b, %w4 \n"
  593. "dup v4.8b, %w5 \n"
  594. // General purpose row blend.
  595. "1: \n"
  596. "ld1 {v0.16b}, [%1], #16 \n"
  597. "ld1 {v1.16b}, [%2], #16 \n"
  598. "subs %w3, %w3, #16 \n"
  599. "umull v6.8h, v0.8b, v4.8b \n"
  600. "umull2 v7.8h, v0.16b, v4.16b \n"
  601. "umlal v6.8h, v1.8b, v5.8b \n"
  602. "umlal2 v7.8h, v1.16b, v5.16b \n"
  603. "rshrn v0.8b, v6.8h, #8 \n"
  604. "rshrn2 v0.16b, v7.8h, #8 \n"
  605. "st1 {v0.16b}, [%0], #16 \n"
  606. "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead
  607. "prfm pldl1keep, [%2, 448] \n"
  608. "b.gt 1b \n"
  609. "b 99f \n"
  610. // Blend 25 / 75.
  611. "25: \n"
  612. "ld1 {v0.16b}, [%1], #16 \n"
  613. "ld1 {v1.16b}, [%2], #16 \n"
  614. "subs %w3, %w3, #16 \n"
  615. "urhadd v0.16b, v0.16b, v1.16b \n"
  616. "urhadd v0.16b, v0.16b, v1.16b \n"
  617. "st1 {v0.16b}, [%0], #16 \n"
  618. "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead
  619. "prfm pldl1keep, [%2, 448] \n"
  620. "b.gt 25b \n"
  621. "b 99f \n"
  622. // Blend 50 / 50.
  623. "50: \n"
  624. "ld1 {v0.16b}, [%1], #16 \n"
  625. "ld1 {v1.16b}, [%2], #16 \n"
  626. "subs %w3, %w3, #16 \n"
  627. "urhadd v0.16b, v0.16b, v1.16b \n"
  628. "st1 {v0.16b}, [%0], #16 \n"
  629. "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead
  630. "prfm pldl1keep, [%2, 448] \n"
  631. "b.gt 50b \n"
  632. "b 99f \n"
  633. // Blend 75 / 25.
  634. "75: \n"
  635. "ld1 {v1.16b}, [%1], #16 \n"
  636. "ld1 {v0.16b}, [%2], #16 \n"
  637. "subs %w3, %w3, #16 \n"
  638. "urhadd v0.16b, v0.16b, v1.16b \n"
  639. "urhadd v0.16b, v0.16b, v1.16b \n"
  640. "st1 {v0.16b}, [%0], #16 \n"
  641. "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead
  642. "prfm pldl1keep, [%2, 448] \n"
  643. "b.gt 75b \n"
  644. "b 99f \n"
  645. // Blend 100 / 0 - Copy row unchanged.
  646. "100: \n"
  647. "ld1 {v0.16b}, [%1], #16 \n"
  648. "subs %w3, %w3, #16 \n"
  649. "st1 {v0.16b}, [%0], #16 \n"
  650. "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead
  651. "b.gt 100b \n"
  652. "99: \n"
  653. "st1 {v0.b}[15], [%0] \n"
  654. : "+r"(dst_ptr), // %0
  655. "+r"(src_ptr), // %1
  656. "+r"(src_stride), // %2
  657. "+r"(dst_width), // %3
  658. "+r"(source_y_fraction), // %4
  659. "+r"(y_fraction) // %5
  660. :
  661. : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "memory", "cc");
  662. }
  663. void ScaleARGBRowDown2_NEON(const uint8_t* src_ptr,
  664. ptrdiff_t src_stride,
  665. uint8_t* dst,
  666. int dst_width) {
  667. (void)src_stride;
  668. asm volatile(
  669. "1: \n"
  670. // load 16 ARGB pixels with even pixels into q0/q2, odd into q1/q3
  671. "ld4 {v0.4s,v1.4s,v2.4s,v3.4s}, [%0], #64 \n"
  672. "subs %w2, %w2, #8 \n" // 8 processed per loop
  673. "mov v2.16b, v3.16b \n"
  674. "st2 {v1.4s,v2.4s}, [%1], #32 \n" // store 8 odd pixels
  675. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  676. "b.gt 1b \n"
  677. : "+r"(src_ptr), // %0
  678. "+r"(dst), // %1
  679. "+r"(dst_width) // %2
  680. :
  681. : "memory", "cc", "v0", "v1", "v2", "v3" // Clobber List
  682. );
  683. }
  684. void ScaleARGBRowDown2Linear_NEON(const uint8_t* src_argb,
  685. ptrdiff_t src_stride,
  686. uint8_t* dst_argb,
  687. int dst_width) {
  688. (void)src_stride;
  689. asm volatile(
  690. "1: \n"
  691. // load 16 ARGB pixels with even pixels into q0/q2, odd into q1/q3
  692. "ld4 {v0.4s,v1.4s,v2.4s,v3.4s}, [%0], #64 \n"
  693. "subs %w2, %w2, #8 \n" // 8 processed per loop
  694. "urhadd v0.16b, v0.16b, v1.16b \n" // rounding half add
  695. "urhadd v1.16b, v2.16b, v3.16b \n"
  696. "st2 {v0.4s,v1.4s}, [%1], #32 \n" // store 8 pixels
  697. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  698. "b.gt 1b \n"
  699. : "+r"(src_argb), // %0
  700. "+r"(dst_argb), // %1
  701. "+r"(dst_width) // %2
  702. :
  703. : "memory", "cc", "v0", "v1", "v2", "v3" // Clobber List
  704. );
  705. }
  706. void ScaleARGBRowDown2Box_NEON(const uint8_t* src_ptr,
  707. ptrdiff_t src_stride,
  708. uint8_t* dst,
  709. int dst_width) {
  710. asm volatile(
  711. // change the stride to row 2 pointer
  712. "add %1, %1, %0 \n"
  713. "1: \n"
  714. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 8 ARGB
  715. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  716. "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts.
  717. "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts.
  718. "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts.
  719. "uaddlp v3.8h, v3.16b \n" // A 16 bytes -> 8 shorts.
  720. "ld4 {v16.16b,v17.16b,v18.16b,v19.16b}, [%1], #64 \n" // load 8
  721. "uadalp v0.8h, v16.16b \n" // B 16 bytes -> 8 shorts.
  722. "uadalp v1.8h, v17.16b \n" // G 16 bytes -> 8 shorts.
  723. "uadalp v2.8h, v18.16b \n" // R 16 bytes -> 8 shorts.
  724. "uadalp v3.8h, v19.16b \n" // A 16 bytes -> 8 shorts.
  725. "rshrn v0.8b, v0.8h, #2 \n" // round and pack
  726. "rshrn v1.8b, v1.8h, #2 \n"
  727. "rshrn v2.8b, v2.8h, #2 \n"
  728. "rshrn v3.8b, v3.8h, #2 \n"
  729. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n"
  730. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  731. "prfm pldl1keep, [%1, 448] \n"
  732. "b.gt 1b \n"
  733. : "+r"(src_ptr), // %0
  734. "+r"(src_stride), // %1
  735. "+r"(dst), // %2
  736. "+r"(dst_width) // %3
  737. :
  738. : "memory", "cc", "v0", "v1", "v2", "v3", "v16", "v17", "v18", "v19");
  739. }
  740. // Reads 4 pixels at a time.
  741. // Alignment requirement: src_argb 4 byte aligned.
  742. void ScaleARGBRowDownEven_NEON(const uint8_t* src_argb,
  743. ptrdiff_t src_stride,
  744. int src_stepx,
  745. uint8_t* dst_argb,
  746. int dst_width) {
  747. (void)src_stride;
  748. asm volatile(
  749. "1: \n"
  750. "ld1 {v0.s}[0], [%0], %3 \n"
  751. "ld1 {v0.s}[1], [%0], %3 \n"
  752. "ld1 {v0.s}[2], [%0], %3 \n"
  753. "ld1 {v0.s}[3], [%0], %3 \n"
  754. "subs %w2, %w2, #4 \n" // 4 pixels per loop.
  755. "st1 {v0.16b}, [%1], #16 \n"
  756. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  757. "b.gt 1b \n"
  758. : "+r"(src_argb), // %0
  759. "+r"(dst_argb), // %1
  760. "+r"(dst_width) // %2
  761. : "r"((int64_t)(src_stepx * 4)) // %3
  762. : "memory", "cc", "v0");
  763. }
  764. // Reads 4 pixels at a time.
  765. // Alignment requirement: src_argb 4 byte aligned.
  766. // TODO(Yang Zhang): Might be worth another optimization pass in future.
  767. // It could be upgraded to 8 pixels at a time to start with.
  768. void ScaleARGBRowDownEvenBox_NEON(const uint8_t* src_argb,
  769. ptrdiff_t src_stride,
  770. int src_stepx,
  771. uint8_t* dst_argb,
  772. int dst_width) {
  773. asm volatile(
  774. "add %1, %1, %0 \n"
  775. "1: \n"
  776. "ld1 {v0.8b}, [%0], %4 \n" // Read 4 2x2 -> 2x1
  777. "ld1 {v1.8b}, [%1], %4 \n"
  778. "ld1 {v2.8b}, [%0], %4 \n"
  779. "ld1 {v3.8b}, [%1], %4 \n"
  780. "ld1 {v4.8b}, [%0], %4 \n"
  781. "ld1 {v5.8b}, [%1], %4 \n"
  782. "ld1 {v6.8b}, [%0], %4 \n"
  783. "ld1 {v7.8b}, [%1], %4 \n"
  784. "uaddl v0.8h, v0.8b, v1.8b \n"
  785. "uaddl v2.8h, v2.8b, v3.8b \n"
  786. "uaddl v4.8h, v4.8b, v5.8b \n"
  787. "uaddl v6.8h, v6.8b, v7.8b \n"
  788. "mov v16.d[1], v0.d[1] \n" // ab_cd -> ac_bd
  789. "mov v0.d[1], v2.d[0] \n"
  790. "mov v2.d[0], v16.d[1] \n"
  791. "mov v16.d[1], v4.d[1] \n" // ef_gh -> eg_fh
  792. "mov v4.d[1], v6.d[0] \n"
  793. "mov v6.d[0], v16.d[1] \n"
  794. "add v0.8h, v0.8h, v2.8h \n" // (a+b)_(c+d)
  795. "add v4.8h, v4.8h, v6.8h \n" // (e+f)_(g+h)
  796. "rshrn v0.8b, v0.8h, #2 \n" // first 2 pixels.
  797. "rshrn2 v0.16b, v4.8h, #2 \n" // next 2 pixels.
  798. "subs %w3, %w3, #4 \n" // 4 pixels per loop.
  799. "st1 {v0.16b}, [%2], #16 \n"
  800. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  801. "prfm pldl1keep, [%1, 448] \n"
  802. "b.gt 1b \n"
  803. : "+r"(src_argb), // %0
  804. "+r"(src_stride), // %1
  805. "+r"(dst_argb), // %2
  806. "+r"(dst_width) // %3
  807. : "r"((int64_t)(src_stepx * 4)) // %4
  808. : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16");
  809. }
  810. // TODO(Yang Zhang): Investigate less load instructions for
  811. // the x/dx stepping
  812. #define LOAD1_DATA32_LANE(vn, n) \
  813. "lsr %5, %3, #16 \n" \
  814. "add %6, %1, %5, lsl #2 \n" \
  815. "add %3, %3, %4 \n" \
  816. "ld1 {" #vn ".s}[" #n "], [%6] \n"
  817. void ScaleARGBCols_NEON(uint8_t* dst_argb,
  818. const uint8_t* src_argb,
  819. int dst_width,
  820. int x,
  821. int dx) {
  822. const uint8_t* src_tmp = src_argb;
  823. int64_t x64 = (int64_t)x; // NOLINT
  824. int64_t dx64 = (int64_t)dx; // NOLINT
  825. int64_t tmp64;
  826. asm volatile(
  827. "1: \n"
  828. // clang-format off
  829. LOAD1_DATA32_LANE(v0, 0)
  830. LOAD1_DATA32_LANE(v0, 1)
  831. LOAD1_DATA32_LANE(v0, 2)
  832. LOAD1_DATA32_LANE(v0, 3)
  833. LOAD1_DATA32_LANE(v1, 0)
  834. LOAD1_DATA32_LANE(v1, 1)
  835. LOAD1_DATA32_LANE(v1, 2)
  836. LOAD1_DATA32_LANE(v1, 3)
  837. // clang-format on
  838. "st1 {v0.4s, v1.4s}, [%0], #32 \n" // store pixels
  839. "subs %w2, %w2, #8 \n" // 8 processed per loop
  840. "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead
  841. "b.gt 1b \n"
  842. : "+r"(dst_argb), // %0
  843. "+r"(src_argb), // %1
  844. "+r"(dst_width), // %2
  845. "+r"(x64), // %3
  846. "+r"(dx64), // %4
  847. "=&r"(tmp64), // %5
  848. "+r"(src_tmp) // %6
  849. :
  850. : "memory", "cc", "v0", "v1");
  851. }
  852. #undef LOAD1_DATA32_LANE
  853. // TODO(Yang Zhang): Investigate less load instructions for
  854. // the x/dx stepping
  855. #define LOAD2_DATA32_LANE(vn1, vn2, n) \
  856. "lsr %5, %3, #16 \n" \
  857. "add %6, %1, %5, lsl #2 \n" \
  858. "add %3, %3, %4 \n" \
  859. "ld2 {" #vn1 ".s, " #vn2 ".s}[" #n "], [%6] \n"
  860. void ScaleARGBFilterCols_NEON(uint8_t* dst_argb,
  861. const uint8_t* src_argb,
  862. int dst_width,
  863. int x,
  864. int dx) {
  865. int dx_offset[4] = {0, 1, 2, 3};
  866. int* tmp = dx_offset;
  867. const uint8_t* src_tmp = src_argb;
  868. int64_t x64 = (int64_t)x; // NOLINT
  869. int64_t dx64 = (int64_t)dx; // NOLINT
  870. asm volatile (
  871. "dup v0.4s, %w3 \n" // x
  872. "dup v1.4s, %w4 \n" // dx
  873. "ld1 {v2.4s}, [%5] \n" // 0 1 2 3
  874. "shl v6.4s, v1.4s, #2 \n" // 4 * dx
  875. "mul v1.4s, v1.4s, v2.4s \n"
  876. "movi v3.16b, #0x7f \n" // 0x7F
  877. "movi v4.8h, #0x7f \n" // 0x7F
  878. // x , x + 1 * dx, x + 2 * dx, x + 3 * dx
  879. "add v5.4s, v1.4s, v0.4s \n"
  880. "1: \n"
  881. // d0, d1: a
  882. // d2, d3: b
  883. LOAD2_DATA32_LANE(v0, v1, 0)
  884. LOAD2_DATA32_LANE(v0, v1, 1)
  885. LOAD2_DATA32_LANE(v0, v1, 2)
  886. LOAD2_DATA32_LANE(v0, v1, 3)
  887. "shrn v2.4h, v5.4s, #9 \n"
  888. "and v2.8b, v2.8b, v4.8b \n"
  889. "dup v16.8b, v2.b[0] \n"
  890. "dup v17.8b, v2.b[2] \n"
  891. "dup v18.8b, v2.b[4] \n"
  892. "dup v19.8b, v2.b[6] \n"
  893. "ext v2.8b, v16.8b, v17.8b, #4 \n"
  894. "ext v17.8b, v18.8b, v19.8b, #4 \n"
  895. "ins v2.d[1], v17.d[0] \n" // f
  896. "eor v7.16b, v2.16b, v3.16b \n" // 0x7f ^ f
  897. "umull v16.8h, v0.8b, v7.8b \n"
  898. "umull2 v17.8h, v0.16b, v7.16b \n"
  899. "umull v18.8h, v1.8b, v2.8b \n"
  900. "umull2 v19.8h, v1.16b, v2.16b \n"
  901. "add v16.8h, v16.8h, v18.8h \n"
  902. "add v17.8h, v17.8h, v19.8h \n"
  903. "shrn v0.8b, v16.8h, #7 \n"
  904. "shrn2 v0.16b, v17.8h, #7 \n"
  905. "st1 {v0.4s}, [%0], #16 \n" // store pixels
  906. "add v5.4s, v5.4s, v6.4s \n"
  907. "subs %w2, %w2, #4 \n" // 4 processed per loop
  908. "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead
  909. "b.gt 1b \n"
  910. : "+r"(dst_argb), // %0
  911. "+r"(src_argb), // %1
  912. "+r"(dst_width), // %2
  913. "+r"(x64), // %3
  914. "+r"(dx64), // %4
  915. "+r"(tmp), // %5
  916. "+r"(src_tmp) // %6
  917. :
  918. : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5",
  919. "v6", "v7", "v16", "v17", "v18", "v19"
  920. );
  921. }
  922. #undef LOAD2_DATA32_LANE
  923. // Read 16x2 average down and write 8x1.
  924. void ScaleRowDown2Box_16_NEON(const uint16_t* src_ptr,
  925. ptrdiff_t src_stride,
  926. uint16_t* dst,
  927. int dst_width) {
  928. asm volatile(
  929. // change the stride to row 2 pointer
  930. "add %1, %0, %1, lsl #1 \n" // ptr + stide * 2
  931. "1: \n"
  932. "ld1 {v0.8h, v1.8h}, [%0], #32 \n" // load row 1 and post inc
  933. "ld1 {v2.8h, v3.8h}, [%1], #32 \n" // load row 2 and post inc
  934. "subs %w3, %w3, #8 \n" // 8 processed per loop
  935. "uaddlp v0.4s, v0.8h \n" // row 1 add adjacent
  936. "uaddlp v1.4s, v1.8h \n"
  937. "uadalp v0.4s, v2.8h \n" // +row 2 add adjacent
  938. "uadalp v1.4s, v3.8h \n"
  939. "rshrn v0.4h, v0.4s, #2 \n" // round and pack
  940. "rshrn2 v0.8h, v1.4s, #2 \n"
  941. "st1 {v0.8h}, [%2], #16 \n"
  942. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  943. "prfm pldl1keep, [%1, 448] \n"
  944. "b.gt 1b \n"
  945. : "+r"(src_ptr), // %0
  946. "+r"(src_stride), // %1
  947. "+r"(dst), // %2
  948. "+r"(dst_width) // %3
  949. :
  950. : "v0", "v1", "v2", "v3" // Clobber List
  951. );
  952. }
  953. // Read 8x2 upsample with filtering and write 16x1.
  954. // Actually reads an extra pixel, so 9x2.
  955. void ScaleRowUp2_16_NEON(const uint16_t* src_ptr,
  956. ptrdiff_t src_stride,
  957. uint16_t* dst,
  958. int dst_width) {
  959. asm volatile(
  960. "add %1, %0, %1, lsl #1 \n" // ptr + stide * 2
  961. "movi v0.8h, #9 \n" // constants
  962. "movi v1.4s, #3 \n"
  963. "1: \n"
  964. "ld1 {v3.8h}, [%0], %4 \n" // TL read first 8
  965. "ld1 {v4.8h}, [%0], %5 \n" // TR read 8 offset by 1
  966. "ld1 {v5.8h}, [%1], %4 \n" // BL read 8 from next row
  967. "ld1 {v6.8h}, [%1], %5 \n" // BR offset by 1
  968. "subs %w3, %w3, #16 \n" // 16 dst pixels per loop
  969. "umull v16.4s, v3.4h, v0.4h \n"
  970. "umull2 v7.4s, v3.8h, v0.8h \n"
  971. "umull v18.4s, v4.4h, v0.4h \n"
  972. "umull2 v17.4s, v4.8h, v0.8h \n"
  973. "uaddw v16.4s, v16.4s, v6.4h \n"
  974. "uaddl2 v19.4s, v6.8h, v3.8h \n"
  975. "uaddl v3.4s, v6.4h, v3.4h \n"
  976. "uaddw2 v6.4s, v7.4s, v6.8h \n"
  977. "uaddl2 v7.4s, v5.8h, v4.8h \n"
  978. "uaddl v4.4s, v5.4h, v4.4h \n"
  979. "uaddw v18.4s, v18.4s, v5.4h \n"
  980. "mla v16.4s, v4.4s, v1.4s \n"
  981. "mla v18.4s, v3.4s, v1.4s \n"
  982. "mla v6.4s, v7.4s, v1.4s \n"
  983. "uaddw2 v4.4s, v17.4s, v5.8h \n"
  984. "uqrshrn v16.4h, v16.4s, #4 \n"
  985. "mla v4.4s, v19.4s, v1.4s \n"
  986. "uqrshrn2 v16.8h, v6.4s, #4 \n"
  987. "uqrshrn v17.4h, v18.4s, #4 \n"
  988. "uqrshrn2 v17.8h, v4.4s, #4 \n"
  989. "st2 {v16.8h-v17.8h}, [%2], #32 \n"
  990. "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead
  991. "prfm pldl1keep, [%1, 448] \n"
  992. "b.gt 1b \n"
  993. : "+r"(src_ptr), // %0
  994. "+r"(src_stride), // %1
  995. "+r"(dst), // %2
  996. "+r"(dst_width) // %3
  997. : "r"(2LL), // %4
  998. "r"(14LL) // %5
  999. : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18",
  1000. "v19" // Clobber List
  1001. );
  1002. }
  1003. #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
  1004. #ifdef __cplusplus
  1005. } // extern "C"
  1006. } // namespace libyuv
  1007. #endif