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.

156 lines
6.2KB

  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 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 FFMPEG_H264_I386_H
  28. #define FFMPEG_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 defined(ARCH_X86) && defined(HAVE_7REGS) && \
  33. defined(HAVE_EBX_AVAILABLE) && \
  34. !defined(BROKEN_RELOCATIONS)
  35. static int decode_significance_x86(CABACContext *c, int max_coeff,
  36. uint8_t *significant_coeff_ctx_base,
  37. int *index){
  38. void *end= significant_coeff_ctx_base + max_coeff - 1;
  39. int minusstart= -(int)significant_coeff_ctx_base;
  40. int minusindex= 4-(int)index;
  41. int coeff_count;
  42. asm volatile(
  43. "movl "RANGE "(%3), %%esi \n\t"
  44. "movl "LOW "(%3), %%ebx \n\t"
  45. "2: \n\t"
  46. BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx",
  47. "%%bx", "%%esi", "%%eax", "%%al")
  48. "test $1, %%edx \n\t"
  49. " jz 3f \n\t"
  50. BRANCHLESS_GET_CABAC("%%edx", "%3", "61(%1)", "%%ebx",
  51. "%%bx", "%%esi", "%%eax", "%%al")
  52. "mov %2, %%"REG_a" \n\t"
  53. "movl %4, %%ecx \n\t"
  54. "add %1, %%"REG_c" \n\t"
  55. "movl %%ecx, (%%"REG_a") \n\t"
  56. "test $1, %%edx \n\t"
  57. " jnz 4f \n\t"
  58. "add $4, %%"REG_a" \n\t"
  59. "mov %%"REG_a", %2 \n\t"
  60. "3: \n\t"
  61. "add $1, %1 \n\t"
  62. "cmp %5, %1 \n\t"
  63. " jb 2b \n\t"
  64. "mov %2, %%"REG_a" \n\t"
  65. "movl %4, %%ecx \n\t"
  66. "add %1, %%"REG_c" \n\t"
  67. "movl %%ecx, (%%"REG_a") \n\t"
  68. "4: \n\t"
  69. "add %6, %%eax \n\t"
  70. "shr $2, %%eax \n\t"
  71. "movl %%esi, "RANGE "(%3) \n\t"
  72. "movl %%ebx, "LOW "(%3) \n\t"
  73. :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index)
  74. :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex)
  75. : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
  76. );
  77. return coeff_count;
  78. }
  79. static int decode_significance_8x8_x86(CABACContext *c,
  80. uint8_t *significant_coeff_ctx_base,
  81. int *index, const uint8_t *sig_off){
  82. int minusindex= 4-(int)index;
  83. int coeff_count;
  84. x86_reg last=0;
  85. asm volatile(
  86. "movl "RANGE "(%3), %%esi \n\t"
  87. "movl "LOW "(%3), %%ebx \n\t"
  88. "mov %1, %%"REG_D" \n\t"
  89. "2: \n\t"
  90. "mov %6, %%"REG_a" \n\t"
  91. "movzbl (%%"REG_a", %%"REG_D"), %%edi \n\t"
  92. "add %5, %%"REG_D" \n\t"
  93. BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx",
  94. "%%bx", "%%esi", "%%eax", "%%al")
  95. "mov %1, %%edi \n\t"
  96. "test $1, %%edx \n\t"
  97. " jz 3f \n\t"
  98. "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
  99. "add %5, %%"REG_D" \n\t"
  100. BRANCHLESS_GET_CABAC("%%edx", "%3", "15(%%"REG_D")", "%%ebx",
  101. "%%bx", "%%esi", "%%eax", "%%al")
  102. "mov %2, %%"REG_a" \n\t"
  103. "mov %1, %%edi \n\t"
  104. "movl %%edi, (%%"REG_a") \n\t"
  105. "test $1, %%edx \n\t"
  106. " jnz 4f \n\t"
  107. "add $4, %%"REG_a" \n\t"
  108. "mov %%"REG_a", %2 \n\t"
  109. "3: \n\t"
  110. "addl $1, %%edi \n\t"
  111. "mov %%edi, %1 \n\t"
  112. "cmpl $63, %%edi \n\t"
  113. " jb 2b \n\t"
  114. "mov %2, %%"REG_a" \n\t"
  115. "movl %%edi, (%%"REG_a") \n\t"
  116. "4: \n\t"
  117. "addl %4, %%eax \n\t"
  118. "shr $2, %%eax \n\t"
  119. "movl %%esi, "RANGE "(%3) \n\t"
  120. "movl %%ebx, "LOW "(%3) \n\t"
  121. :"=&a"(coeff_count),"+m"(last), "+m"(index)
  122. :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off)
  123. : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory"
  124. );
  125. return coeff_count;
  126. }
  127. #endif /* defined(ARCH_X86) && defined(HAVE_7REGS) && */
  128. /* defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) */
  129. #endif /* FFMPEG_H264_I386_H */