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.

201 lines
7.7KB

  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 / MPEG-4 part10 codec.
  24. * non-SIMD x86-specific optimizations for H.264
  25. * @author Michael Niedermayer <michaelni@gmx.at>
  26. */
  27. #include <stddef.h>
  28. #include "libavcodec/cabac.h"
  29. #include "cabac.h"
  30. #if HAVE_INLINE_ASM
  31. //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
  32. //as that would make optimization work hard)
  33. #if HAVE_7REGS
  34. #define decode_significance decode_significance_x86
  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. #ifdef BROKEN_RELOCATIONS
  44. void *tables;
  45. __asm__ volatile(
  46. "lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
  47. : "=&r"(tables)
  48. );
  49. #endif
  50. __asm__ volatile(
  51. "3: \n\t"
  52. BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
  53. "%5", "%q5", "%k0", "%b0",
  54. "%c11(%6)", "%c12(%6)",
  55. AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
  56. AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
  57. AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
  58. "%13")
  59. "test $1, %4 \n\t"
  60. " jz 4f \n\t"
  61. "add %10, %1 \n\t"
  62. BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
  63. "%5", "%q5", "%k0", "%b0",
  64. "%c11(%6)", "%c12(%6)",
  65. AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
  66. AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
  67. AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
  68. "%13")
  69. "sub %10, %1 \n\t"
  70. "mov %2, %0 \n\t"
  71. "movl %7, %%ecx \n\t"
  72. "add %1, %%"FF_REG_c" \n\t"
  73. "movl %%ecx, (%0) \n\t"
  74. "test $1, %4 \n\t"
  75. " jnz 5f \n\t"
  76. "add"FF_OPSIZE" $4, %2 \n\t"
  77. "4: \n\t"
  78. "add $1, %1 \n\t"
  79. "cmp %8, %1 \n\t"
  80. " jb 3b \n\t"
  81. "mov %2, %0 \n\t"
  82. "movl %7, %%ecx \n\t"
  83. "add %1, %%"FF_REG_c" \n\t"
  84. "movl %%ecx, (%0) \n\t"
  85. "5: \n\t"
  86. "add %9, %k0 \n\t"
  87. "shr $2, %k0 \n\t"
  88. : "=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
  89. "+&r"(c->low), "=&r"(bit), "+&r"(c->range)
  90. : "r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
  91. "i"(offsetof(CABACContext, bytestream)),
  92. "i"(offsetof(CABACContext, bytestream_end))
  93. TABLES_ARG
  94. : "%"FF_REG_c, "memory"
  95. );
  96. return coeff_count;
  97. }
  98. #define decode_significance_8x8 decode_significance_8x8_x86
  99. static int decode_significance_8x8_x86(CABACContext *c,
  100. uint8_t *significant_coeff_ctx_base,
  101. int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
  102. int minusindex= 4-(intptr_t)index;
  103. int bit;
  104. x86_reg coeff_count;
  105. x86_reg last=0;
  106. x86_reg state;
  107. #ifdef BROKEN_RELOCATIONS
  108. void *tables;
  109. __asm__ volatile(
  110. "lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
  111. : "=&r"(tables)
  112. );
  113. #endif
  114. __asm__ volatile(
  115. "mov %1, %6 \n\t"
  116. "3: \n\t"
  117. "mov %10, %0 \n\t"
  118. "movzbl (%0, %6), %k6 \n\t"
  119. "add %9, %6 \n\t"
  120. BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
  121. "%5", "%q5", "%k0", "%b0",
  122. "%c12(%7)", "%c13(%7)",
  123. AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
  124. AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
  125. AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
  126. "%15")
  127. "mov %1, %k6 \n\t"
  128. "test $1, %4 \n\t"
  129. " jz 4f \n\t"
  130. #ifdef BROKEN_RELOCATIONS
  131. "movzbl %c14(%15, %q6), %k6\n\t"
  132. #else
  133. "movzbl "MANGLE(ff_h264_cabac_tables)"+%c14(%k6), %k6\n\t"
  134. #endif
  135. "add %11, %6 \n\t"
  136. BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
  137. "%5", "%q5", "%k0", "%b0",
  138. "%c12(%7)", "%c13(%7)",
  139. AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
  140. AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
  141. AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
  142. "%15")
  143. "mov %2, %0 \n\t"
  144. "mov %1, %k6 \n\t"
  145. "movl %k6, (%0) \n\t"
  146. "test $1, %4 \n\t"
  147. " jnz 5f \n\t"
  148. "add"FF_OPSIZE" $4, %2 \n\t"
  149. "4: \n\t"
  150. "addl $1, %k6 \n\t"
  151. "mov %k6, %1 \n\t"
  152. "cmpl $63, %k6 \n\t"
  153. " jb 3b \n\t"
  154. "mov %2, %0 \n\t"
  155. "movl %k6, (%0) \n\t"
  156. "5: \n\t"
  157. "addl %8, %k0 \n\t"
  158. "shr $2, %k0 \n\t"
  159. : "=&q"(coeff_count), "+m"(last), "+m"(index), "+&r"(c->low),
  160. "=&r"(bit), "+&r"(c->range), "=&r"(state)
  161. : "r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base),
  162. "m"(sig_off), "m"(last_coeff_ctx_base),
  163. "i"(offsetof(CABACContext, bytestream)),
  164. "i"(offsetof(CABACContext, bytestream_end)),
  165. "i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET) TABLES_ARG
  166. : "%"FF_REG_c, "memory"
  167. );
  168. return coeff_count;
  169. }
  170. #endif /* HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
  171. #endif /* HAVE_INLINE_ASM */