rgb2rgb_rvv.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright © 2022 Rémi Denis-Courmont.
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/riscv/asm.S"
  21. func ff_shuffle_bytes_0321_rvv, zve32x
  22. lpad 0
  23. li t1, 0x00ff00ff
  24. j 1f
  25. endfunc
  26. func ff_shuffle_bytes_2103_rvv, zve32x, zba
  27. lpad 0
  28. li t1, ~0x00ff00ff
  29. 1:
  30. not t2, t1
  31. srai a2, a2, 2
  32. 2:
  33. vsetvli t0, a2, e32, m8, ta, ma
  34. vle32.v v8, (a0)
  35. sub a2, a2, t0
  36. vand.vx v16, v8, t2
  37. sh2add a0, t0, a0
  38. vand.vx v8, v8, t1
  39. vsrl.vi v24, v16, 16
  40. vsll.vi v16, v16, 16
  41. vor.vv v8, v8, v24
  42. vor.vv v8, v16, v8
  43. vse32.v v8, (a1)
  44. sh2add a1, t0, a1
  45. bnez a2, 2b
  46. ret
  47. endfunc
  48. func ff_shuffle_bytes_1230_rvv, zve32x
  49. lpad 0
  50. li t1, 24
  51. li t2, 8
  52. j 3f
  53. endfunc
  54. func ff_shuffle_bytes_3012_rvv, zve32x, zba
  55. lpad 0
  56. li t1, 8
  57. li t2, 24
  58. 3:
  59. srai a2, a2, 2
  60. 4:
  61. vsetvli t0, a2, e32, m8, ta, ma
  62. vle32.v v8, (a0)
  63. sub a2, a2, t0
  64. vsll.vx v16, v8, t1
  65. sh2add a0, t0, a0
  66. vsrl.vx v8, v8, t2
  67. vor.vv v16, v16, v8
  68. vse32.v v16, (a1)
  69. sh2add a1, t0, a1
  70. bnez a2, 4b
  71. ret
  72. endfunc
  73. func ff_interleave_bytes_rvv, zve32x, zba
  74. lpad 0
  75. 1:
  76. mv t0, a0
  77. mv t1, a1
  78. mv t2, a2
  79. mv t3, a3
  80. addi a4, a4, -1
  81. 2:
  82. vsetvli t4, t3, e8, m4, ta, ma
  83. sub t3, t3, t4
  84. vle8.v v8, (t0)
  85. add t0, t4, t0
  86. vle8.v v12, (t1)
  87. add t1, t4, t1
  88. vsseg2e8.v v8, (t2)
  89. sh1add t2, t4, t2
  90. bnez t3, 2b
  91. add a0, a0, a5
  92. add a1, a1, a6
  93. add a2, a2, a7
  94. bnez a4, 1b
  95. ret
  96. endfunc
  97. func ff_deinterleave_bytes_rvv, zve32x, zba
  98. lpad 0
  99. 1:
  100. mv t0, a0
  101. mv t1, a1
  102. mv t2, a2
  103. mv t3, a3
  104. addi a4, a4, -1
  105. 2:
  106. vsetvli t4, t3, e8, m4, ta, ma
  107. sub t3, t3, t4
  108. vlseg2e8.v v8, (t0)
  109. sh1add t0, t4, t0
  110. vse8.v v8, (t1)
  111. add t1, t4, t1
  112. vse8.v v12, (t2)
  113. add t2, t4, t2
  114. bnez t3, 2b
  115. add a0, a0, a5
  116. add a1, a1, a6
  117. add a2, a2, a7
  118. bnez a4, 1b
  119. ret
  120. endfunc
  121. .macro yuy2_to_i422p luma, chroma
  122. lpad 0
  123. srai t4, a4, 1 // pixel width -> chroma width
  124. lw t6, (sp)
  125. slli t5, a4, 1 // pixel width -> (source) byte width
  126. sub a6, a6, a4
  127. sub a7, a7, t4
  128. sub t6, t6, t5
  129. vsetvli t2, zero, e8, m4, ta, ma
  130. 1:
  131. mv t4, a4
  132. addi a5, a5, -1
  133. 2:
  134. min t0, t2, t4 // ensure even VL on penultimate iteration
  135. vsetvli t0, t0, e8, m4, ta, ma
  136. vlseg2e8.v v16, (a3)
  137. srli t1, t0, 1
  138. vsetvli zero, t1, e8, m2, ta, ma
  139. vnsrl.wi v24, \chroma, 0 // U
  140. sub t4, t4, t0
  141. vnsrl.wi v28, \chroma, 8 // V
  142. sh1add a3, t0, a3
  143. vse8.v v24, (a1)
  144. add a1, t1, a1
  145. vse8.v v28, (a2)
  146. add a2, t1, a2
  147. vsetvli zero, t0, e8, m4, ta, ma
  148. vse8.v \luma, (a0)
  149. add a0, t0, a0
  150. bnez t4, 2b
  151. add a3, a3, t6
  152. add a0, a0, a6
  153. add a1, a1, a7
  154. add a2, a2, a7
  155. bnez a5, 1b
  156. ret
  157. .endm
  158. func ff_uyvytoyuv422_rvv, zve32x, b
  159. yuy2_to_i422p v20, v16
  160. endfunc
  161. func ff_yuyvtoyuv422_rvv, zve32x, b
  162. yuy2_to_i422p v16, v20
  163. endfunc