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.

170 lines
6.6KB

  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 Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  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 <stddef.h>
  30. #include "libavcodec/cabac.h"
  31. //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
  32. //as that would make optimization work hard)
  33. #if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
  34. static int decode_significance_x86(CABACContext *c, int max_coeff,
  35. uint8_t *significant_coeff_ctx_base,
  36. int *index, x86_reg last_off){
  37. void *end= significant_coeff_ctx_base + max_coeff - 1;
  38. int minusstart= -(int)significant_coeff_ctx_base;
  39. int minusindex= 4-(int)index;
  40. int bit;
  41. x86_reg coeff_count;
  42. int low;
  43. int range;
  44. __asm__ volatile(
  45. "movl %a11(%6), %5 \n\t"
  46. "movl %a12(%6), %3 \n\t"
  47. "2: \n\t"
  48. BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
  49. "%w3", "%5", "%k0", "%b0", "%a13")
  50. "test $1, %4 \n\t"
  51. " jz 3f \n\t"
  52. "add %10, %1 \n\t"
  53. BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
  54. "%w3", "%5", "%k0", "%b0", "%a13")
  55. "sub %10, %1 \n\t"
  56. "mov %2, %0 \n\t"
  57. "movl %7, %%ecx \n\t"
  58. "add %1, %%"REG_c" \n\t"
  59. "movl %%ecx, (%0) \n\t"
  60. "test $1, %4 \n\t"
  61. " jnz 4f \n\t"
  62. "add $4, %0 \n\t"
  63. "mov %0, %2 \n\t"
  64. "3: \n\t"
  65. "add $1, %1 \n\t"
  66. "cmp %8, %1 \n\t"
  67. " jb 2b \n\t"
  68. "mov %2, %0 \n\t"
  69. "movl %7, %%ecx \n\t"
  70. "add %1, %%"REG_c" \n\t"
  71. "movl %%ecx, (%0) \n\t"
  72. "4: \n\t"
  73. "add %9, %k0 \n\t"
  74. "shr $2, %k0 \n\t"
  75. "movl %5, %a11(%6) \n\t"
  76. "movl %3, %a12(%6) \n\t"
  77. :"=&r"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
  78. "=&r"(low), "=&r"(bit), "=&r"(range)
  79. :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
  80. "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
  81. "i"(offsetof(CABACContext, bytestream))
  82. : "%"REG_c, "memory"
  83. );
  84. return coeff_count;
  85. }
  86. static int decode_significance_8x8_x86(CABACContext *c,
  87. uint8_t *significant_coeff_ctx_base,
  88. int *index, x86_reg last_off, const uint8_t *sig_off){
  89. int minusindex= 4-(int)index;
  90. int bit;
  91. x86_reg coeff_count;
  92. int low;
  93. int range;
  94. x86_reg last=0;
  95. __asm__ volatile(
  96. "movl %a11(%6), %5 \n\t"
  97. "movl %a12(%6), %3 \n\t"
  98. "mov %1, %%"REG_D" \n\t"
  99. "2: \n\t"
  100. "mov %9, %0 \n\t"
  101. "movzbl (%0, %%"REG_D"), %%edi \n\t"
  102. "add %8, %%"REG_D" \n\t"
  103. BRANCHLESS_GET_CABAC("%4", "%6", "(%%"REG_D")", "%3",
  104. "%w3", "%5", "%k0", "%b0", "%a13")
  105. "mov %1, %%edi \n\t"
  106. "test $1, %4 \n\t"
  107. " jz 3f \n\t"
  108. "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
  109. "add %8, %%"REG_D" \n\t"
  110. "add %10, %%"REG_D" \n\t"
  111. BRANCHLESS_GET_CABAC("%4", "%6", "(%%"REG_D")", "%3",
  112. "%w3", "%5", "%k0", "%b0", "%a13")
  113. "mov %2, %0 \n\t"
  114. "mov %1, %%edi \n\t"
  115. "movl %%edi, (%0) \n\t"
  116. "test $1, %4 \n\t"
  117. " jnz 4f \n\t"
  118. "add $4, %0 \n\t"
  119. "mov %0, %2 \n\t"
  120. "3: \n\t"
  121. "addl $1, %%edi \n\t"
  122. "mov %%edi, %1 \n\t"
  123. "cmpl $63, %%edi \n\t"
  124. " jb 2b \n\t"
  125. "mov %2, %0 \n\t"
  126. "movl %%edi, (%0) \n\t"
  127. "4: \n\t"
  128. "addl %7, %k0 \n\t"
  129. "shr $2, %k0 \n\t"
  130. "movl %5, %a11(%6) \n\t"
  131. "movl %3, %a12(%6) \n\t"
  132. :"=&r"(coeff_count),"+m"(last), "+m"(index), "=&r"(low), "=&r"(bit),
  133. "=&r"(range)
  134. :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off),
  135. "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
  136. "i"(offsetof(CABACContext, bytestream))
  137. : "%"REG_c, "%"REG_D, "memory"
  138. );
  139. return coeff_count;
  140. }
  141. #endif /* ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
  142. #endif /* AVCODEC_X86_H264_I386_H */