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.

249 lines
15KB

  1. /*
  2. * Copyright (c) 2012
  3. * MIPS Technologies, Inc., California.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
  14. * contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * Author: Bojan Zivkovic (bojan@mips.com)
  30. *
  31. * Compute antialias function optimised for MIPS fixed-point architecture
  32. *
  33. * This file is part of FFmpeg.
  34. *
  35. * FFmpeg is free software; you can redistribute it and/or
  36. * modify it under the terms of the GNU Lesser General Public
  37. * License as published by the Free Software Foundation; either
  38. * version 2.1 of the License, or (at your option) any later version.
  39. *
  40. * FFmpeg is distributed in the hope that it will be useful,
  41. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  43. * Lesser General Public License for more details.
  44. *
  45. * You should have received a copy of the GNU Lesser General Public
  46. * License along with FFmpeg; if not, write to the Free Software
  47. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  48. */
  49. /**
  50. * @file
  51. * Reference: libavcodec/mpegaudiodec.c
  52. */
  53. #ifndef AVCODEC_MIPS_COMPUTE_ANTIALIAS_FIXED_H
  54. #define AVCODEC_MIPS_COMPUTE_ANTIALIAS_FIXED_H
  55. #if HAVE_INLINE_ASM
  56. static void compute_antialias_mips_fixed(MPADecodeContext *s,
  57. GranuleDef *g)
  58. {
  59. int32_t *ptr, *csa;
  60. int n, i;
  61. int MAX_lo = 0xffffffff;
  62. /* we antialias only "long" bands */
  63. if (g->block_type == 2) {
  64. if (!g->switch_point)
  65. return;
  66. /* XXX: check this for 8000Hz case */
  67. n = 1;
  68. } else {
  69. n = SBLIMIT - 1;
  70. }
  71. ptr = g->sb_hybrid + 18;
  72. for(i = n;i > 0;i--) {
  73. int tmp0, tmp1, tmp2, tmp00, tmp11;
  74. int temp_reg1, temp_reg2, temp_reg3, temp_reg4, temp_reg5, temp_reg6;
  75. csa = &csa_table[0][0];
  76. /**
  77. * instructions are scheduled to minimize pipeline stall.
  78. */
  79. __asm__ volatile (
  80. "lw %[tmp0], -1*4(%[ptr]) \n\t"
  81. "lw %[tmp1], 0*4(%[ptr]) \n\t"
  82. "lw %[temp_reg1], 0*4(%[csa]) \n\t"
  83. "lw %[temp_reg2], 2*4(%[csa]) \n\t"
  84. "add %[tmp2], %[tmp0], %[tmp1] \n\t"
  85. "lw %[temp_reg3], 3*4(%[csa]) \n\t"
  86. "mult $ac0, %[tmp2], %[temp_reg1] \n\t"
  87. "mult $ac1, %[tmp2], %[temp_reg1] \n\t"
  88. "lw %[tmp00], -2*4(%[ptr]) \n\t"
  89. "lw %[tmp11], 1*4(%[ptr]) \n\t"
  90. "lw %[temp_reg4], 4*4(%[csa]) \n\t"
  91. "mtlo %[MAX_lo], $ac0 \n\t"
  92. "mtlo $zero, $ac1 \n\t"
  93. "msub $ac0, %[tmp1], %[temp_reg2] \n\t"
  94. "madd $ac1, %[tmp0], %[temp_reg3] \n\t"
  95. "add %[tmp2], %[tmp00], %[tmp11] \n\t"
  96. "lw %[temp_reg5], 6*4(%[csa]) \n\t"
  97. "mult $ac2, %[tmp2], %[temp_reg4] \n\t"
  98. "mult $ac3, %[tmp2], %[temp_reg4] \n\t"
  99. "mfhi %[temp_reg1], $ac0 \n\t"
  100. "mfhi %[temp_reg2], $ac1 \n\t"
  101. "lw %[temp_reg6], 7*4(%[csa]) \n\t"
  102. "mtlo %[MAX_lo], $ac2 \n\t"
  103. "msub $ac2, %[tmp11], %[temp_reg5] \n\t"
  104. "mtlo $zero, $ac3 \n\t"
  105. "madd $ac3, %[tmp00], %[temp_reg6] \n\t"
  106. "sll %[temp_reg1], %[temp_reg1], 2 \n\t"
  107. "sw %[temp_reg1], -1*4(%[ptr]) \n\t"
  108. "mfhi %[temp_reg4], $ac2 \n\t"
  109. "sll %[temp_reg2], %[temp_reg2], 2 \n\t"
  110. "mfhi %[temp_reg5], $ac3 \n\t"
  111. "sw %[temp_reg2], 0*4(%[ptr]) \n\t"
  112. "lw %[tmp0], -3*4(%[ptr]) \n\t"
  113. "lw %[tmp1], 2*4(%[ptr]) \n\t"
  114. "lw %[temp_reg1], 8*4(%[csa]) \n\t"
  115. "sll %[temp_reg4], %[temp_reg4], 2 \n\t"
  116. "add %[tmp2], %[tmp0], %[tmp1] \n\t"
  117. "sll %[temp_reg5], %[temp_reg5], 2 \n\t"
  118. "mult $ac0, %[tmp2], %[temp_reg1] \n\t"
  119. "mult $ac1, %[tmp2], %[temp_reg1] \n\t"
  120. "sw %[temp_reg4], -2*4(%[ptr]) \n\t"
  121. "sw %[temp_reg5], 1*4(%[ptr]) \n\t"
  122. "lw %[temp_reg2], 10*4(%[csa]) \n\t"
  123. "mtlo %[MAX_lo], $ac0 \n\t"
  124. "lw %[temp_reg3], 11*4(%[csa]) \n\t"
  125. "msub $ac0, %[tmp1], %[temp_reg2] \n\t"
  126. "mtlo $zero, $ac1 \n\t"
  127. "madd $ac1, %[tmp0], %[temp_reg3] \n\t"
  128. "lw %[tmp00], -4*4(%[ptr]) \n\t"
  129. "lw %[tmp11], 3*4(%[ptr]) \n\t"
  130. "mfhi %[temp_reg1], $ac0 \n\t"
  131. "lw %[temp_reg4], 12*4(%[csa]) \n\t"
  132. "mfhi %[temp_reg2], $ac1 \n\t"
  133. "add %[tmp2], %[tmp00], %[tmp11] \n\t"
  134. "mult $ac2, %[tmp2], %[temp_reg4] \n\t"
  135. "mult $ac3, %[tmp2], %[temp_reg4] \n\t"
  136. "lw %[temp_reg5], 14*4(%[csa]) \n\t"
  137. "lw %[temp_reg6], 15*4(%[csa]) \n\t"
  138. "sll %[temp_reg1], %[temp_reg1], 2 \n\t"
  139. "mtlo %[MAX_lo], $ac2 \n\t"
  140. "msub $ac2, %[tmp11], %[temp_reg5] \n\t"
  141. "mtlo $zero, $ac3 \n\t"
  142. "madd $ac3, %[tmp00], %[temp_reg6] \n\t"
  143. "sll %[temp_reg2], %[temp_reg2], 2 \n\t"
  144. "sw %[temp_reg1], -3*4(%[ptr]) \n\t"
  145. "mfhi %[temp_reg4], $ac2 \n\t"
  146. "sw %[temp_reg2], 2*4(%[ptr]) \n\t"
  147. "mfhi %[temp_reg5], $ac3 \n\t"
  148. "lw %[tmp0], -5*4(%[ptr]) \n\t"
  149. "lw %[tmp1], 4*4(%[ptr]) \n\t"
  150. "lw %[temp_reg1], 16*4(%[csa]) \n\t"
  151. "lw %[temp_reg2], 18*4(%[csa]) \n\t"
  152. "add %[tmp2], %[tmp0], %[tmp1] \n\t"
  153. "lw %[temp_reg3], 19*4(%[csa]) \n\t"
  154. "mult $ac0, %[tmp2], %[temp_reg1] \n\t"
  155. "mult $ac1, %[tmp2], %[temp_reg1] \n\t"
  156. "sll %[temp_reg4], %[temp_reg4], 2 \n\t"
  157. "sll %[temp_reg5], %[temp_reg5], 2 \n\t"
  158. "sw %[temp_reg4], -4*4(%[ptr]) \n\t"
  159. "mtlo %[MAX_lo], $ac0 \n\t"
  160. "msub $ac0, %[tmp1], %[temp_reg2] \n\t"
  161. "mtlo $zero, $ac1 \n\t"
  162. "madd $ac1, %[tmp0], %[temp_reg3] \n\t"
  163. "sw %[temp_reg5], 3*4(%[ptr]) \n\t"
  164. "lw %[tmp00], -6*4(%[ptr]) \n\t"
  165. "mfhi %[temp_reg1], $ac0 \n\t"
  166. "lw %[tmp11], 5*4(%[ptr]) \n\t"
  167. "mfhi %[temp_reg2], $ac1 \n\t"
  168. "lw %[temp_reg4], 20*4(%[csa]) \n\t"
  169. "add %[tmp2], %[tmp00], %[tmp11] \n\t"
  170. "lw %[temp_reg5], 22*4(%[csa]) \n\t"
  171. "mult $ac2, %[tmp2], %[temp_reg4] \n\t"
  172. "mult $ac3, %[tmp2], %[temp_reg4] \n\t"
  173. "lw %[temp_reg6], 23*4(%[csa]) \n\t"
  174. "sll %[temp_reg1], %[temp_reg1], 2 \n\t"
  175. "sll %[temp_reg2], %[temp_reg2], 2 \n\t"
  176. "mtlo %[MAX_lo], $ac2 \n\t"
  177. "msub $ac2, %[tmp11], %[temp_reg5] \n\t"
  178. "mtlo $zero, $ac3 \n\t"
  179. "madd $ac3, %[tmp00], %[temp_reg6] \n\t"
  180. "sw %[temp_reg1], -5*4(%[ptr]) \n\t"
  181. "sw %[temp_reg2], 4*4(%[ptr]) \n\t"
  182. "mfhi %[temp_reg4], $ac2 \n\t"
  183. "lw %[tmp0], -7*4(%[ptr]) \n\t"
  184. "mfhi %[temp_reg5], $ac3 \n\t"
  185. "lw %[tmp1], 6*4(%[ptr]) \n\t"
  186. "lw %[temp_reg1], 24*4(%[csa]) \n\t"
  187. "lw %[temp_reg2], 26*4(%[csa]) \n\t"
  188. "add %[tmp2], %[tmp0], %[tmp1] \n\t"
  189. "lw %[temp_reg3], 27*4(%[csa]) \n\t"
  190. "mult $ac0, %[tmp2], %[temp_reg1] \n\t"
  191. "mult $ac1, %[tmp2], %[temp_reg1] \n\t"
  192. "sll %[temp_reg4], %[temp_reg4], 2 \n\t"
  193. "sll %[temp_reg5], %[temp_reg5], 2 \n\t"
  194. "sw %[temp_reg4], -6*4(%[ptr]) \n\t"
  195. "mtlo %[MAX_lo], $ac0 \n\t"
  196. "msub $ac0, %[tmp1], %[temp_reg2] \n\t"
  197. "mtlo $zero, $ac1 \n\t"
  198. "madd $ac1, %[tmp0], %[temp_reg3] \n\t"
  199. "sw %[temp_reg5], 5*4(%[ptr]) \n\t"
  200. "lw %[tmp00], -8*4(%[ptr]) \n\t"
  201. "mfhi %[temp_reg1], $ac0 \n\t"
  202. "lw %[tmp11], 7*4(%[ptr]) \n\t"
  203. "mfhi %[temp_reg2], $ac1 \n\t"
  204. "lw %[temp_reg4], 28*4(%[csa]) \n\t"
  205. "add %[tmp2], %[tmp00], %[tmp11] \n\t"
  206. "lw %[temp_reg5], 30*4(%[csa]) \n\t"
  207. "mult $ac2, %[tmp2], %[temp_reg4] \n\t"
  208. "mult $ac3, %[tmp2], %[temp_reg4] \n\t"
  209. "lw %[temp_reg6], 31*4(%[csa]) \n\t"
  210. "sll %[temp_reg1], %[temp_reg1], 2 \n\t"
  211. "sll %[temp_reg2], %[temp_reg2], 2 \n\t"
  212. "mtlo %[MAX_lo], $ac2 \n\t"
  213. "msub $ac2, %[tmp11], %[temp_reg5] \n\t"
  214. "mtlo $zero, $ac3 \n\t"
  215. "madd $ac3, %[tmp00], %[temp_reg6] \n\t"
  216. "sw %[temp_reg1], -7*4(%[ptr]) \n\t"
  217. "sw %[temp_reg2], 6*4(%[ptr]) \n\t"
  218. "mfhi %[temp_reg4], $ac2 \n\t"
  219. "mfhi %[temp_reg5], $ac3 \n\t"
  220. "sll %[temp_reg4], %[temp_reg4], 2 \n\t"
  221. "sll %[temp_reg5], %[temp_reg5], 2 \n\t"
  222. "sw %[temp_reg4], -8*4(%[ptr]) \n\t"
  223. "sw %[temp_reg5], 7*4(%[ptr]) \n\t"
  224. : [tmp0] "=&r" (tmp0), [tmp1] "=&r" (tmp1), [tmp2] "=&r" (tmp2),
  225. [tmp00] "=&r" (tmp00), [tmp11] "=&r" (tmp11),
  226. [temp_reg1] "=&r" (temp_reg1), [temp_reg2] "=&r" (temp_reg2),
  227. [temp_reg3] "=&r" (temp_reg3), [temp_reg4] "=&r" (temp_reg4),
  228. [temp_reg5] "=&r" (temp_reg5), [temp_reg6] "=&r" (temp_reg6)
  229. : [csa] "r" (csa), [ptr] "r" (ptr),
  230. [MAX_lo] "r" (MAX_lo)
  231. );
  232. ptr += 18;
  233. }
  234. }
  235. #define compute_antialias compute_antialias_mips_fixed
  236. #endif /* HAVE_INLINE_ASM */
  237. #endif /* AVCODEC_MIPS_COMPUTE_ANTIALIAS_FIXED_H */