scale_neon64.cc 45 KB

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