scale_neon64.cc 45 KB

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