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.

151 lines
5.9KB

  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
  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. #include "cabac.h"
  32. //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
  33. //as that would make optimization work hard)
  34. #if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
  35. static int decode_significance_x86(CABACContext *c, int max_coeff,
  36. uint8_t *significant_coeff_ctx_base,
  37. int *index, x86_reg last_off){
  38. void *end= significant_coeff_ctx_base + max_coeff - 1;
  39. int minusstart= -(intptr_t)significant_coeff_ctx_base;
  40. int minusindex= 4-(intptr_t)index;
  41. int bit;
  42. x86_reg coeff_count;
  43. __asm__ volatile(
  44. "2: \n\t"
  45. BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
  46. "%w3", "%5", "%k0", "%b0", "%a11")
  47. "test $1, %4 \n\t"
  48. " jz 3f \n\t"
  49. "add %10, %1 \n\t"
  50. BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
  51. "%w3", "%5", "%k0", "%b0", "%a11")
  52. "sub %10, %1 \n\t"
  53. "mov %2, %0 \n\t"
  54. "movl %7, %%ecx \n\t"
  55. "add %1, %%"REG_c" \n\t"
  56. "movl %%ecx, (%0) \n\t"
  57. "test $1, %4 \n\t"
  58. " jnz 4f \n\t"
  59. "add"OPSIZE" $4, %2 \n\t"
  60. "3: \n\t"
  61. "add $1, %1 \n\t"
  62. "cmp %8, %1 \n\t"
  63. " jb 2b \n\t"
  64. "mov %2, %0 \n\t"
  65. "movl %7, %%ecx \n\t"
  66. "add %1, %%"REG_c" \n\t"
  67. "movl %%ecx, (%0) \n\t"
  68. "4: \n\t"
  69. "add %9, %k0 \n\t"
  70. "shr $2, %k0 \n\t"
  71. :"=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
  72. "+&r"(c->low), "=&r"(bit), "+&r"(c->range)
  73. :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
  74. "i"(offsetof(CABACContext, bytestream))
  75. : "%"REG_c, "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, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
  82. int minusindex= 4-(intptr_t)index;
  83. int bit;
  84. x86_reg coeff_count;
  85. x86_reg last=0;
  86. x86_reg state;
  87. __asm__ volatile(
  88. "mov %1, %6 \n\t"
  89. "2: \n\t"
  90. "mov %10, %0 \n\t"
  91. "movzbl (%0, %6), %k6 \n\t"
  92. "add %9, %6 \n\t"
  93. BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
  94. "%w3", "%5", "%k0", "%b0", "%a12")
  95. "mov %1, %k6 \n\t"
  96. "test $1, %4 \n\t"
  97. " jz 3f \n\t"
  98. "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%k6), %k6\n\t"
  99. "add %11, %6 \n\t"
  100. BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
  101. "%w3", "%5", "%k0", "%b0", "%a12")
  102. "mov %2, %0 \n\t"
  103. "mov %1, %k6 \n\t"
  104. "movl %k6, (%0) \n\t"
  105. "test $1, %4 \n\t"
  106. " jnz 4f \n\t"
  107. "add"OPSIZE" $4, %2 \n\t"
  108. "3: \n\t"
  109. "addl $1, %k6 \n\t"
  110. "mov %k6, %1 \n\t"
  111. "cmpl $63, %k6 \n\t"
  112. " jb 2b \n\t"
  113. "mov %2, %0 \n\t"
  114. "movl %k6, (%0) \n\t"
  115. "4: \n\t"
  116. "addl %8, %k0 \n\t"
  117. "shr $2, %k0 \n\t"
  118. :"=&q"(coeff_count),"+m"(last), "+m"(index), "+&r"(c->low), "=&r"(bit),
  119. "+&r"(c->range), "=&r"(state)
  120. :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_coeff_ctx_base),
  121. "i"(offsetof(CABACContext, bytestream))
  122. : "%"REG_c, "memory"
  123. );
  124. return coeff_count;
  125. }
  126. #endif /* ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
  127. #endif /* AVCODEC_X86_H264_I386_H */