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.

188 lines
6.4KB

  1. /*
  2. * MLP DSP functions x86-optimized
  3. * Copyright (c) 2009 Ramiro Polla
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/attributes.h"
  22. #include "libavutil/internal.h"
  23. #include "libavutil/cpu.h"
  24. #include "libavutil/x86/asm.h"
  25. #include "libavutil/x86/cpu.h"
  26. #include "libavcodec/mlpdsp.h"
  27. #include "libavcodec/mlp.h"
  28. #if HAVE_7REGS && HAVE_INLINE_ASM
  29. extern char ff_mlp_firorder_8;
  30. extern char ff_mlp_firorder_7;
  31. extern char ff_mlp_firorder_6;
  32. extern char ff_mlp_firorder_5;
  33. extern char ff_mlp_firorder_4;
  34. extern char ff_mlp_firorder_3;
  35. extern char ff_mlp_firorder_2;
  36. extern char ff_mlp_firorder_1;
  37. extern char ff_mlp_firorder_0;
  38. extern char ff_mlp_iirorder_4;
  39. extern char ff_mlp_iirorder_3;
  40. extern char ff_mlp_iirorder_2;
  41. extern char ff_mlp_iirorder_1;
  42. extern char ff_mlp_iirorder_0;
  43. static const void * const firtable[9] = { &ff_mlp_firorder_0, &ff_mlp_firorder_1,
  44. &ff_mlp_firorder_2, &ff_mlp_firorder_3,
  45. &ff_mlp_firorder_4, &ff_mlp_firorder_5,
  46. &ff_mlp_firorder_6, &ff_mlp_firorder_7,
  47. &ff_mlp_firorder_8 };
  48. static const void * const iirtable[5] = { &ff_mlp_iirorder_0, &ff_mlp_iirorder_1,
  49. &ff_mlp_iirorder_2, &ff_mlp_iirorder_3,
  50. &ff_mlp_iirorder_4 };
  51. #if ARCH_X86_64
  52. #define MLPMUL(label, offset, offs, offc) \
  53. LABEL_MANGLE(label)": \n\t" \
  54. "movslq "offset"+"offs"(%0), %%rax\n\t" \
  55. "movslq "offset"+"offc"(%1), %%rdx\n\t" \
  56. "imul %%rdx, %%rax\n\t" \
  57. "add %%rax, %%rsi\n\t"
  58. #define FIRMULREG(label, offset, firc)\
  59. LABEL_MANGLE(label)": \n\t" \
  60. "movslq "#offset"(%0), %%rax\n\t" \
  61. "imul %"#firc", %%rax\n\t" \
  62. "add %%rax, %%rsi\n\t"
  63. #define CLEAR_ACCUM \
  64. "xor %%rsi, %%rsi\n\t"
  65. #define SHIFT_ACCUM \
  66. "shr %%cl, %%rsi\n\t"
  67. #define ACCUM "%%rdx"
  68. #define RESULT "%%rsi"
  69. #define RESULT32 "%%esi"
  70. #else /* if ARCH_X86_32 */
  71. #define MLPMUL(label, offset, offs, offc) \
  72. LABEL_MANGLE(label)": \n\t" \
  73. "mov "offset"+"offs"(%0), %%eax\n\t" \
  74. "imull "offset"+"offc"(%1) \n\t" \
  75. "add %%eax , %%esi\n\t" \
  76. "adc %%edx , %%ecx\n\t"
  77. #define FIRMULREG(label, offset, firc) \
  78. MLPMUL(label, #offset, "0", "0")
  79. #define CLEAR_ACCUM \
  80. "xor %%esi, %%esi\n\t" \
  81. "xor %%ecx, %%ecx\n\t"
  82. #define SHIFT_ACCUM \
  83. "mov %%ecx, %%edx\n\t" \
  84. "mov %%esi, %%eax\n\t" \
  85. "movzbl %7 , %%ecx\n\t" \
  86. "shrd %%cl, %%edx, %%eax\n\t" \
  87. #define ACCUM "%%edx"
  88. #define RESULT "%%eax"
  89. #define RESULT32 "%%eax"
  90. #endif /* !ARCH_X86_64 */
  91. #define BINC AV_STRINGIFY(4* MAX_CHANNELS)
  92. #define IOFFS AV_STRINGIFY(4*(MAX_FIR_ORDER + MAX_BLOCKSIZE))
  93. #define IOFFC AV_STRINGIFY(4* MAX_FIR_ORDER)
  94. #define FIRMUL(label, offset) MLPMUL(label, #offset, "0", "0")
  95. #define IIRMUL(label, offset) MLPMUL(label, #offset, IOFFS, IOFFC)
  96. static void mlp_filter_channel_x86(int32_t *state, const int32_t *coeff,
  97. int firorder, int iirorder,
  98. unsigned int filter_shift, int32_t mask,
  99. int blocksize, int32_t *sample_buffer)
  100. {
  101. const void *firjump = firtable[firorder];
  102. const void *iirjump = iirtable[iirorder];
  103. blocksize = -blocksize;
  104. __asm__ volatile(
  105. "1: \n\t"
  106. CLEAR_ACCUM
  107. "jmp *%5 \n\t"
  108. FIRMUL (ff_mlp_firorder_8, 0x1c )
  109. FIRMUL (ff_mlp_firorder_7, 0x18 )
  110. FIRMUL (ff_mlp_firorder_6, 0x14 )
  111. FIRMUL (ff_mlp_firorder_5, 0x10 )
  112. FIRMUL (ff_mlp_firorder_4, 0x0c )
  113. FIRMULREG(ff_mlp_firorder_3, 0x08,10)
  114. FIRMULREG(ff_mlp_firorder_2, 0x04, 9)
  115. FIRMULREG(ff_mlp_firorder_1, 0x00, 8)
  116. LABEL_MANGLE(ff_mlp_firorder_0)":\n\t"
  117. "jmp *%6 \n\t"
  118. IIRMUL (ff_mlp_iirorder_4, 0x0c )
  119. IIRMUL (ff_mlp_iirorder_3, 0x08 )
  120. IIRMUL (ff_mlp_iirorder_2, 0x04 )
  121. IIRMUL (ff_mlp_iirorder_1, 0x00 )
  122. LABEL_MANGLE(ff_mlp_iirorder_0)":\n\t"
  123. SHIFT_ACCUM
  124. "mov "RESULT" ,"ACCUM" \n\t"
  125. "add (%2) ,"RESULT" \n\t"
  126. "and %4 ,"RESULT" \n\t"
  127. "sub $4 , %0 \n\t"
  128. "mov "RESULT32", (%0) \n\t"
  129. "mov "RESULT32", (%2) \n\t"
  130. "add $"BINC" , %2 \n\t"
  131. "sub "ACCUM" ,"RESULT" \n\t"
  132. "mov "RESULT32","IOFFS"(%0) \n\t"
  133. "incl %3 \n\t"
  134. "js 1b \n\t"
  135. : /* 0*/"+r"(state),
  136. /* 1*/"+r"(coeff),
  137. /* 2*/"+r"(sample_buffer),
  138. #if ARCH_X86_64
  139. /* 3*/"+r"(blocksize)
  140. : /* 4*/"r"((x86_reg)mask), /* 5*/"r"(firjump),
  141. /* 6*/"r"(iirjump) , /* 7*/"c"(filter_shift)
  142. , /* 8*/"r"((int64_t)coeff[0])
  143. , /* 9*/"r"((int64_t)coeff[1])
  144. , /*10*/"r"((int64_t)coeff[2])
  145. : "rax", "rdx", "rsi"
  146. #else /* ARCH_X86_32 */
  147. /* 3*/"+m"(blocksize)
  148. : /* 4*/"m"( mask), /* 5*/"m"(firjump),
  149. /* 6*/"m"(iirjump) , /* 7*/"m"(filter_shift)
  150. : "eax", "edx", "esi", "ecx"
  151. #endif /* !ARCH_X86_64 */
  152. );
  153. }
  154. #endif /* HAVE_7REGS && HAVE_INLINE_ASM */
  155. av_cold void ff_mlpdsp_init_x86(MLPDSPContext *c)
  156. {
  157. #if HAVE_7REGS && HAVE_INLINE_ASM
  158. int cpu_flags = av_get_cpu_flags();
  159. if (INLINE_MMX(cpu_flags))
  160. c->mlp_filter_channel = mlp_filter_channel_x86;
  161. #endif
  162. }