range_convert_neon.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2024 Ramiro Polla
  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/aarch64/asm.S"
  21. .macro lumConvertRange name, max, mult, offset, shift
  22. function ff_\name, export=1
  23. .if \max != 0
  24. mov w3, #\max
  25. dup v24.8h, w3
  26. .endif
  27. mov w3, #\mult
  28. dup v25.4s, w3
  29. movz w3, #(\offset & 0xffff)
  30. movk w3, #((\offset >> 16) & 0xffff), lsl #16
  31. dup v26.4s, w3
  32. 1:
  33. ld1 {v0.8h}, [x0]
  34. .if \max != 0
  35. smin v0.8h, v0.8h, v24.8h
  36. .endif
  37. mov v16.16b, v26.16b
  38. mov v18.16b, v26.16b
  39. sxtl v20.4s, v0.4h
  40. sxtl2 v22.4s, v0.8h
  41. mla v16.4s, v20.4s, v25.4s
  42. mla v18.4s, v22.4s, v25.4s
  43. shrn v0.4h, v16.4s, #\shift
  44. shrn2 v0.8h, v18.4s, #\shift
  45. subs w1, w1, #8
  46. st1 {v0.8h}, [x0], #16
  47. b.gt 1b
  48. ret
  49. endfunc
  50. .endm
  51. .macro chrConvertRange name, max, mult, offset, shift
  52. function ff_\name, export=1
  53. .if \max != 0
  54. mov w3, #\max
  55. dup v24.8h, w3
  56. .endif
  57. mov w3, #\mult
  58. dup v25.4s, w3
  59. movz w3, #(\offset & 0xffff)
  60. movk w3, #((\offset >> 16) & 0xffff), lsl #16
  61. dup v26.4s, w3
  62. 1:
  63. ld1 {v0.8h}, [x0]
  64. ld1 {v1.8h}, [x1]
  65. .if \max != 0
  66. smin v0.8h, v0.8h, v24.8h
  67. smin v1.8h, v1.8h, v24.8h
  68. .endif
  69. mov v16.16b, v26.16b
  70. mov v17.16b, v26.16b
  71. mov v18.16b, v26.16b
  72. mov v19.16b, v26.16b
  73. sxtl v20.4s, v0.4h
  74. sxtl v21.4s, v1.4h
  75. sxtl2 v22.4s, v0.8h
  76. sxtl2 v23.4s, v1.8h
  77. mla v16.4s, v20.4s, v25.4s
  78. mla v17.4s, v21.4s, v25.4s
  79. mla v18.4s, v22.4s, v25.4s
  80. mla v19.4s, v23.4s, v25.4s
  81. shrn v0.4h, v16.4s, #\shift
  82. shrn v1.4h, v17.4s, #\shift
  83. shrn2 v0.8h, v18.4s, #\shift
  84. shrn2 v1.8h, v19.4s, #\shift
  85. subs w2, w2, #8
  86. st1 {v0.8h}, [x0], #16
  87. st1 {v1.8h}, [x1], #16
  88. b.gt 1b
  89. ret
  90. endfunc
  91. .endm
  92. lumConvertRange lumRangeToJpeg_neon, 30189, 19077, -39057361, 14
  93. chrConvertRange chrRangeToJpeg_neon, 30775, 4663, -9289992, 12
  94. lumConvertRange lumRangeFromJpeg_neon, 0, 14071, 33561947, 14
  95. chrConvertRange chrRangeFromJpeg_neon, 0, 1799, 4081085, 11