h264_i386.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
  3. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  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. /**
  22. * @file libavcodec/x86/h264_i386.h
  23. * H.264 / AVC / MPEG4 part10 codec.
  24. * non-MMX i386-specific optimizations for H.264
  25. * @author Michael Niedermayer <michaelni@gmx.at>
  26. */
  27. #ifndef AVCODEC_X86_H264_I386_H
  28. #define AVCODEC_X86_H264_I386_H
  29. #include "libavcodec/cabac.h"
  30. //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
  31. //as that would make optimization work hard)
  32. #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
  33. static int decode_significance_x86(CABACContext *c, int max_coeff,
  34. uint8_t *significant_coeff_ctx_base,
  35. int *index){
  36. void *end= significant_coeff_ctx_base + max_coeff - 1;
  37. int minusstart= -(int)significant_coeff_ctx_base;
  38. int minusindex= 4-(int)index;
  39. int coeff_count;
  40. __asm__ volatile(
  41. "movl "RANGE "(%3), %%esi \n\t"
  42. "movl "LOW "(%3), %%ebx \n\t"
  43. "2: \n\t"
  44. BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx",
  45. "%%bx", "%%esi", "%%eax", "%%al")
  46. "test $1, %%edx \n\t"
  47. " jz 3f \n\t"
  48. BRANCHLESS_GET_CABAC("%%edx", "%3", "61(%1)", "%%ebx",
  49. "%%bx", "%%esi", "%%eax", "%%al")
  50. "mov %2, %%"REG_a" \n\t"
  51. "movl %4, %%ecx \n\t"
  52. "add %1, %%"REG_c" \n\t"
  53. "movl %%ecx, (%%"REG_a") \n\t"
  54. "test $1, %%edx \n\t"
  55. " jnz 4f \n\t"
  56. "add $4, %%"REG_a" \n\t"
  57. "mov %%"REG_a", %2 \n\t"
  58. "3: \n\t"
  59. "add $1, %1 \n\t"
  60. "cmp %5, %1 \n\t"
  61. " jb 2b \n\t"
  62. "mov %2, %%"REG_a" \n\t"
  63. "movl %4, %%ecx \n\t"
  64. "add %1, %%"REG_c" \n\t"
  65. "movl %%ecx, (%%"REG_a") \n\t"
  66. "4: \n\t"
  67. "add %6, %%eax \n\t"
  68. "shr $2, %%eax \n\t"
  69. "movl %%esi, "RANGE "(%3) \n\t"
  70. "movl %%ebx, "LOW "(%3) \n\t"
  71. :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index)
  72. :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex)
  73. : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
  74. );
  75. return coeff_count;
  76. }
  77. static int decode_significance_8x8_x86(CABACContext *c,
  78. uint8_t *significant_coeff_ctx_base,
  79. int *index, const uint8_t *sig_off){
  80. int minusindex= 4-(int)index;
  81. int coeff_count;
  82. x86_reg last=0;
  83. __asm__ volatile(
  84. "movl "RANGE "(%3), %%esi \n\t"
  85. "movl "LOW "(%3), %%ebx \n\t"
  86. "mov %1, %%"REG_D" \n\t"
  87. "2: \n\t"
  88. "mov %6, %%"REG_a" \n\t"
  89. "movzbl (%%"REG_a", %%"REG_D"), %%edi \n\t"
  90. "add %5, %%"REG_D" \n\t"
  91. BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx",
  92. "%%bx", "%%esi", "%%eax", "%%al")
  93. "mov %1, %%edi \n\t"
  94. "test $1, %%edx \n\t"
  95. " jz 3f \n\t"
  96. "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
  97. "add %5, %%"REG_D" \n\t"
  98. BRANCHLESS_GET_CABAC("%%edx", "%3", "15(%%"REG_D")", "%%ebx",
  99. "%%bx", "%%esi", "%%eax", "%%al")
  100. "mov %2, %%"REG_a" \n\t"
  101. "mov %1, %%edi \n\t"
  102. "movl %%edi, (%%"REG_a") \n\t"
  103. "test $1, %%edx \n\t"
  104. " jnz 4f \n\t"
  105. "add $4, %%"REG_a" \n\t"
  106. "mov %%"REG_a", %2 \n\t"
  107. "3: \n\t"
  108. "addl $1, %%edi \n\t"
  109. "mov %%edi, %1 \n\t"
  110. "cmpl $63, %%edi \n\t"
  111. " jb 2b \n\t"
  112. "mov %2, %%"REG_a" \n\t"
  113. "movl %%edi, (%%"REG_a") \n\t"
  114. "4: \n\t"
  115. "addl %4, %%eax \n\t"
  116. "shr $2, %%eax \n\t"
  117. "movl %%esi, "RANGE "(%3) \n\t"
  118. "movl %%ebx, "LOW "(%3) \n\t"
  119. :"=&a"(coeff_count),"+m"(last), "+m"(index)
  120. :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off)
  121. : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory"
  122. );
  123. return coeff_count;
  124. }
  125. #endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE */
  126. /* !defined(BROKEN_RELOCATIONS) */
  127. #endif /* AVCODEC_X86_H264_I386_H */