inline_asm.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * inline assembly helper macros
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_X86_INLINE_ASM_H
  21. #define AVCODEC_X86_INLINE_ASM_H
  22. #include "constants.h"
  23. #define MOVQ_WONE(regd) \
  24. __asm__ volatile ( \
  25. "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
  26. "psrlw $15, %%" #regd ::)
  27. #define JUMPALIGN() __asm__ volatile (".p2align 3"::)
  28. #define MOVQ_ZERO(regd) __asm__ volatile ("pxor %%"#regd", %%"#regd ::)
  29. #define MOVQ_BFE(regd) \
  30. __asm__ volatile ( \
  31. "pcmpeqd %%"#regd", %%"#regd" \n\t" \
  32. "paddb %%"#regd", %%"#regd" \n\t" ::)
  33. #ifndef PIC
  34. #define MOVQ_WTWO(regd) __asm__ volatile ("movq %0, %%"#regd" \n\t" :: "m"(ff_pw_2))
  35. #else
  36. // for shared library it's better to use this way for accessing constants
  37. // pcmpeqd -> -1
  38. #define MOVQ_WTWO(regd) \
  39. __asm__ volatile ( \
  40. "pcmpeqd %%"#regd", %%"#regd" \n\t" \
  41. "psrlw $15, %%"#regd" \n\t" \
  42. "psllw $1, %%"#regd" \n\t"::)
  43. #endif
  44. // using regr as temporary and for the output result
  45. // first argument is unmodified and second is trashed
  46. // regfe is supposed to contain 0xfefefefefefefefe
  47. #define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
  48. "movq "#rega", "#regr" \n\t" \
  49. "pand "#regb", "#regr" \n\t" \
  50. "pxor "#rega", "#regb" \n\t" \
  51. "pand "#regfe", "#regb" \n\t" \
  52. "psrlq $1, "#regb" \n\t" \
  53. "paddb "#regb", "#regr" \n\t"
  54. #define PAVGB_MMX(rega, regb, regr, regfe) \
  55. "movq "#rega", "#regr" \n\t" \
  56. "por "#regb", "#regr" \n\t" \
  57. "pxor "#rega", "#regb" \n\t" \
  58. "pand "#regfe", "#regb" \n\t" \
  59. "psrlq $1, "#regb" \n\t" \
  60. "psubb "#regb", "#regr" \n\t"
  61. // mm6 is supposed to contain 0xfefefefefefefefe
  62. #define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
  63. "movq "#rega", "#regr" \n\t" \
  64. "movq "#regc", "#regp" \n\t" \
  65. "pand "#regb", "#regr" \n\t" \
  66. "pand "#regd", "#regp" \n\t" \
  67. "pxor "#rega", "#regb" \n\t" \
  68. "pxor "#regc", "#regd" \n\t" \
  69. "pand %%mm6, "#regb" \n\t" \
  70. "pand %%mm6, "#regd" \n\t" \
  71. "psrlq $1, "#regb" \n\t" \
  72. "psrlq $1, "#regd" \n\t" \
  73. "paddb "#regb", "#regr" \n\t" \
  74. "paddb "#regd", "#regp" \n\t"
  75. #define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
  76. "movq "#rega", "#regr" \n\t" \
  77. "movq "#regc", "#regp" \n\t" \
  78. "por "#regb", "#regr" \n\t" \
  79. "por "#regd", "#regp" \n\t" \
  80. "pxor "#rega", "#regb" \n\t" \
  81. "pxor "#regc", "#regd" \n\t" \
  82. "pand %%mm6, "#regb" \n\t" \
  83. "pand %%mm6, "#regd" \n\t" \
  84. "psrlq $1, "#regd" \n\t" \
  85. "psrlq $1, "#regb" \n\t" \
  86. "psubb "#regb", "#regr" \n\t" \
  87. "psubb "#regd", "#regp" \n\t"
  88. #endif /* AVCODEC_X86_INLINE_ASM_H */