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.

137 lines
4.2KB

  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
  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. #ifndef AVCODEC_I386_DSPUTIL_MMX_H
  22. #define AVCODEC_I386_DSPUTIL_MMX_H
  23. #include <stdint.h>
  24. #include "libavcodec/dsputil.h"
  25. typedef struct { uint64_t a, b; } xmm_t;
  26. extern const uint64_t ff_bone;
  27. extern const uint64_t ff_wtwo;
  28. extern const uint64_t ff_pdw_80000000[2];
  29. extern const uint64_t ff_pw_3;
  30. extern const uint64_t ff_pw_4;
  31. extern const xmm_t ff_pw_5;
  32. extern const xmm_t ff_pw_8;
  33. extern const uint64_t ff_pw_15;
  34. extern const xmm_t ff_pw_16;
  35. extern const uint64_t ff_pw_20;
  36. extern const xmm_t ff_pw_28;
  37. extern const xmm_t ff_pw_32;
  38. extern const uint64_t ff_pw_42;
  39. extern const uint64_t ff_pw_64;
  40. extern const uint64_t ff_pw_96;
  41. extern const uint64_t ff_pw_128;
  42. extern const uint64_t ff_pw_255;
  43. extern const uint64_t ff_pb_1;
  44. extern const uint64_t ff_pb_3;
  45. extern const uint64_t ff_pb_7;
  46. extern const uint64_t ff_pb_3F;
  47. extern const uint64_t ff_pb_A1;
  48. extern const uint64_t ff_pb_FC;
  49. extern const double ff_pd_1[2];
  50. extern const double ff_pd_2[2];
  51. #define LOAD4(stride,in,a,b,c,d)\
  52. "movq 0*"#stride"+"#in", "#a"\n\t"\
  53. "movq 1*"#stride"+"#in", "#b"\n\t"\
  54. "movq 2*"#stride"+"#in", "#c"\n\t"\
  55. "movq 3*"#stride"+"#in", "#d"\n\t"
  56. #define STORE4(stride,out,a,b,c,d)\
  57. "movq "#a", 0*"#stride"+"#out"\n\t"\
  58. "movq "#b", 1*"#stride"+"#out"\n\t"\
  59. "movq "#c", 2*"#stride"+"#out"\n\t"\
  60. "movq "#d", 3*"#stride"+"#out"\n\t"
  61. /* in/out: mma=mma+mmb, mmb=mmb-mma */
  62. #define SUMSUB_BA( a, b ) \
  63. "paddw "#b", "#a" \n\t"\
  64. "paddw "#b", "#b" \n\t"\
  65. "psubw "#a", "#b" \n\t"
  66. #define SBUTTERFLY(a,b,t,n,m)\
  67. "mov" #m " " #a ", " #t " \n\t" /* abcd */\
  68. "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
  69. "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
  70. #define TRANSPOSE4(a,b,c,d,t)\
  71. SBUTTERFLY(a,b,t,wd,q) /* a=aebf t=cgdh */\
  72. SBUTTERFLY(c,d,b,wd,q) /* c=imjn b=kolp */\
  73. SBUTTERFLY(a,c,d,dq,q) /* a=aeim d=bfjn */\
  74. SBUTTERFLY(t,b,c,dq,q) /* t=cgko c=dhlp */
  75. #ifdef ARCH_X86_64
  76. // permutes 01234567 -> 05736421
  77. #define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\
  78. SBUTTERFLY(a,b,%%xmm8,wd,dqa)\
  79. SBUTTERFLY(c,d,b,wd,dqa)\
  80. SBUTTERFLY(e,f,d,wd,dqa)\
  81. SBUTTERFLY(g,h,f,wd,dqa)\
  82. SBUTTERFLY(a,c,h,dq,dqa)\
  83. SBUTTERFLY(%%xmm8,b,c,dq,dqa)\
  84. SBUTTERFLY(e,g,b,dq,dqa)\
  85. SBUTTERFLY(d,f,g,dq,dqa)\
  86. SBUTTERFLY(a,e,f,qdq,dqa)\
  87. SBUTTERFLY(%%xmm8,d,e,qdq,dqa)\
  88. SBUTTERFLY(h,b,d,qdq,dqa)\
  89. SBUTTERFLY(c,g,b,qdq,dqa)\
  90. "movdqa %%xmm8, "#g" \n\t"
  91. #else
  92. #define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\
  93. "movdqa "#h", "#t" \n\t"\
  94. SBUTTERFLY(a,b,h,wd,dqa)\
  95. "movdqa "#h", 16"#t" \n\t"\
  96. "movdqa "#t", "#h" \n\t"\
  97. SBUTTERFLY(c,d,b,wd,dqa)\
  98. SBUTTERFLY(e,f,d,wd,dqa)\
  99. SBUTTERFLY(g,h,f,wd,dqa)\
  100. SBUTTERFLY(a,c,h,dq,dqa)\
  101. "movdqa "#h", "#t" \n\t"\
  102. "movdqa 16"#t", "#h" \n\t"\
  103. SBUTTERFLY(h,b,c,dq,dqa)\
  104. SBUTTERFLY(e,g,b,dq,dqa)\
  105. SBUTTERFLY(d,f,g,dq,dqa)\
  106. SBUTTERFLY(a,e,f,qdq,dqa)\
  107. SBUTTERFLY(h,d,e,qdq,dqa)\
  108. "movdqa "#h", 16"#t" \n\t"\
  109. "movdqa "#t", "#h" \n\t"\
  110. SBUTTERFLY(h,b,d,qdq,dqa)\
  111. SBUTTERFLY(c,g,b,qdq,dqa)\
  112. "movdqa 16"#t", "#g" \n\t"
  113. #endif
  114. #define MOVQ_WONE(regd) \
  115. asm volatile ( \
  116. "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
  117. "psrlw $15, %%" #regd ::)
  118. void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx);
  119. #endif /* AVCODEC_I386_DSPUTIL_MMX_H */