You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
7.3KB

  1. /*
  2. * Copyright (c) 2014 Janne Grunau <janne-libav@jannau.net>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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. #define FRAC_BITS 23 // fractional bits for sb_samples and dct
  22. #define WFRAC_BITS 16 // fractional bits for window
  23. #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
  24. const tbl_rev128.s align=4
  25. .byte 12, 13, 14, 15
  26. .byte 8, 9, 10, 11
  27. .byte 4, 5, 6, 7
  28. .byte 0, 1, 2, 3
  29. endconst
  30. .macro apply_window type, st
  31. function ff_mpadsp_apply_window_\type\()_neon, export=1
  32. mov x7, x0
  33. sxtw x4, w4 // incr
  34. add x8, x0, #512<<2
  35. ld1 {v0.4s,v1.4s,v2.4s,v3.4s}, [x7], #64
  36. ld1 {v4.4s,v5.4s,v6.4s,v7.4s}, [x7], #64
  37. st1 {v0.4s,v1.4s,v2.4s,v3.4s}, [x8], #64
  38. st1 {v4.4s,v5.4s,v6.4s,v7.4s}, [x8], #64
  39. movrel x15, tbl_rev128.s
  40. ld1 {v27.4s}, [x15]
  41. .ifc \type, fixed
  42. lsl x4, x4, #1
  43. .else
  44. lsl x4, x4, #2
  45. .endif
  46. add x10, x0, #45<<2
  47. add x0, x0, #16<<2
  48. add x1, x1, #16<<2
  49. add x5, x3, x4, lsl #5
  50. sub x5, x5, x4 // samples2
  51. neg x13, x4 // -incr
  52. mov x9, #64<<2
  53. .ifc \type, fixed
  54. ld1r {v16.2s}, [x2] // dither_state
  55. sxtl v16.2d, v16.2s
  56. movi v29.2d, #0
  57. movi v30.2d, #(1<<OUT_SHIFT)-1
  58. trn1 v31.2d, v29.2d, v30.2d
  59. trn2 v30.2d, v30.2d, v29.2d
  60. trn1 v16.2d, v16.2d, v29.2d
  61. .else
  62. movi v16.4s, #0
  63. movi v28.4s, #0
  64. .endif
  65. mov x14, #4
  66. 1:
  67. mov x8, x0
  68. sub x7, x1, #3<<2
  69. sub x6, x1, x14, lsl #4
  70. add x7, x7, x14, lsl #4
  71. add x11, x6, #(32)<<2 // w + 32
  72. add x12, x7, #(32)<<2 // w2 + 32
  73. mov x15, #8
  74. movi v17.2d, #0
  75. movi v18.2d, #0
  76. movi v19.2d, #0
  77. 2:
  78. subs x15, x15, #1
  79. ld1 {v0.4s}, [x8], x9
  80. ld1 {v1.4s}, [x10], x9
  81. ld1 {v2.4s}, [x6], x9
  82. ld1 {v3.4s}, [x7], x9
  83. tbl v6.16b, {v0.16b}, v27.16b
  84. tbl v7.16b, {v1.16b}, v27.16b
  85. ld1 {v4.4s}, [x11], x9
  86. ld1 {v5.4s}, [x12], x9
  87. MLA v16, v2, v0
  88. MLA2 v17, v2, v0
  89. MLS v18, v3, v6
  90. MLS2 v19, v3, v6
  91. MLS v16, v4, v7
  92. MLS2 v17, v4, v7
  93. MLS v18, v5, v1
  94. MLS2 v19, v5, v1
  95. b.gt 2b
  96. cmp x14, #4
  97. sub x10, x10, #64<<5 // 64 * 8 * sizeof(int32_t)
  98. .ifc \type, fixed
  99. and v28.16b, v16.16b, v30.16b
  100. ext v28.16b, v29.16b, v28.16b, #8
  101. b.eq 4f
  102. round_sample v19, 1, 1
  103. 4:
  104. round_sample v16, 1, 0
  105. shrn v16.2s, v16.2d, #OUT_SHIFT
  106. round_sample v19, 0, 0
  107. shrn v19.2s, v19.2d, #OUT_SHIFT
  108. round_sample v17, 0, 1
  109. round_sample v18, 1, 1
  110. round_sample v17, 1, 0
  111. shrn2 v16.4s, v17.2d, #OUT_SHIFT
  112. round_sample v18, 0, 0
  113. shrn2 v19.4s, v18.2d, #OUT_SHIFT
  114. sqxtn v16.4h, v16.4s
  115. sqxtn v18.4h, v19.4s
  116. .else
  117. ext v18.16b, v18.16b, v18.16b, #8
  118. .endif
  119. st1 {v16.\st\()}[0], [x3], x4
  120. b.eq 4f
  121. st1 {v18.\st\()}[1], [x5], x13
  122. 4:
  123. st1 {v16.\st\()}[1], [x3], x4
  124. st1 {v18.\st\()}[0], [x5], x13
  125. st1 {v16.\st\()}[2], [x3], x4
  126. st1 {v18.\st\()}[3], [x5], x13
  127. st1 {v16.\st\()}[3], [x3], x4
  128. st1 {v18.\st\()}[2], [x5], x13
  129. mov v16.16b, v28.16b
  130. subs x14, x14, #1
  131. add x0, x0, #4<<2
  132. sub x10, x10, #4<<2
  133. b.gt 1b
  134. // comuting samples[16]
  135. add x6, x1, #32<<2
  136. ld1 {v0.2s}, [x6], x9
  137. ld1 {v1.2s}, [x0], x9
  138. .rept 3
  139. ld1 {v2.2s}, [x6], x9
  140. ld1 {v3.2s}, [x0], x9
  141. MLS v16, v0, v1
  142. ld1 {v0.2s}, [x6], x9
  143. ld1 {v1.2s}, [x0], x9
  144. MLS v16, v2, v3
  145. .endr
  146. ld1 {v2.2s}, [x6], x9
  147. ld1 {v3.2s}, [x0], x9
  148. MLS v16, v0, v1
  149. MLS v16, v2, v3
  150. .ifc \type, fixed
  151. and v28.16b, v16.16b, v30.16b
  152. shrn v20.2s, v16.2d, #OUT_SHIFT
  153. xtn v28.2s, v28.2d
  154. sqxtn v20.4h, v20.4s
  155. st1 {v28.s}[0], [x2] // save dither_state
  156. st1 {v20.h}[0], [x3]
  157. .else
  158. st1 {v16.s}[0], [x3]
  159. .endif
  160. ret
  161. endfunc
  162. .purgem round_sample
  163. .purgem MLA
  164. .purgem MLA2
  165. .purgem MLS
  166. .purgem MLS2
  167. .endm
  168. .macro round_sample r, idx, next
  169. add \r\().2d, \r\().2d, v28.2d
  170. .if \idx == 0
  171. and v28.16b, \r\().16b, v30.16b
  172. .else // \idx == 1
  173. and v28.16b, \r\().16b, v31.16b
  174. .endif
  175. .if \idx != \next
  176. .if \next == 0
  177. ext v28.16b, v28.16b, v29.16b, #8
  178. .else
  179. ext v28.16b, v29.16b, v28.16b, #8
  180. .endif
  181. .endif
  182. .endm
  183. .macro MLA d, s1, s2
  184. smlal \d\().2d, \s1\().2s, \s2\().2s
  185. .endm
  186. .macro MLA2 d, s1, s2
  187. smlal2 \d\().2d, \s1\().4s, \s2\().4s
  188. .endm
  189. .macro MLS d, s1, s2
  190. smlsl \d\().2d, \s1\().2s, \s2\().2s
  191. .endm
  192. .macro MLS2 d, s1, s2
  193. smlsl2 \d\().2d, \s1\().4s, \s2\().4s
  194. .endm
  195. apply_window fixed, h
  196. // nothing to do for round_sample and ML{A,S}2
  197. .macro round_sample r, idx, next
  198. .endm
  199. .macro MLA2 d, s1, s2
  200. .endm
  201. .macro MLS2 d, s1, s2
  202. .endm
  203. .macro MLA d, s1, s2
  204. fmla \d\().4s, \s1\().4s, \s2\().4s
  205. .endm
  206. .macro MLS d, s1, s2
  207. fmls \d\().4s, \s1\().4s, \s2\().4s
  208. .endm
  209. apply_window float, s