rgb2rgb_rvv.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. li t1, 0x00ff00ff
  23. j 1f
  24. endfunc
  25. func ff_shuffle_bytes_2103_rvv, zve32x
  26. li t1, ~0x00ff00ff
  27. 1:
  28. not t2, t1
  29. srai a2, a2, 2
  30. 2:
  31. vsetvli t0, a2, e32, m8, ta, ma
  32. vle32.v v8, (a0)
  33. sub a2, a2, t0
  34. vand.vx v16, v8, t2
  35. sh2add a0, t0, a0
  36. vand.vx v8, v8, t1
  37. vsrl.vi v24, v16, 16
  38. vsll.vi v16, v16, 16
  39. vor.vv v8, v8, v24
  40. vor.vv v8, v16, v8
  41. vse32.v v8, (a1)
  42. sh2add a1, t0, a1
  43. bnez a2, 2b
  44. ret
  45. endfunc
  46. func ff_shuffle_bytes_1230_rvv, zve32x
  47. li t1, 24
  48. li t2, 8
  49. j 3f
  50. endfunc
  51. func ff_shuffle_bytes_3012_rvv, zve32x
  52. li t1, 8
  53. li t2, 24
  54. 3:
  55. srai a2, a2, 2
  56. 4:
  57. vsetvli t0, a2, e32, m8, ta, ma
  58. vle32.v v8, (a0)
  59. sub a2, a2, t0
  60. vsll.vx v16, v8, t1
  61. sh2add a0, t0, a0
  62. vsrl.vx v8, v8, t2
  63. vor.vv v16, v16, v8
  64. vse32.v v16, (a1)
  65. sh2add a1, t0, a1
  66. bnez a2, 4b
  67. ret
  68. endfunc
  69. func ff_interleave_bytes_rvv, zve32x
  70. 1:
  71. mv t0, a0
  72. mv t1, a1
  73. mv t2, a2
  74. mv t3, a3
  75. addi a4, a4, -1
  76. 2:
  77. vsetvli t4, t3, e8, m4, ta, ma
  78. sub t3, t3, t4
  79. vle8.v v8, (t0)
  80. add t0, t4, t0
  81. vle8.v v12, (t1)
  82. add t1, t4, t1
  83. vsseg2e8.v v8, (t2)
  84. sh1add t2, t4, t2
  85. bnez t3, 2b
  86. add a0, a0, a5
  87. add a1, a1, a6
  88. add a2, a2, a7
  89. bnez a4, 1b
  90. ret
  91. endfunc
  92. func ff_deinterleave_bytes_rvv, zve32x
  93. 1:
  94. mv t0, a0
  95. mv t1, a1
  96. mv t2, a2
  97. mv t3, a3
  98. addi a4, a4, -1
  99. 2:
  100. vsetvli t4, t3, e8, m4, ta, ma
  101. sub t3, t3, t4
  102. vlseg2e8.v v8, (t0)
  103. sh1add t0, t4, t0
  104. vse8.v v8, (t1)
  105. add t1, t4, t1
  106. vse8.v v12, (t2)
  107. add t2, t4, t2
  108. bnez t3, 2b
  109. add a0, a0, a5
  110. add a1, a1, a6
  111. add a2, a2, a7
  112. bnez a4, 1b
  113. ret
  114. endfunc
  115. .macro yuy2_to_i422p luma, chroma
  116. srai t4, a4, 1 // pixel width -> chroma width
  117. lw t6, (sp)
  118. slli t5, a4, 1 // pixel width -> (source) byte width
  119. sub a6, a6, a4
  120. sub a7, a7, t4
  121. sub t6, t6, t5
  122. vsetvli t2, zero, e8, m4, ta, ma
  123. 1:
  124. mv t4, a4
  125. addi a5, a5, -1
  126. 2:
  127. min t0, t2, t4 // ensure even VL on penultimate iteration
  128. vsetvli t0, t0, e8, m4, ta, ma
  129. vlseg2e8.v v16, (a3)
  130. srli t1, t0, 1
  131. vsetvli zero, t1, e8, m2, ta, ma
  132. vnsrl.wi v24, \chroma, 0 // U
  133. sub t4, t4, t0
  134. vnsrl.wi v28, \chroma, 8 // V
  135. sh1add a3, t0, a3
  136. vse8.v v24, (a1)
  137. add a1, t1, a1
  138. vse8.v v28, (a2)
  139. add a2, t1, a2
  140. vsetvli zero, t0, e8, m4, ta, ma
  141. vse8.v \luma, (a0)
  142. add a0, t0, a0
  143. bnez t4, 2b
  144. add a3, a3, t6
  145. add a0, a0, a6
  146. add a1, a1, a7
  147. add a2, a2, a7
  148. bnez a5, 1b
  149. ret
  150. .endm
  151. func ff_uyvytoyuv422_rvv, zve32x, zbb
  152. yuy2_to_i422p v20, v16
  153. endfunc
  154. func ff_yuyvtoyuv422_rvv, zve32x, zbb
  155. yuy2_to_i422p v16, v20
  156. endfunc