range_rvv.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright © 2024 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_range_lum_to_jpeg_16_rvv, zve32x, zba
  22. lpad 0
  23. li t1, 30189
  24. li t2, 19077
  25. li t3, -39057361
  26. 1:
  27. vsetvli t0, a1, e16, m4, ta, ma
  28. vle16.v v0, (a0)
  29. sub a1, a1, t0
  30. vmin.vx v0, v0, t1
  31. vwmul.vx v8, v0, t2
  32. vsetvli zero, zero, e32, m8, ta, ma
  33. vadd.vx v8, v8, t3
  34. vsetvli zero, zero, e16, m4, ta, ma
  35. vnsra.wi v0, v8, 14
  36. vse16.v v0, (a0)
  37. sh1add a0, t0, a0
  38. bnez a1, 1b
  39. ret
  40. endfunc
  41. func ff_range_lum_from_jpeg_16_rvv, zve32x, zba
  42. lpad 0
  43. li t1, 14071
  44. li t2, 33561947
  45. 1:
  46. vsetvli t0, a1, e16, m4, ta, ma
  47. vle16.v v0, (a0)
  48. sub a1, a1, t0
  49. vwmul.vx v8, v0, t1
  50. vsetvli zero, zero, e32, m8, ta, ma
  51. vadd.vx v8, v8, t2
  52. vsetvli zero, zero, e16, m4, ta, ma
  53. vnsra.wi v0, v8, 14
  54. vse16.v v0, (a0)
  55. sh1add a0, t0, a0
  56. bnez a1, 1b
  57. ret
  58. endfunc
  59. func ff_range_chr_to_jpeg_16_rvv, zve32x, zba
  60. lpad 0
  61. li t1, 30775
  62. li t2, 4663
  63. li t3, -9289992
  64. 1:
  65. vsetvli t0, a2, e16, m4, ta, ma
  66. vle16.v v0, (a0)
  67. sub a2, a2, t0
  68. vle16.v v4, (a1)
  69. vmin.vx v0, v0, t1
  70. vmin.vx v4, v4, t1
  71. vwmul.vx v8, v0, t2
  72. vwmul.vx v16, v4, t2
  73. vsetvli zero, zero, e32, m8, ta, ma
  74. vadd.vx v8, v8, t3
  75. vadd.vx v16, v16, t3
  76. vsetvli zero, zero, e16, m4, ta, ma
  77. vnsra.wi v0, v8, 12
  78. vnsra.wi v4, v16, 12
  79. vse16.v v0, (a0)
  80. sh1add a0, t0, a0
  81. vse16.v v4, (a1)
  82. sh1add a1, t0, a1
  83. bnez a2, 1b
  84. ret
  85. endfunc
  86. func ff_range_chr_from_jpeg_16_rvv, zve32x, zba
  87. lpad 0
  88. li t1, 1799
  89. li t2, 4081085
  90. 1:
  91. vsetvli t0, a2, e16, m4, ta, ma
  92. vle16.v v0, (a0)
  93. sub a2, a2, t0
  94. vle16.v v4, (a1)
  95. vwmul.vx v8, v0, t1
  96. vwmul.vx v16, v4, t1
  97. vsetvli zero, zero, e32, m8, ta, ma
  98. vadd.vx v8, v8, t2
  99. vadd.vx v16, v16, t2
  100. vsetvli zero, zero, e16, m4, ta, ma
  101. vnsra.wi v0, v8, 11
  102. vnsra.wi v4, v16, 11
  103. vse16.v v0, (a0)
  104. sh1add a0, t0, a0
  105. vse16.v v4, (a1)
  106. sh1add a1, t0, a1
  107. bnez a2, 1b
  108. ret
  109. endfunc