row_mips.cc 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /*
  2. * Copyright (c) 2012 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. #ifdef __cplusplus
  12. namespace libyuv {
  13. extern "C" {
  14. #endif
  15. // The following are available on Mips platforms:
  16. #if !defined(LIBYUV_DISABLE_MIPS) && defined(__mips__) && \
  17. (_MIPS_SIM == _MIPS_SIM_ABI32)
  18. #ifdef HAS_COPYROW_MIPS
  19. void CopyRow_MIPS(const uint8* src, uint8* dst, int count) {
  20. __asm__ __volatile__ (
  21. ".set noreorder \n"
  22. ".set noat \n"
  23. "slti $at, %[count], 8 \n"
  24. "bne $at ,$zero, $last8 \n"
  25. "xor $t8, %[src], %[dst] \n"
  26. "andi $t8, $t8, 0x3 \n"
  27. "bne $t8, $zero, unaligned \n"
  28. "negu $a3, %[dst] \n"
  29. // make dst/src aligned
  30. "andi $a3, $a3, 0x3 \n"
  31. "beq $a3, $zero, $chk16w \n"
  32. // word-aligned now count is the remining bytes count
  33. "subu %[count], %[count], $a3 \n"
  34. "lwr $t8, 0(%[src]) \n"
  35. "addu %[src], %[src], $a3 \n"
  36. "swr $t8, 0(%[dst]) \n"
  37. "addu %[dst], %[dst], $a3 \n"
  38. // Now the dst/src are mutually word-aligned with word-aligned addresses
  39. "$chk16w: \n"
  40. "andi $t8, %[count], 0x3f \n" // whole 64-B chunks?
  41. // t8 is the byte count after 64-byte chunks
  42. "beq %[count], $t8, chk8w \n"
  43. // There will be at most 1 32-byte chunk after it
  44. "subu $a3, %[count], $t8 \n" // the reminder
  45. // Here a3 counts bytes in 16w chunks
  46. "addu $a3, %[dst], $a3 \n"
  47. // Now a3 is the final dst after 64-byte chunks
  48. "addu $t0, %[dst], %[count] \n"
  49. // t0 is the "past the end" address
  50. // When in the loop we exercise "pref 30,x(a1)", the a1+x should not be past
  51. // the "t0-32" address
  52. // This means: for x=128 the last "safe" a1 address is "t0-160"
  53. // Alternatively, for x=64 the last "safe" a1 address is "t0-96"
  54. // we will use "pref 30,128(a1)", so "t0-160" is the limit
  55. "subu $t9, $t0, 160 \n"
  56. // t9 is the "last safe pref 30,128(a1)" address
  57. "pref 0, 0(%[src]) \n" // first line of src
  58. "pref 0, 32(%[src]) \n" // second line of src
  59. "pref 0, 64(%[src]) \n"
  60. "pref 30, 32(%[dst]) \n"
  61. // In case the a1 > t9 don't use "pref 30" at all
  62. "sgtu $v1, %[dst], $t9 \n"
  63. "bgtz $v1, $loop16w \n"
  64. "nop \n"
  65. // otherwise, start with using pref30
  66. "pref 30, 64(%[dst]) \n"
  67. "$loop16w: \n"
  68. "pref 0, 96(%[src]) \n"
  69. "lw $t0, 0(%[src]) \n"
  70. "bgtz $v1, $skip_pref30_96 \n" // skip
  71. "lw $t1, 4(%[src]) \n"
  72. "pref 30, 96(%[dst]) \n" // continue
  73. "$skip_pref30_96: \n"
  74. "lw $t2, 8(%[src]) \n"
  75. "lw $t3, 12(%[src]) \n"
  76. "lw $t4, 16(%[src]) \n"
  77. "lw $t5, 20(%[src]) \n"
  78. "lw $t6, 24(%[src]) \n"
  79. "lw $t7, 28(%[src]) \n"
  80. "pref 0, 128(%[src]) \n"
  81. // bring the next lines of src, addr 128
  82. "sw $t0, 0(%[dst]) \n"
  83. "sw $t1, 4(%[dst]) \n"
  84. "sw $t2, 8(%[dst]) \n"
  85. "sw $t3, 12(%[dst]) \n"
  86. "sw $t4, 16(%[dst]) \n"
  87. "sw $t5, 20(%[dst]) \n"
  88. "sw $t6, 24(%[dst]) \n"
  89. "sw $t7, 28(%[dst]) \n"
  90. "lw $t0, 32(%[src]) \n"
  91. "bgtz $v1, $skip_pref30_128 \n" // skip pref 30,128(a1)
  92. "lw $t1, 36(%[src]) \n"
  93. "pref 30, 128(%[dst]) \n" // set dest, addr 128
  94. "$skip_pref30_128: \n"
  95. "lw $t2, 40(%[src]) \n"
  96. "lw $t3, 44(%[src]) \n"
  97. "lw $t4, 48(%[src]) \n"
  98. "lw $t5, 52(%[src]) \n"
  99. "lw $t6, 56(%[src]) \n"
  100. "lw $t7, 60(%[src]) \n"
  101. "pref 0, 160(%[src]) \n"
  102. // bring the next lines of src, addr 160
  103. "sw $t0, 32(%[dst]) \n"
  104. "sw $t1, 36(%[dst]) \n"
  105. "sw $t2, 40(%[dst]) \n"
  106. "sw $t3, 44(%[dst]) \n"
  107. "sw $t4, 48(%[dst]) \n"
  108. "sw $t5, 52(%[dst]) \n"
  109. "sw $t6, 56(%[dst]) \n"
  110. "sw $t7, 60(%[dst]) \n"
  111. "addiu %[dst], %[dst], 64 \n" // adding 64 to dest
  112. "sgtu $v1, %[dst], $t9 \n"
  113. "bne %[dst], $a3, $loop16w \n"
  114. " addiu %[src], %[src], 64 \n" // adding 64 to src
  115. "move %[count], $t8 \n"
  116. // Here we have src and dest word-aligned but less than 64-bytes to go
  117. "chk8w: \n"
  118. "pref 0, 0x0(%[src]) \n"
  119. "andi $t8, %[count], 0x1f \n" // 32-byte chunk?
  120. // the t8 is the reminder count past 32-bytes
  121. "beq %[count], $t8, chk1w \n"
  122. // count=t8,no 32-byte chunk
  123. " nop \n"
  124. "lw $t0, 0(%[src]) \n"
  125. "lw $t1, 4(%[src]) \n"
  126. "lw $t2, 8(%[src]) \n"
  127. "lw $t3, 12(%[src]) \n"
  128. "lw $t4, 16(%[src]) \n"
  129. "lw $t5, 20(%[src]) \n"
  130. "lw $t6, 24(%[src]) \n"
  131. "lw $t7, 28(%[src]) \n"
  132. "addiu %[src], %[src], 32 \n"
  133. "sw $t0, 0(%[dst]) \n"
  134. "sw $t1, 4(%[dst]) \n"
  135. "sw $t2, 8(%[dst]) \n"
  136. "sw $t3, 12(%[dst]) \n"
  137. "sw $t4, 16(%[dst]) \n"
  138. "sw $t5, 20(%[dst]) \n"
  139. "sw $t6, 24(%[dst]) \n"
  140. "sw $t7, 28(%[dst]) \n"
  141. "addiu %[dst], %[dst], 32 \n"
  142. "chk1w: \n"
  143. "andi %[count], $t8, 0x3 \n"
  144. // now count is the reminder past 1w chunks
  145. "beq %[count], $t8, $last8 \n"
  146. " subu $a3, $t8, %[count] \n"
  147. // a3 is count of bytes in 1w chunks
  148. "addu $a3, %[dst], $a3 \n"
  149. // now a3 is the dst address past the 1w chunks
  150. // copying in words (4-byte chunks)
  151. "$wordCopy_loop: \n"
  152. "lw $t3, 0(%[src]) \n"
  153. // the first t3 may be equal t0 ... optimize?
  154. "addiu %[src], %[src],4 \n"
  155. "addiu %[dst], %[dst],4 \n"
  156. "bne %[dst], $a3,$wordCopy_loop \n"
  157. " sw $t3, -4(%[dst]) \n"
  158. // For the last (<8) bytes
  159. "$last8: \n"
  160. "blez %[count], leave \n"
  161. " addu $a3, %[dst], %[count] \n" // a3 -last dst address
  162. "$last8loop: \n"
  163. "lb $v1, 0(%[src]) \n"
  164. "addiu %[src], %[src], 1 \n"
  165. "addiu %[dst], %[dst], 1 \n"
  166. "bne %[dst], $a3, $last8loop \n"
  167. " sb $v1, -1(%[dst]) \n"
  168. "leave: \n"
  169. " j $ra \n"
  170. " nop \n"
  171. //
  172. // UNALIGNED case
  173. //
  174. "unaligned: \n"
  175. // got here with a3="negu a1"
  176. "andi $a3, $a3, 0x3 \n" // a1 is word aligned?
  177. "beqz $a3, $ua_chk16w \n"
  178. " subu %[count], %[count], $a3 \n"
  179. // bytes left after initial a3 bytes
  180. "lwr $v1, 0(%[src]) \n"
  181. "lwl $v1, 3(%[src]) \n"
  182. "addu %[src], %[src], $a3 \n" // a3 may be 1, 2 or 3
  183. "swr $v1, 0(%[dst]) \n"
  184. "addu %[dst], %[dst], $a3 \n"
  185. // below the dst will be word aligned (NOTE1)
  186. "$ua_chk16w: \n"
  187. "andi $t8, %[count], 0x3f \n" // whole 64-B chunks?
  188. // t8 is the byte count after 64-byte chunks
  189. "beq %[count], $t8, ua_chk8w \n"
  190. // if a2==t8, no 64-byte chunks
  191. // There will be at most 1 32-byte chunk after it
  192. "subu $a3, %[count], $t8 \n" // the reminder
  193. // Here a3 counts bytes in 16w chunks
  194. "addu $a3, %[dst], $a3 \n"
  195. // Now a3 is the final dst after 64-byte chunks
  196. "addu $t0, %[dst], %[count] \n" // t0 "past the end"
  197. "subu $t9, $t0, 160 \n"
  198. // t9 is the "last safe pref 30,128(a1)" address
  199. "pref 0, 0(%[src]) \n" // first line of src
  200. "pref 0, 32(%[src]) \n" // second line addr 32
  201. "pref 0, 64(%[src]) \n"
  202. "pref 30, 32(%[dst]) \n"
  203. // safe, as we have at least 64 bytes ahead
  204. // In case the a1 > t9 don't use "pref 30" at all
  205. "sgtu $v1, %[dst], $t9 \n"
  206. "bgtz $v1, $ua_loop16w \n"
  207. // skip "pref 30,64(a1)" for too short arrays
  208. " nop \n"
  209. // otherwise, start with using pref30
  210. "pref 30, 64(%[dst]) \n"
  211. "$ua_loop16w: \n"
  212. "pref 0, 96(%[src]) \n"
  213. "lwr $t0, 0(%[src]) \n"
  214. "lwl $t0, 3(%[src]) \n"
  215. "lwr $t1, 4(%[src]) \n"
  216. "bgtz $v1, $ua_skip_pref30_96 \n"
  217. " lwl $t1, 7(%[src]) \n"
  218. "pref 30, 96(%[dst]) \n"
  219. // continue setting up the dest, addr 96
  220. "$ua_skip_pref30_96: \n"
  221. "lwr $t2, 8(%[src]) \n"
  222. "lwl $t2, 11(%[src]) \n"
  223. "lwr $t3, 12(%[src]) \n"
  224. "lwl $t3, 15(%[src]) \n"
  225. "lwr $t4, 16(%[src]) \n"
  226. "lwl $t4, 19(%[src]) \n"
  227. "lwr $t5, 20(%[src]) \n"
  228. "lwl $t5, 23(%[src]) \n"
  229. "lwr $t6, 24(%[src]) \n"
  230. "lwl $t6, 27(%[src]) \n"
  231. "lwr $t7, 28(%[src]) \n"
  232. "lwl $t7, 31(%[src]) \n"
  233. "pref 0, 128(%[src]) \n"
  234. // bring the next lines of src, addr 128
  235. "sw $t0, 0(%[dst]) \n"
  236. "sw $t1, 4(%[dst]) \n"
  237. "sw $t2, 8(%[dst]) \n"
  238. "sw $t3, 12(%[dst]) \n"
  239. "sw $t4, 16(%[dst]) \n"
  240. "sw $t5, 20(%[dst]) \n"
  241. "sw $t6, 24(%[dst]) \n"
  242. "sw $t7, 28(%[dst]) \n"
  243. "lwr $t0, 32(%[src]) \n"
  244. "lwl $t0, 35(%[src]) \n"
  245. "lwr $t1, 36(%[src]) \n"
  246. "bgtz $v1, ua_skip_pref30_128 \n"
  247. " lwl $t1, 39(%[src]) \n"
  248. "pref 30, 128(%[dst]) \n"
  249. // continue setting up the dest, addr 128
  250. "ua_skip_pref30_128: \n"
  251. "lwr $t2, 40(%[src]) \n"
  252. "lwl $t2, 43(%[src]) \n"
  253. "lwr $t3, 44(%[src]) \n"
  254. "lwl $t3, 47(%[src]) \n"
  255. "lwr $t4, 48(%[src]) \n"
  256. "lwl $t4, 51(%[src]) \n"
  257. "lwr $t5, 52(%[src]) \n"
  258. "lwl $t5, 55(%[src]) \n"
  259. "lwr $t6, 56(%[src]) \n"
  260. "lwl $t6, 59(%[src]) \n"
  261. "lwr $t7, 60(%[src]) \n"
  262. "lwl $t7, 63(%[src]) \n"
  263. "pref 0, 160(%[src]) \n"
  264. // bring the next lines of src, addr 160
  265. "sw $t0, 32(%[dst]) \n"
  266. "sw $t1, 36(%[dst]) \n"
  267. "sw $t2, 40(%[dst]) \n"
  268. "sw $t3, 44(%[dst]) \n"
  269. "sw $t4, 48(%[dst]) \n"
  270. "sw $t5, 52(%[dst]) \n"
  271. "sw $t6, 56(%[dst]) \n"
  272. "sw $t7, 60(%[dst]) \n"
  273. "addiu %[dst],%[dst],64 \n" // adding 64 to dest
  274. "sgtu $v1,%[dst],$t9 \n"
  275. "bne %[dst],$a3,$ua_loop16w \n"
  276. " addiu %[src],%[src],64 \n" // adding 64 to src
  277. "move %[count],$t8 \n"
  278. // Here we have src and dest word-aligned but less than 64-bytes to go
  279. "ua_chk8w: \n"
  280. "pref 0, 0x0(%[src]) \n"
  281. "andi $t8, %[count], 0x1f \n" // 32-byte chunk?
  282. // the t8 is the reminder count
  283. "beq %[count], $t8, $ua_chk1w \n"
  284. // when count==t8, no 32-byte chunk
  285. "lwr $t0, 0(%[src]) \n"
  286. "lwl $t0, 3(%[src]) \n"
  287. "lwr $t1, 4(%[src]) \n"
  288. "lwl $t1, 7(%[src]) \n"
  289. "lwr $t2, 8(%[src]) \n"
  290. "lwl $t2, 11(%[src]) \n"
  291. "lwr $t3, 12(%[src]) \n"
  292. "lwl $t3, 15(%[src]) \n"
  293. "lwr $t4, 16(%[src]) \n"
  294. "lwl $t4, 19(%[src]) \n"
  295. "lwr $t5, 20(%[src]) \n"
  296. "lwl $t5, 23(%[src]) \n"
  297. "lwr $t6, 24(%[src]) \n"
  298. "lwl $t6, 27(%[src]) \n"
  299. "lwr $t7, 28(%[src]) \n"
  300. "lwl $t7, 31(%[src]) \n"
  301. "addiu %[src], %[src], 32 \n"
  302. "sw $t0, 0(%[dst]) \n"
  303. "sw $t1, 4(%[dst]) \n"
  304. "sw $t2, 8(%[dst]) \n"
  305. "sw $t3, 12(%[dst]) \n"
  306. "sw $t4, 16(%[dst]) \n"
  307. "sw $t5, 20(%[dst]) \n"
  308. "sw $t6, 24(%[dst]) \n"
  309. "sw $t7, 28(%[dst]) \n"
  310. "addiu %[dst], %[dst], 32 \n"
  311. "$ua_chk1w: \n"
  312. "andi %[count], $t8, 0x3 \n"
  313. // now count is the reminder past 1w chunks
  314. "beq %[count], $t8, ua_smallCopy \n"
  315. "subu $a3, $t8, %[count] \n"
  316. // a3 is count of bytes in 1w chunks
  317. "addu $a3, %[dst], $a3 \n"
  318. // now a3 is the dst address past the 1w chunks
  319. // copying in words (4-byte chunks)
  320. "$ua_wordCopy_loop: \n"
  321. "lwr $v1, 0(%[src]) \n"
  322. "lwl $v1, 3(%[src]) \n"
  323. "addiu %[src], %[src], 4 \n"
  324. "addiu %[dst], %[dst], 4 \n"
  325. // note: dst=a1 is word aligned here, see NOTE1
  326. "bne %[dst], $a3, $ua_wordCopy_loop \n"
  327. " sw $v1,-4(%[dst]) \n"
  328. // Now less than 4 bytes (value in count) left to copy
  329. "ua_smallCopy: \n"
  330. "beqz %[count], leave \n"
  331. " addu $a3, %[dst], %[count] \n" // a3 = last dst address
  332. "$ua_smallCopy_loop: \n"
  333. "lb $v1, 0(%[src]) \n"
  334. "addiu %[src], %[src], 1 \n"
  335. "addiu %[dst], %[dst], 1 \n"
  336. "bne %[dst],$a3,$ua_smallCopy_loop \n"
  337. " sb $v1, -1(%[dst]) \n"
  338. "j $ra \n"
  339. " nop \n"
  340. ".set at \n"
  341. ".set reorder \n"
  342. : [dst] "+r" (dst), [src] "+r" (src)
  343. : [count] "r" (count)
  344. : "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
  345. "t8", "t9", "a3", "v1", "at"
  346. );
  347. }
  348. #endif // HAS_COPYROW_MIPS
  349. // DSPR2 functions
  350. #if !defined(LIBYUV_DISABLE_MIPS) && defined(__mips_dsp) && \
  351. (__mips_dsp_rev >= 2) && \
  352. (_MIPS_SIM == _MIPS_SIM_ABI32) && (__mips_isa_rev < 6)
  353. void SplitUVRow_DSPR2(const uint8* src_uv, uint8* dst_u, uint8* dst_v,
  354. int width) {
  355. __asm__ __volatile__ (
  356. ".set push \n"
  357. ".set noreorder \n"
  358. "srl $t4, %[width], 4 \n" // multiplies of 16
  359. "blez $t4, 2f \n"
  360. " andi %[width], %[width], 0xf \n" // residual
  361. "1: \n"
  362. "addiu $t4, $t4, -1 \n"
  363. "lw $t0, 0(%[src_uv]) \n" // V1 | U1 | V0 | U0
  364. "lw $t1, 4(%[src_uv]) \n" // V3 | U3 | V2 | U2
  365. "lw $t2, 8(%[src_uv]) \n" // V5 | U5 | V4 | U4
  366. "lw $t3, 12(%[src_uv]) \n" // V7 | U7 | V6 | U6
  367. "lw $t5, 16(%[src_uv]) \n" // V9 | U9 | V8 | U8
  368. "lw $t6, 20(%[src_uv]) \n" // V11 | U11 | V10 | U10
  369. "lw $t7, 24(%[src_uv]) \n" // V13 | U13 | V12 | U12
  370. "lw $t8, 28(%[src_uv]) \n" // V15 | U15 | V14 | U14
  371. "addiu %[src_uv], %[src_uv], 32 \n"
  372. "precrq.qb.ph $t9, $t1, $t0 \n" // V3 | V2 | V1 | V0
  373. "precr.qb.ph $t0, $t1, $t0 \n" // U3 | U2 | U1 | U0
  374. "precrq.qb.ph $t1, $t3, $t2 \n" // V7 | V6 | V5 | V4
  375. "precr.qb.ph $t2, $t3, $t2 \n" // U7 | U6 | U5 | U4
  376. "precrq.qb.ph $t3, $t6, $t5 \n" // V11 | V10 | V9 | V8
  377. "precr.qb.ph $t5, $t6, $t5 \n" // U11 | U10 | U9 | U8
  378. "precrq.qb.ph $t6, $t8, $t7 \n" // V15 | V14 | V13 | V12
  379. "precr.qb.ph $t7, $t8, $t7 \n" // U15 | U14 | U13 | U12
  380. "sw $t9, 0(%[dst_v]) \n"
  381. "sw $t0, 0(%[dst_u]) \n"
  382. "sw $t1, 4(%[dst_v]) \n"
  383. "sw $t2, 4(%[dst_u]) \n"
  384. "sw $t3, 8(%[dst_v]) \n"
  385. "sw $t5, 8(%[dst_u]) \n"
  386. "sw $t6, 12(%[dst_v]) \n"
  387. "sw $t7, 12(%[dst_u]) \n"
  388. "addiu %[dst_v], %[dst_v], 16 \n"
  389. "bgtz $t4, 1b \n"
  390. " addiu %[dst_u], %[dst_u], 16 \n"
  391. "beqz %[width], 3f \n"
  392. " nop \n"
  393. "2: \n"
  394. "lbu $t0, 0(%[src_uv]) \n"
  395. "lbu $t1, 1(%[src_uv]) \n"
  396. "addiu %[src_uv], %[src_uv], 2 \n"
  397. "addiu %[width], %[width], -1 \n"
  398. "sb $t0, 0(%[dst_u]) \n"
  399. "sb $t1, 0(%[dst_v]) \n"
  400. "addiu %[dst_u], %[dst_u], 1 \n"
  401. "bgtz %[width], 2b \n"
  402. " addiu %[dst_v], %[dst_v], 1 \n"
  403. "3: \n"
  404. ".set pop \n"
  405. : [src_uv] "+r" (src_uv),
  406. [width] "+r" (width),
  407. [dst_u] "+r" (dst_u),
  408. [dst_v] "+r" (dst_v)
  409. :
  410. : "t0", "t1", "t2", "t3",
  411. "t4", "t5", "t6", "t7", "t8", "t9"
  412. );
  413. }
  414. void MirrorRow_DSPR2(const uint8* src, uint8* dst, int width) {
  415. __asm__ __volatile__ (
  416. ".set push \n"
  417. ".set noreorder \n"
  418. "srl $t4, %[width], 4 \n" // multiplies of 16
  419. "andi $t5, %[width], 0xf \n"
  420. "blez $t4, 2f \n"
  421. " addu %[src], %[src], %[width] \n" // src += width
  422. "1: \n"
  423. "lw $t0, -16(%[src]) \n" // |3|2|1|0|
  424. "lw $t1, -12(%[src]) \n" // |7|6|5|4|
  425. "lw $t2, -8(%[src]) \n" // |11|10|9|8|
  426. "lw $t3, -4(%[src]) \n" // |15|14|13|12|
  427. "wsbh $t0, $t0 \n" // |2|3|0|1|
  428. "wsbh $t1, $t1 \n" // |6|7|4|5|
  429. "wsbh $t2, $t2 \n" // |10|11|8|9|
  430. "wsbh $t3, $t3 \n" // |14|15|12|13|
  431. "rotr $t0, $t0, 16 \n" // |0|1|2|3|
  432. "rotr $t1, $t1, 16 \n" // |4|5|6|7|
  433. "rotr $t2, $t2, 16 \n" // |8|9|10|11|
  434. "rotr $t3, $t3, 16 \n" // |12|13|14|15|
  435. "addiu %[src], %[src], -16 \n"
  436. "addiu $t4, $t4, -1 \n"
  437. "sw $t3, 0(%[dst]) \n" // |15|14|13|12|
  438. "sw $t2, 4(%[dst]) \n" // |11|10|9|8|
  439. "sw $t1, 8(%[dst]) \n" // |7|6|5|4|
  440. "sw $t0, 12(%[dst]) \n" // |3|2|1|0|
  441. "bgtz $t4, 1b \n"
  442. " addiu %[dst], %[dst], 16 \n"
  443. "beqz $t5, 3f \n"
  444. " nop \n"
  445. "2: \n"
  446. "lbu $t0, -1(%[src]) \n"
  447. "addiu $t5, $t5, -1 \n"
  448. "addiu %[src], %[src], -1 \n"
  449. "sb $t0, 0(%[dst]) \n"
  450. "bgez $t5, 2b \n"
  451. " addiu %[dst], %[dst], 1 \n"
  452. "3: \n"
  453. ".set pop \n"
  454. : [src] "+r" (src), [dst] "+r" (dst)
  455. : [width] "r" (width)
  456. : "t0", "t1", "t2", "t3", "t4", "t5"
  457. );
  458. }
  459. void MirrorUVRow_DSPR2(const uint8* src_uv, uint8* dst_u, uint8* dst_v,
  460. int width) {
  461. int x;
  462. int y;
  463. __asm__ __volatile__ (
  464. ".set push \n"
  465. ".set noreorder \n"
  466. "addu $t4, %[width], %[width] \n"
  467. "srl %[x], %[width], 4 \n"
  468. "andi %[y], %[width], 0xf \n"
  469. "blez %[x], 2f \n"
  470. " addu %[src_uv], %[src_uv], $t4 \n"
  471. "1: \n"
  472. "lw $t0, -32(%[src_uv]) \n" // |3|2|1|0|
  473. "lw $t1, -28(%[src_uv]) \n" // |7|6|5|4|
  474. "lw $t2, -24(%[src_uv]) \n" // |11|10|9|8|
  475. "lw $t3, -20(%[src_uv]) \n" // |15|14|13|12|
  476. "lw $t4, -16(%[src_uv]) \n" // |19|18|17|16|
  477. "lw $t6, -12(%[src_uv]) \n" // |23|22|21|20|
  478. "lw $t7, -8(%[src_uv]) \n" // |27|26|25|24|
  479. "lw $t8, -4(%[src_uv]) \n" // |31|30|29|28|
  480. "rotr $t0, $t0, 16 \n" // |1|0|3|2|
  481. "rotr $t1, $t1, 16 \n" // |5|4|7|6|
  482. "rotr $t2, $t2, 16 \n" // |9|8|11|10|
  483. "rotr $t3, $t3, 16 \n" // |13|12|15|14|
  484. "rotr $t4, $t4, 16 \n" // |17|16|19|18|
  485. "rotr $t6, $t6, 16 \n" // |21|20|23|22|
  486. "rotr $t7, $t7, 16 \n" // |25|24|27|26|
  487. "rotr $t8, $t8, 16 \n" // |29|28|31|30|
  488. "precr.qb.ph $t9, $t0, $t1 \n" // |0|2|4|6|
  489. "precrq.qb.ph $t5, $t0, $t1 \n" // |1|3|5|7|
  490. "precr.qb.ph $t0, $t2, $t3 \n" // |8|10|12|14|
  491. "precrq.qb.ph $t1, $t2, $t3 \n" // |9|11|13|15|
  492. "precr.qb.ph $t2, $t4, $t6 \n" // |16|18|20|22|
  493. "precrq.qb.ph $t3, $t4, $t6 \n" // |17|19|21|23|
  494. "precr.qb.ph $t4, $t7, $t8 \n" // |24|26|28|30|
  495. "precrq.qb.ph $t6, $t7, $t8 \n" // |25|27|29|31|
  496. "addiu %[src_uv], %[src_uv], -32 \n"
  497. "addiu %[x], %[x], -1 \n"
  498. "swr $t4, 0(%[dst_u]) \n"
  499. "swl $t4, 3(%[dst_u]) \n" // |30|28|26|24|
  500. "swr $t6, 0(%[dst_v]) \n"
  501. "swl $t6, 3(%[dst_v]) \n" // |31|29|27|25|
  502. "swr $t2, 4(%[dst_u]) \n"
  503. "swl $t2, 7(%[dst_u]) \n" // |22|20|18|16|
  504. "swr $t3, 4(%[dst_v]) \n"
  505. "swl $t3, 7(%[dst_v]) \n" // |23|21|19|17|
  506. "swr $t0, 8(%[dst_u]) \n"
  507. "swl $t0, 11(%[dst_u]) \n" // |14|12|10|8|
  508. "swr $t1, 8(%[dst_v]) \n"
  509. "swl $t1, 11(%[dst_v]) \n" // |15|13|11|9|
  510. "swr $t9, 12(%[dst_u]) \n"
  511. "swl $t9, 15(%[dst_u]) \n" // |6|4|2|0|
  512. "swr $t5, 12(%[dst_v]) \n"
  513. "swl $t5, 15(%[dst_v]) \n" // |7|5|3|1|
  514. "addiu %[dst_v], %[dst_v], 16 \n"
  515. "bgtz %[x], 1b \n"
  516. " addiu %[dst_u], %[dst_u], 16 \n"
  517. "beqz %[y], 3f \n"
  518. " nop \n"
  519. "b 2f \n"
  520. " nop \n"
  521. "2: \n"
  522. "lbu $t0, -2(%[src_uv]) \n"
  523. "lbu $t1, -1(%[src_uv]) \n"
  524. "addiu %[src_uv], %[src_uv], -2 \n"
  525. "addiu %[y], %[y], -1 \n"
  526. "sb $t0, 0(%[dst_u]) \n"
  527. "sb $t1, 0(%[dst_v]) \n"
  528. "addiu %[dst_u], %[dst_u], 1 \n"
  529. "bgtz %[y], 2b \n"
  530. " addiu %[dst_v], %[dst_v], 1 \n"
  531. "3: \n"
  532. ".set pop \n"
  533. : [src_uv] "+r" (src_uv),
  534. [dst_u] "+r" (dst_u),
  535. [dst_v] "+r" (dst_v),
  536. [x] "=&r" (x),
  537. [y] "=&r" (y)
  538. : [width] "r" (width)
  539. : "t0", "t1", "t2", "t3", "t4",
  540. "t5", "t7", "t8", "t9"
  541. );
  542. }
  543. // Convert (4 Y and 2 VU) I422 and arrange RGB values into
  544. // t5 = | 0 | B0 | 0 | b0 |
  545. // t4 = | 0 | B1 | 0 | b1 |
  546. // t9 = | 0 | G0 | 0 | g0 |
  547. // t8 = | 0 | G1 | 0 | g1 |
  548. // t2 = | 0 | R0 | 0 | r0 |
  549. // t1 = | 0 | R1 | 0 | r1 |
  550. #define YUVTORGB \
  551. "lw $t0, 0(%[y_buf]) \n" \
  552. "lhu $t1, 0(%[u_buf]) \n" \
  553. "lhu $t2, 0(%[v_buf]) \n" \
  554. "preceu.ph.qbr $t1, $t1 \n" \
  555. "preceu.ph.qbr $t2, $t2 \n" \
  556. "preceu.ph.qbra $t3, $t0 \n" \
  557. "preceu.ph.qbla $t0, $t0 \n" \
  558. "subu.ph $t1, $t1, $s5 \n" \
  559. "subu.ph $t2, $t2, $s5 \n" \
  560. "subu.ph $t3, $t3, $s4 \n" \
  561. "subu.ph $t0, $t0, $s4 \n" \
  562. "mul.ph $t3, $t3, $s0 \n" \
  563. "mul.ph $t0, $t0, $s0 \n" \
  564. "shll.ph $t4, $t1, 0x7 \n" \
  565. "subu.ph $t4, $t4, $t1 \n" \
  566. "mul.ph $t6, $t1, $s1 \n" \
  567. "mul.ph $t1, $t2, $s2 \n" \
  568. "addq_s.ph $t5, $t4, $t3 \n" \
  569. "addq_s.ph $t4, $t4, $t0 \n" \
  570. "shra.ph $t5, $t5, 6 \n" \
  571. "shra.ph $t4, $t4, 6 \n" \
  572. "addiu %[u_buf], 2 \n" \
  573. "addiu %[v_buf], 2 \n" \
  574. "addu.ph $t6, $t6, $t1 \n" \
  575. "mul.ph $t1, $t2, $s3 \n" \
  576. "addu.ph $t9, $t6, $t3 \n" \
  577. "addu.ph $t8, $t6, $t0 \n" \
  578. "shra.ph $t9, $t9, 6 \n" \
  579. "shra.ph $t8, $t8, 6 \n" \
  580. "addu.ph $t2, $t1, $t3 \n" \
  581. "addu.ph $t1, $t1, $t0 \n" \
  582. "shra.ph $t2, $t2, 6 \n" \
  583. "shra.ph $t1, $t1, 6 \n" \
  584. "subu.ph $t5, $t5, $s5 \n" \
  585. "subu.ph $t4, $t4, $s5 \n" \
  586. "subu.ph $t9, $t9, $s5 \n" \
  587. "subu.ph $t8, $t8, $s5 \n" \
  588. "subu.ph $t2, $t2, $s5 \n" \
  589. "subu.ph $t1, $t1, $s5 \n" \
  590. "shll_s.ph $t5, $t5, 8 \n" \
  591. "shll_s.ph $t4, $t4, 8 \n" \
  592. "shll_s.ph $t9, $t9, 8 \n" \
  593. "shll_s.ph $t8, $t8, 8 \n" \
  594. "shll_s.ph $t2, $t2, 8 \n" \
  595. "shll_s.ph $t1, $t1, 8 \n" \
  596. "shra.ph $t5, $t5, 8 \n" \
  597. "shra.ph $t4, $t4, 8 \n" \
  598. "shra.ph $t9, $t9, 8 \n" \
  599. "shra.ph $t8, $t8, 8 \n" \
  600. "shra.ph $t2, $t2, 8 \n" \
  601. "shra.ph $t1, $t1, 8 \n" \
  602. "addu.ph $t5, $t5, $s5 \n" \
  603. "addu.ph $t4, $t4, $s5 \n" \
  604. "addu.ph $t9, $t9, $s5 \n" \
  605. "addu.ph $t8, $t8, $s5 \n" \
  606. "addu.ph $t2, $t2, $s5 \n" \
  607. "addu.ph $t1, $t1, $s5 \n"
  608. // TODO(fbarchard): accept yuv conversion constants.
  609. void I422ToARGBRow_DSPR2(const uint8* y_buf,
  610. const uint8* u_buf,
  611. const uint8* v_buf,
  612. uint8* rgb_buf,
  613. const struct YuvConstants* yuvconstants,
  614. int width) {
  615. __asm__ __volatile__ (
  616. ".set push \n"
  617. ".set noreorder \n"
  618. "beqz %[width], 2f \n"
  619. " repl.ph $s0, 74 \n" // |YG|YG| = |74|74|
  620. "repl.ph $s1, -25 \n" // |UG|UG| = |-25|-25|
  621. "repl.ph $s2, -52 \n" // |VG|VG| = |-52|-52|
  622. "repl.ph $s3, 102 \n" // |VR|VR| = |102|102|
  623. "repl.ph $s4, 16 \n" // |0|16|0|16|
  624. "repl.ph $s5, 128 \n" // |128|128| // clipping
  625. "lui $s6, 0xff00 \n"
  626. "ori $s6, 0xff00 \n" // |ff|00|ff|00|ff|
  627. "1: \n"
  628. YUVTORGB
  629. // Arranging into argb format
  630. "precr.qb.ph $t4, $t8, $t4 \n" // |G1|g1|B1|b1|
  631. "precr.qb.ph $t5, $t9, $t5 \n" // |G0|g0|B0|b0|
  632. "addiu %[width], -4 \n"
  633. "precrq.qb.ph $t8, $t4, $t5 \n" // |G1|B1|G0|B0|
  634. "precr.qb.ph $t9, $t4, $t5 \n" // |g1|b1|g0|b0|
  635. "precr.qb.ph $t2, $t1, $t2 \n" // |R1|r1|R0|r0|
  636. "addiu %[y_buf], 4 \n"
  637. "preceu.ph.qbla $t1, $t2 \n" // |0 |R1|0 |R0|
  638. "preceu.ph.qbra $t2, $t2 \n" // |0 |r1|0 |r0|
  639. "or $t1, $t1, $s6 \n" // |ff|R1|ff|R0|
  640. "or $t2, $t2, $s6 \n" // |ff|r1|ff|r0|
  641. "precrq.ph.w $t0, $t2, $t9 \n" // |ff|r1|g1|b1|
  642. "precrq.ph.w $t3, $t1, $t8 \n" // |ff|R1|G1|B1|
  643. "sll $t9, $t9, 16 \n"
  644. "sll $t8, $t8, 16 \n"
  645. "packrl.ph $t2, $t2, $t9 \n" // |ff|r0|g0|b0|
  646. "packrl.ph $t1, $t1, $t8 \n" // |ff|R0|G0|B0|
  647. // Store results.
  648. "sw $t2, 0(%[rgb_buf]) \n"
  649. "sw $t0, 4(%[rgb_buf]) \n"
  650. "sw $t1, 8(%[rgb_buf]) \n"
  651. "sw $t3, 12(%[rgb_buf]) \n"
  652. "bnez %[width], 1b \n"
  653. " addiu %[rgb_buf], 16 \n"
  654. "2: \n"
  655. ".set pop \n"
  656. :[y_buf] "+r" (y_buf),
  657. [u_buf] "+r" (u_buf),
  658. [v_buf] "+r" (v_buf),
  659. [width] "+r" (width),
  660. [rgb_buf] "+r" (rgb_buf)
  661. :
  662. : "t0", "t1", "t2", "t3", "t4", "t5",
  663. "t6", "t7", "t8", "t9",
  664. "s0", "s1", "s2", "s3",
  665. "s4", "s5", "s6"
  666. );
  667. }
  668. // Bilinear filter 8x2 -> 8x1
  669. void InterpolateRow_DSPR2(uint8* dst_ptr, const uint8* src_ptr,
  670. ptrdiff_t src_stride, int dst_width,
  671. int source_y_fraction) {
  672. int y0_fraction = 256 - source_y_fraction;
  673. const uint8* src_ptr1 = src_ptr + src_stride;
  674. __asm__ __volatile__ (
  675. ".set push \n"
  676. ".set noreorder \n"
  677. "replv.ph $t0, %[y0_fraction] \n"
  678. "replv.ph $t1, %[source_y_fraction] \n"
  679. "1: \n"
  680. "lw $t2, 0(%[src_ptr]) \n"
  681. "lw $t3, 0(%[src_ptr1]) \n"
  682. "lw $t4, 4(%[src_ptr]) \n"
  683. "lw $t5, 4(%[src_ptr1]) \n"
  684. "muleu_s.ph.qbl $t6, $t2, $t0 \n"
  685. "muleu_s.ph.qbr $t7, $t2, $t0 \n"
  686. "muleu_s.ph.qbl $t8, $t3, $t1 \n"
  687. "muleu_s.ph.qbr $t9, $t3, $t1 \n"
  688. "muleu_s.ph.qbl $t2, $t4, $t0 \n"
  689. "muleu_s.ph.qbr $t3, $t4, $t0 \n"
  690. "muleu_s.ph.qbl $t4, $t5, $t1 \n"
  691. "muleu_s.ph.qbr $t5, $t5, $t1 \n"
  692. "addq.ph $t6, $t6, $t8 \n"
  693. "addq.ph $t7, $t7, $t9 \n"
  694. "addq.ph $t2, $t2, $t4 \n"
  695. "addq.ph $t3, $t3, $t5 \n"
  696. "shra.ph $t6, $t6, 8 \n"
  697. "shra.ph $t7, $t7, 8 \n"
  698. "shra.ph $t2, $t2, 8 \n"
  699. "shra.ph $t3, $t3, 8 \n"
  700. "precr.qb.ph $t6, $t6, $t7 \n"
  701. "precr.qb.ph $t2, $t2, $t3 \n"
  702. "addiu %[src_ptr], %[src_ptr], 8 \n"
  703. "addiu %[src_ptr1], %[src_ptr1], 8 \n"
  704. "addiu %[dst_width], %[dst_width], -8 \n"
  705. "sw $t6, 0(%[dst_ptr]) \n"
  706. "sw $t2, 4(%[dst_ptr]) \n"
  707. "bgtz %[dst_width], 1b \n"
  708. " addiu %[dst_ptr], %[dst_ptr], 8 \n"
  709. ".set pop \n"
  710. : [dst_ptr] "+r" (dst_ptr),
  711. [src_ptr1] "+r" (src_ptr1),
  712. [src_ptr] "+r" (src_ptr),
  713. [dst_width] "+r" (dst_width)
  714. : [source_y_fraction] "r" (source_y_fraction),
  715. [y0_fraction] "r" (y0_fraction),
  716. [src_stride] "r" (src_stride)
  717. : "t0", "t1", "t2", "t3", "t4", "t5",
  718. "t6", "t7", "t8", "t9"
  719. );
  720. }
  721. #endif // __mips_dsp_rev >= 2
  722. #endif // defined(__mips__)
  723. #ifdef __cplusplus
  724. } // extern "C"
  725. } // namespace libyuv
  726. #endif