scale_neon64.cc 41 KB

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