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.

194 lines
7.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 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. #include "cabac.h"
  32. #if HAVE_INLINE_ASM
  33. //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
  34. //as that would make optimization work hard)
  35. #if HAVE_7REGS
  36. #define decode_significance decode_significance_x86
  37. static int decode_significance_x86(CABACContext *c, int max_coeff,
  38. uint8_t *significant_coeff_ctx_base,
  39. int *index, x86_reg last_off){
  40. void *end= significant_coeff_ctx_base + max_coeff - 1;
  41. int minusstart= -(intptr_t)significant_coeff_ctx_base;
  42. int minusindex= 4-(intptr_t)index;
  43. int bit;
  44. x86_reg coeff_count;
  45. #ifdef BROKEN_RELOCATIONS
  46. void *tables;
  47. __asm__ volatile(
  48. "lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
  49. : "=&r"(tables)
  50. );
  51. #endif
  52. __asm__ volatile(
  53. "3: \n\t"
  54. BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
  55. "%5", "%q5", "%k0", "%b0",
  56. "%a11(%6)", "%a12(%6)", "%a13", "%a14", "%a15", "%16")
  57. "test $1, %4 \n\t"
  58. " jz 4f \n\t"
  59. "add %10, %1 \n\t"
  60. BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
  61. "%5", "%q5", "%k0", "%b0",
  62. "%a11(%6)", "%a12(%6)", "%a13", "%a14", "%a15", "%16")
  63. "sub %10, %1 \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. "test $1, %4 \n\t"
  69. " jnz 5f \n\t"
  70. "add"OPSIZE" $4, %2 \n\t"
  71. "4: \n\t"
  72. "add $1, %1 \n\t"
  73. "cmp %8, %1 \n\t"
  74. " jb 3b \n\t"
  75. "mov %2, %0 \n\t"
  76. "movl %7, %%ecx \n\t"
  77. "add %1, %%"REG_c" \n\t"
  78. "movl %%ecx, (%0) \n\t"
  79. "5: \n\t"
  80. "add %9, %k0 \n\t"
  81. "shr $2, %k0 \n\t"
  82. : "=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
  83. "+&r"(c->low), "=&r"(bit), "+&r"(c->range)
  84. : "r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
  85. "i"(offsetof(CABACContext, bytestream)),
  86. "i"(offsetof(CABACContext, bytestream_end)),
  87. "i"(H264_NORM_SHIFT_OFFSET),
  88. "i"(H264_LPS_RANGE_OFFSET),
  89. "i"(H264_MLPS_STATE_OFFSET) TABLES_ARG
  90. : "%"REG_c, "memory"
  91. );
  92. return coeff_count;
  93. }
  94. #define decode_significance_8x8 decode_significance_8x8_x86
  95. static int decode_significance_8x8_x86(CABACContext *c,
  96. uint8_t *significant_coeff_ctx_base,
  97. int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
  98. int minusindex= 4-(intptr_t)index;
  99. int bit;
  100. x86_reg coeff_count;
  101. x86_reg last=0;
  102. x86_reg state;
  103. #ifdef BROKEN_RELOCATIONS
  104. void *tables;
  105. __asm__ volatile(
  106. "lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
  107. : "=&r"(tables)
  108. );
  109. #endif
  110. __asm__ volatile(
  111. "mov %1, %6 \n\t"
  112. "3: \n\t"
  113. "mov %10, %0 \n\t"
  114. "movzbl (%0, %6), %k6 \n\t"
  115. "add %9, %6 \n\t"
  116. BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
  117. "%5", "%q5", "%k0", "%b0",
  118. "%a12(%7)", "%a13(%7)", "%a14", "%a15", "%a16", "%18")
  119. "mov %1, %k6 \n\t"
  120. "test $1, %4 \n\t"
  121. " jz 4f \n\t"
  122. #ifdef BROKEN_RELOCATIONS
  123. "movzbl %a17(%18, %q6), %k6\n\t"
  124. #else
  125. "movzbl "MANGLE(ff_h264_cabac_tables)"+%a17(%k6), %k6\n\t"
  126. #endif
  127. "add %11, %6 \n\t"
  128. BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
  129. "%5", "%q5", "%k0", "%b0",
  130. "%a12(%7)", "%a13(%7)", "%a14", "%a15", "%a16", "%18")
  131. "mov %2, %0 \n\t"
  132. "mov %1, %k6 \n\t"
  133. "movl %k6, (%0) \n\t"
  134. "test $1, %4 \n\t"
  135. " jnz 5f \n\t"
  136. "add"OPSIZE" $4, %2 \n\t"
  137. "4: \n\t"
  138. "addl $1, %k6 \n\t"
  139. "mov %k6, %1 \n\t"
  140. "cmpl $63, %k6 \n\t"
  141. " jb 3b \n\t"
  142. "mov %2, %0 \n\t"
  143. "movl %k6, (%0) \n\t"
  144. "5: \n\t"
  145. "addl %8, %k0 \n\t"
  146. "shr $2, %k0 \n\t"
  147. : "=&q"(coeff_count), "+m"(last), "+m"(index), "+&r"(c->low),
  148. "=&r"(bit), "+&r"(c->range), "=&r"(state)
  149. : "r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base),
  150. "m"(sig_off), "m"(last_coeff_ctx_base),
  151. "i"(offsetof(CABACContext, bytestream)),
  152. "i"(offsetof(CABACContext, bytestream_end)),
  153. "i"(H264_NORM_SHIFT_OFFSET),
  154. "i"(H264_LPS_RANGE_OFFSET),
  155. "i"(H264_MLPS_STATE_OFFSET),
  156. "i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET) TABLES_ARG
  157. : "%"REG_c, "memory"
  158. );
  159. return coeff_count;
  160. }
  161. #endif /* HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
  162. #endif /* HAVE_INLINE_ASM */
  163. #endif /* AVCODEC_X86_H264_I386_H */