aacdec_mips.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. * Authors: Darko Laus (darko@mips.com)
  30. * Djordje Pesut (djordje@mips.com)
  31. * Mirjana Vulin (mvulin@mips.com)
  32. *
  33. * AAC Spectral Band Replication decoding functions optimized for MIPS
  34. *
  35. * This file is part of FFmpeg.
  36. *
  37. * FFmpeg is free software; you can redistribute it and/or
  38. * modify it under the terms of the GNU Lesser General Public
  39. * License as published by the Free Software Foundation; either
  40. * version 2.1 of the License, or (at your option) any later version.
  41. *
  42. * FFmpeg is distributed in the hope that it will be useful,
  43. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  44. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  45. * Lesser General Public License for more details.
  46. *
  47. * You should have received a copy of the GNU Lesser General Public
  48. * License along with FFmpeg; if not, write to the Free Software
  49. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  50. */
  51. /**
  52. * @file
  53. * Reference: libavcodec/aacdec.c
  54. */
  55. #ifndef AVCODEC_MIPS_AACDEC_MIPS_H
  56. #define AVCODEC_MIPS_AACDEC_MIPS_H
  57. #include "libavcodec/aac.h"
  58. #include "libavutil/mips/asmdefs.h"
  59. #if HAVE_INLINE_ASM && HAVE_MIPSFPU
  60. #if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
  61. static inline float *VMUL2_mips(float *dst, const float *v, unsigned idx,
  62. const float *scale)
  63. {
  64. float temp0, temp1, temp2;
  65. int temp3, temp4;
  66. float *ret;
  67. __asm__ volatile(
  68. "andi %[temp3], %[idx], 0x0F \n\t"
  69. "andi %[temp4], %[idx], 0xF0 \n\t"
  70. "sll %[temp3], %[temp3], 2 \n\t"
  71. "srl %[temp4], %[temp4], 2 \n\t"
  72. "lwc1 %[temp2], 0(%[scale]) \n\t"
  73. "lwxc1 %[temp0], %[temp3](%[v]) \n\t"
  74. "lwxc1 %[temp1], %[temp4](%[v]) \n\t"
  75. "mul.s %[temp0], %[temp0], %[temp2] \n\t"
  76. "mul.s %[temp1], %[temp1], %[temp2] \n\t"
  77. PTR_ADDIU "%[ret], %[dst], 8 \n\t"
  78. "swc1 %[temp0], 0(%[dst]) \n\t"
  79. "swc1 %[temp1], 4(%[dst]) \n\t"
  80. : [temp0]"=&f"(temp0), [temp1]"=&f"(temp1),
  81. [temp2]"=&f"(temp2), [temp3]"=&r"(temp3),
  82. [temp4]"=&r"(temp4), [ret]"=&r"(ret)
  83. : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v),
  84. [dst]"r"(dst)
  85. : "memory"
  86. );
  87. return ret;
  88. }
  89. static inline float *VMUL4_mips(float *dst, const float *v, unsigned idx,
  90. const float *scale)
  91. {
  92. int temp0, temp1, temp2, temp3;
  93. float temp4, temp5, temp6, temp7, temp8;
  94. float *ret;
  95. __asm__ volatile(
  96. "andi %[temp0], %[idx], 0x03 \n\t"
  97. "andi %[temp1], %[idx], 0x0C \n\t"
  98. "andi %[temp2], %[idx], 0x30 \n\t"
  99. "andi %[temp3], %[idx], 0xC0 \n\t"
  100. "sll %[temp0], %[temp0], 2 \n\t"
  101. "srl %[temp2], %[temp2], 2 \n\t"
  102. "srl %[temp3], %[temp3], 4 \n\t"
  103. "lwc1 %[temp4], 0(%[scale]) \n\t"
  104. "lwxc1 %[temp5], %[temp0](%[v]) \n\t"
  105. "lwxc1 %[temp6], %[temp1](%[v]) \n\t"
  106. "lwxc1 %[temp7], %[temp2](%[v]) \n\t"
  107. "lwxc1 %[temp8], %[temp3](%[v]) \n\t"
  108. "mul.s %[temp5], %[temp5], %[temp4] \n\t"
  109. "mul.s %[temp6], %[temp6], %[temp4] \n\t"
  110. "mul.s %[temp7], %[temp7], %[temp4] \n\t"
  111. "mul.s %[temp8], %[temp8], %[temp4] \n\t"
  112. PTR_ADDIU "%[ret], %[dst], 16 \n\t"
  113. "swc1 %[temp5], 0(%[dst]) \n\t"
  114. "swc1 %[temp6], 4(%[dst]) \n\t"
  115. "swc1 %[temp7], 8(%[dst]) \n\t"
  116. "swc1 %[temp8], 12(%[dst]) \n\t"
  117. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1),
  118. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3),
  119. [temp4]"=&f"(temp4), [temp5]"=&f"(temp5),
  120. [temp6]"=&f"(temp6), [temp7]"=&f"(temp7),
  121. [temp8]"=&f"(temp8), [ret]"=&r"(ret)
  122. : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v),
  123. [dst]"r"(dst)
  124. : "memory"
  125. );
  126. return ret;
  127. }
  128. static inline float *VMUL2S_mips(float *dst, const float *v, unsigned idx,
  129. unsigned sign, const float *scale)
  130. {
  131. int temp0, temp1, temp2, temp3, temp4, temp5;
  132. float temp6, temp7, temp8, temp9;
  133. float *ret;
  134. __asm__ volatile(
  135. "andi %[temp0], %[idx], 0x0F \n\t"
  136. "andi %[temp1], %[idx], 0xF0 \n\t"
  137. "lw %[temp4], 0(%[scale]) \n\t"
  138. "srl %[temp2], %[sign], 1 \n\t"
  139. "sll %[temp3], %[sign], 31 \n\t"
  140. "sll %[temp2], %[temp2], 31 \n\t"
  141. "sll %[temp0], %[temp0], 2 \n\t"
  142. "srl %[temp1], %[temp1], 2 \n\t"
  143. "lwxc1 %[temp8], %[temp0](%[v]) \n\t"
  144. "lwxc1 %[temp9], %[temp1](%[v]) \n\t"
  145. "xor %[temp5], %[temp4], %[temp2] \n\t"
  146. "xor %[temp4], %[temp4], %[temp3] \n\t"
  147. "mtc1 %[temp5], %[temp6] \n\t"
  148. "mtc1 %[temp4], %[temp7] \n\t"
  149. "mul.s %[temp8], %[temp8], %[temp6] \n\t"
  150. "mul.s %[temp9], %[temp9], %[temp7] \n\t"
  151. PTR_ADDIU "%[ret], %[dst], 8 \n\t"
  152. "swc1 %[temp8], 0(%[dst]) \n\t"
  153. "swc1 %[temp9], 4(%[dst]) \n\t"
  154. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1),
  155. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3),
  156. [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  157. [temp6]"=&f"(temp6), [temp7]"=&f"(temp7),
  158. [temp8]"=&f"(temp8), [temp9]"=&f"(temp9),
  159. [ret]"=&r"(ret)
  160. : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v),
  161. [dst]"r"(dst), [sign]"r"(sign)
  162. : "memory"
  163. );
  164. return ret;
  165. }
  166. static inline float *VMUL4S_mips(float *dst, const float *v, unsigned idx,
  167. unsigned sign, const float *scale)
  168. {
  169. int temp0, temp1, temp2, temp3, temp4;
  170. float temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17;
  171. float *ret;
  172. unsigned int mask = 1U << 31;
  173. __asm__ volatile(
  174. "lw %[temp0], 0(%[scale]) \n\t"
  175. "andi %[temp1], %[idx], 0x03 \n\t"
  176. "andi %[temp2], %[idx], 0x0C \n\t"
  177. "andi %[temp3], %[idx], 0x30 \n\t"
  178. "andi %[temp4], %[idx], 0xC0 \n\t"
  179. "sll %[temp1], %[temp1], 2 \n\t"
  180. "srl %[temp3], %[temp3], 2 \n\t"
  181. "srl %[temp4], %[temp4], 4 \n\t"
  182. "lwxc1 %[temp10], %[temp1](%[v]) \n\t"
  183. "lwxc1 %[temp11], %[temp2](%[v]) \n\t"
  184. "lwxc1 %[temp12], %[temp3](%[v]) \n\t"
  185. "lwxc1 %[temp13], %[temp4](%[v]) \n\t"
  186. "and %[temp1], %[sign], %[mask] \n\t"
  187. "srl %[temp2], %[idx], 12 \n\t"
  188. "srl %[temp3], %[idx], 13 \n\t"
  189. "srl %[temp4], %[idx], 14 \n\t"
  190. "andi %[temp2], %[temp2], 1 \n\t"
  191. "andi %[temp3], %[temp3], 1 \n\t"
  192. "andi %[temp4], %[temp4], 1 \n\t"
  193. "sllv %[sign], %[sign], %[temp2] \n\t"
  194. "xor %[temp1], %[temp0], %[temp1] \n\t"
  195. "and %[temp2], %[sign], %[mask] \n\t"
  196. "mtc1 %[temp1], %[temp14] \n\t"
  197. "xor %[temp2], %[temp0], %[temp2] \n\t"
  198. "sllv %[sign], %[sign], %[temp3] \n\t"
  199. "mtc1 %[temp2], %[temp15] \n\t"
  200. "and %[temp3], %[sign], %[mask] \n\t"
  201. "sllv %[sign], %[sign], %[temp4] \n\t"
  202. "xor %[temp3], %[temp0], %[temp3] \n\t"
  203. "and %[temp4], %[sign], %[mask] \n\t"
  204. "mtc1 %[temp3], %[temp16] \n\t"
  205. "xor %[temp4], %[temp0], %[temp4] \n\t"
  206. "mtc1 %[temp4], %[temp17] \n\t"
  207. "mul.s %[temp10], %[temp10], %[temp14] \n\t"
  208. "mul.s %[temp11], %[temp11], %[temp15] \n\t"
  209. "mul.s %[temp12], %[temp12], %[temp16] \n\t"
  210. "mul.s %[temp13], %[temp13], %[temp17] \n\t"
  211. PTR_ADDIU "%[ret], %[dst], 16 \n\t"
  212. "swc1 %[temp10], 0(%[dst]) \n\t"
  213. "swc1 %[temp11], 4(%[dst]) \n\t"
  214. "swc1 %[temp12], 8(%[dst]) \n\t"
  215. "swc1 %[temp13], 12(%[dst]) \n\t"
  216. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1),
  217. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3),
  218. [temp4]"=&r"(temp4), [temp10]"=&f"(temp10),
  219. [temp11]"=&f"(temp11), [temp12]"=&f"(temp12),
  220. [temp13]"=&f"(temp13), [temp14]"=&f"(temp14),
  221. [temp15]"=&f"(temp15), [temp16]"=&f"(temp16),
  222. [temp17]"=&f"(temp17), [ret]"=&r"(ret),
  223. [sign]"+r"(sign)
  224. : [idx]"r"(idx), [scale]"r"(scale), [v]"r"(v),
  225. [dst]"r"(dst), [mask]"r"(mask)
  226. : "memory"
  227. );
  228. return ret;
  229. }
  230. #define VMUL2 VMUL2_mips
  231. #define VMUL4 VMUL4_mips
  232. #define VMUL2S VMUL2S_mips
  233. #define VMUL4S VMUL4S_mips
  234. #endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
  235. #endif /* HAVE_INLINE_ASM && HAVE_MIPSFPU */
  236. #endif /* AVCODEC_MIPS_AACDEC_MIPS_H */