2
0

rematrix_init.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2012 Michael Niedermayer (michaelni@gmx.at)
  3. *
  4. * This file is part of libswresample
  5. *
  6. * libswresample 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. * libswresample 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 libswresample; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/x86/cpu.h"
  21. #include "libswresample/swresample_internal.h"
  22. #define D(type, simd) \
  23. mix_1_1_func_type ff_mix_1_1_a_## type ## _ ## simd;\
  24. mix_2_1_func_type ff_mix_2_1_a_## type ## _ ## simd;
  25. D(float, sse)
  26. D(float, avx)
  27. D(int16, mmx)
  28. D(int16, sse2)
  29. av_cold int swri_rematrix_init_x86(struct SwrContext *s){
  30. #if HAVE_X86ASM
  31. int mm_flags = av_get_cpu_flags();
  32. int nb_in = s->used_ch_count;
  33. int nb_out = s->out.ch_count;
  34. int num = nb_in * nb_out;
  35. int i,j;
  36. s->mix_1_1_simd = NULL;
  37. s->mix_2_1_simd = NULL;
  38. if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
  39. if(EXTERNAL_MMX(mm_flags)) {
  40. s->mix_1_1_simd = ff_mix_1_1_a_int16_mmx;
  41. s->mix_2_1_simd = ff_mix_2_1_a_int16_mmx;
  42. }
  43. if(EXTERNAL_SSE2(mm_flags)) {
  44. s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;
  45. s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;
  46. }
  47. s->native_simd_matrix = av_mallocz_array(num, 2 * sizeof(int16_t));
  48. s->native_simd_one = av_mallocz(2 * sizeof(int16_t));
  49. if (!s->native_simd_matrix || !s->native_simd_one)
  50. return AVERROR(ENOMEM);
  51. for(i=0; i<nb_out; i++){
  52. int sh = 0;
  53. for(j=0; j<nb_in; j++)
  54. sh = FFMAX(sh, FFABS(((int*)s->native_matrix)[i * nb_in + j]));
  55. sh = FFMAX(av_log2(sh) - 14, 0);
  56. for(j=0; j<nb_in; j++) {
  57. ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;
  58. ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =
  59. ((((int*)s->native_matrix)[i * nb_in + j]) + (1<<sh>>1)) >> sh;
  60. }
  61. }
  62. ((int16_t*)s->native_simd_one)[1] = 14;
  63. ((int16_t*)s->native_simd_one)[0] = 16384;
  64. } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
  65. if(EXTERNAL_SSE(mm_flags)) {
  66. s->mix_1_1_simd = ff_mix_1_1_a_float_sse;
  67. s->mix_2_1_simd = ff_mix_2_1_a_float_sse;
  68. }
  69. if(EXTERNAL_AVX_FAST(mm_flags)) {
  70. s->mix_1_1_simd = ff_mix_1_1_a_float_avx;
  71. s->mix_2_1_simd = ff_mix_2_1_a_float_avx;
  72. }
  73. s->native_simd_matrix = av_mallocz_array(num, sizeof(float));
  74. s->native_simd_one = av_mallocz(sizeof(float));
  75. if (!s->native_simd_matrix || !s->native_simd_one)
  76. return AVERROR(ENOMEM);
  77. memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));
  78. memcpy(s->native_simd_one, s->native_one, sizeof(float));
  79. }
  80. #endif
  81. return 0;
  82. }