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.

183 lines
6.2KB

  1. /*
  2. * MLP DSP functions x86-optimized
  3. * Copyright (c) 2009 Ramiro Polla
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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/x86/asm.h"
  23. #include "libavcodec/mlpdsp.h"
  24. #include "libavcodec/mlp.h"
  25. #if HAVE_7REGS && HAVE_INLINE_ASM
  26. extern char ff_mlp_firorder_8;
  27. extern char ff_mlp_firorder_7;
  28. extern char ff_mlp_firorder_6;
  29. extern char ff_mlp_firorder_5;
  30. extern char ff_mlp_firorder_4;
  31. extern char ff_mlp_firorder_3;
  32. extern char ff_mlp_firorder_2;
  33. extern char ff_mlp_firorder_1;
  34. extern char ff_mlp_firorder_0;
  35. extern char ff_mlp_iirorder_4;
  36. extern char ff_mlp_iirorder_3;
  37. extern char ff_mlp_iirorder_2;
  38. extern char ff_mlp_iirorder_1;
  39. extern char ff_mlp_iirorder_0;
  40. static const void *firtable[9] = { &ff_mlp_firorder_0, &ff_mlp_firorder_1,
  41. &ff_mlp_firorder_2, &ff_mlp_firorder_3,
  42. &ff_mlp_firorder_4, &ff_mlp_firorder_5,
  43. &ff_mlp_firorder_6, &ff_mlp_firorder_7,
  44. &ff_mlp_firorder_8 };
  45. static const void *iirtable[5] = { &ff_mlp_iirorder_0, &ff_mlp_iirorder_1,
  46. &ff_mlp_iirorder_2, &ff_mlp_iirorder_3,
  47. &ff_mlp_iirorder_4 };
  48. #if ARCH_X86_64
  49. #define MLPMUL(label, offset, offs, offc) \
  50. LABEL_MANGLE(label)": \n\t" \
  51. "movslq "offset"+"offs"(%0), %%rax\n\t" \
  52. "movslq "offset"+"offc"(%1), %%rdx\n\t" \
  53. "imul %%rdx, %%rax\n\t" \
  54. "add %%rax, %%rsi\n\t"
  55. #define FIRMULREG(label, offset, firc)\
  56. LABEL_MANGLE(label)": \n\t" \
  57. "movslq "#offset"(%0), %%rax\n\t" \
  58. "imul %"#firc", %%rax\n\t" \
  59. "add %%rax, %%rsi\n\t"
  60. #define CLEAR_ACCUM \
  61. "xor %%rsi, %%rsi\n\t"
  62. #define SHIFT_ACCUM \
  63. "shr %%cl, %%rsi\n\t"
  64. #define ACCUM "%%rdx"
  65. #define RESULT "%%rsi"
  66. #define RESULT32 "%%esi"
  67. #else /* if ARCH_X86_32 */
  68. #define MLPMUL(label, offset, offs, offc) \
  69. LABEL_MANGLE(label)": \n\t" \
  70. "mov "offset"+"offs"(%0), %%eax\n\t" \
  71. "imull "offset"+"offc"(%1) \n\t" \
  72. "add %%eax , %%esi\n\t" \
  73. "adc %%edx , %%ecx\n\t"
  74. #define FIRMULREG(label, offset, firc) \
  75. MLPMUL(label, #offset, "0", "0")
  76. #define CLEAR_ACCUM \
  77. "xor %%esi, %%esi\n\t" \
  78. "xor %%ecx, %%ecx\n\t"
  79. #define SHIFT_ACCUM \
  80. "mov %%ecx, %%edx\n\t" \
  81. "mov %%esi, %%eax\n\t" \
  82. "movzbl %7 , %%ecx\n\t" \
  83. "shrd %%cl, %%edx, %%eax\n\t" \
  84. #define ACCUM "%%edx"
  85. #define RESULT "%%eax"
  86. #define RESULT32 "%%eax"
  87. #endif /* !ARCH_X86_64 */
  88. #define BINC AV_STRINGIFY(4* MAX_CHANNELS)
  89. #define IOFFS AV_STRINGIFY(4*(MAX_FIR_ORDER + MAX_BLOCKSIZE))
  90. #define IOFFC AV_STRINGIFY(4* MAX_FIR_ORDER)
  91. #define FIRMUL(label, offset) MLPMUL(label, #offset, "0", "0")
  92. #define IIRMUL(label, offset) MLPMUL(label, #offset, IOFFS, IOFFC)
  93. static void mlp_filter_channel_x86(int32_t *state, const int32_t *coeff,
  94. int firorder, int iirorder,
  95. unsigned int filter_shift, int32_t mask,
  96. int blocksize, int32_t *sample_buffer)
  97. {
  98. const void *firjump = firtable[firorder];
  99. const void *iirjump = iirtable[iirorder];
  100. blocksize = -blocksize;
  101. __asm__ volatile(
  102. "1: \n\t"
  103. CLEAR_ACCUM
  104. "jmp *%5 \n\t"
  105. FIRMUL (ff_mlp_firorder_8, 0x1c )
  106. FIRMUL (ff_mlp_firorder_7, 0x18 )
  107. FIRMUL (ff_mlp_firorder_6, 0x14 )
  108. FIRMUL (ff_mlp_firorder_5, 0x10 )
  109. FIRMUL (ff_mlp_firorder_4, 0x0c )
  110. FIRMULREG(ff_mlp_firorder_3, 0x08,10)
  111. FIRMULREG(ff_mlp_firorder_2, 0x04, 9)
  112. FIRMULREG(ff_mlp_firorder_1, 0x00, 8)
  113. LABEL_MANGLE(ff_mlp_firorder_0)":\n\t"
  114. "jmp *%6 \n\t"
  115. IIRMUL (ff_mlp_iirorder_4, 0x0c )
  116. IIRMUL (ff_mlp_iirorder_3, 0x08 )
  117. IIRMUL (ff_mlp_iirorder_2, 0x04 )
  118. IIRMUL (ff_mlp_iirorder_1, 0x00 )
  119. LABEL_MANGLE(ff_mlp_iirorder_0)":\n\t"
  120. SHIFT_ACCUM
  121. "mov "RESULT" ,"ACCUM" \n\t"
  122. "add (%2) ,"RESULT" \n\t"
  123. "and %4 ,"RESULT" \n\t"
  124. "sub $4 , %0 \n\t"
  125. "mov "RESULT32", (%0) \n\t"
  126. "mov "RESULT32", (%2) \n\t"
  127. "add $"BINC" , %2 \n\t"
  128. "sub "ACCUM" ,"RESULT" \n\t"
  129. "mov "RESULT32","IOFFS"(%0) \n\t"
  130. "incl %3 \n\t"
  131. "js 1b \n\t"
  132. : /* 0*/"+r"(state),
  133. /* 1*/"+r"(coeff),
  134. /* 2*/"+r"(sample_buffer),
  135. #if ARCH_X86_64
  136. /* 3*/"+r"(blocksize)
  137. : /* 4*/"r"((x86_reg)mask), /* 5*/"r"(firjump),
  138. /* 6*/"r"(iirjump) , /* 7*/"c"(filter_shift)
  139. , /* 8*/"r"((int64_t)coeff[0])
  140. , /* 9*/"r"((int64_t)coeff[1])
  141. , /*10*/"r"((int64_t)coeff[2])
  142. : "rax", "rdx", "rsi"
  143. #else /* ARCH_X86_32 */
  144. /* 3*/"+m"(blocksize)
  145. : /* 4*/"m"( mask), /* 5*/"m"(firjump),
  146. /* 6*/"m"(iirjump) , /* 7*/"m"(filter_shift)
  147. : "eax", "edx", "esi", "ecx"
  148. #endif /* !ARCH_X86_64 */
  149. );
  150. }
  151. #endif /* HAVE_7REGS && HAVE_INLINE_ASM */
  152. av_cold void ff_mlpdsp_init_x86(MLPDSPContext *c)
  153. {
  154. #if HAVE_7REGS && HAVE_INLINE_ASM
  155. c->mlp_filter_channel = mlp_filter_channel_x86;
  156. #endif
  157. }