cabac.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVCODEC_ARM_CABAC_H
  19. #define AVCODEC_ARM_CABAC_H
  20. #include "config.h"
  21. #if HAVE_ARMV6T2_INLINE
  22. #include "libavutil/attributes.h"
  23. #include "libavutil/internal.h"
  24. #include "libavcodec/cabac.h"
  25. #define get_cabac_inline get_cabac_inline_arm
  26. static av_always_inline int get_cabac_inline_arm(CABACContext *c,
  27. uint8_t *const state)
  28. {
  29. int bit;
  30. void *reg_b, *reg_c, *tmp;
  31. __asm__ volatile(
  32. "ldrb %[bit] , [%[state]] \n\t"
  33. "add %[r_b] , %[tables] , %[lps_off] \n\t"
  34. "mov %[tmp] , %[range] \n\t"
  35. "and %[range] , %[range] , #0xC0 \n\t"
  36. "add %[r_b] , %[r_b] , %[bit] \n\t"
  37. "ldrb %[range] , [%[r_b], %[range], lsl #1] \n\t"
  38. "add %[r_b] , %[tables] , %[norm_off] \n\t"
  39. "sub %[r_c] , %[tmp] , %[range] \n\t"
  40. "lsl %[tmp] , %[r_c] , #17 \n\t"
  41. "cmp %[tmp] , %[low] \n\t"
  42. "it gt \n\t"
  43. "movgt %[range] , %[r_c] \n\t"
  44. "itt cc \n\t"
  45. "mvncc %[bit] , %[bit] \n\t"
  46. "subcc %[low] , %[low] , %[tmp] \n\t"
  47. "add %[r_c] , %[tables] , %[mlps_off] \n\t"
  48. "ldrb %[tmp] , [%[r_b], %[range]] \n\t"
  49. "ldrb %[r_b] , [%[r_c], %[bit]] \n\t"
  50. "lsl %[low] , %[low] , %[tmp] \n\t"
  51. "lsl %[range] , %[range] , %[tmp] \n\t"
  52. "uxth %[r_c] , %[low] \n\t"
  53. "strb %[r_b] , [%[state]] \n\t"
  54. "tst %[r_c] , %[r_c] \n\t"
  55. "bne 2f \n\t"
  56. "ldr %[r_c] , [%[c], %[byte]] \n\t"
  57. #if UNCHECKED_BITSTREAM_READER
  58. "ldrh %[tmp] , [%[r_c]] \n\t"
  59. "add %[r_c] , %[r_c] , #2 \n\t"
  60. "str %[r_c] , [%[c], %[byte]] \n\t"
  61. #else
  62. "ldr %[r_b] , [%[c], %[end]] \n\t"
  63. "ldrh %[tmp] , [%[r_c]] \n\t"
  64. "cmp %[r_c] , %[r_b] \n\t"
  65. "itt lt \n\t"
  66. "addlt %[r_c] , %[r_c] , #2 \n\t"
  67. "strlt %[r_c] , [%[c], %[byte]] \n\t"
  68. #endif
  69. "sub %[r_c] , %[low] , #1 \n\t"
  70. "add %[r_b] , %[tables] , %[norm_off] \n\t"
  71. "eor %[r_c] , %[low] , %[r_c] \n\t"
  72. "rev %[tmp] , %[tmp] \n\t"
  73. "lsr %[r_c] , %[r_c] , #15 \n\t"
  74. "lsr %[tmp] , %[tmp] , #15 \n\t"
  75. "ldrb %[r_c] , [%[r_b], %[r_c]] \n\t"
  76. "movw %[r_b] , #0xFFFF \n\t"
  77. "sub %[tmp] , %[tmp] , %[r_b] \n\t"
  78. "rsb %[r_c] , %[r_c] , #7 \n\t"
  79. "lsl %[tmp] , %[tmp] , %[r_c] \n\t"
  80. "add %[low] , %[low] , %[tmp] \n\t"
  81. "2: \n\t"
  82. : [bit]"=&r"(bit),
  83. [low]"+&r"(c->low),
  84. [range]"+&r"(c->range),
  85. [r_b]"=&r"(reg_b),
  86. [r_c]"=&r"(reg_c),
  87. [tmp]"=&r"(tmp)
  88. : [c]"r"(c),
  89. [state]"r"(state),
  90. [tables]"r"(ff_h264_cabac_tables),
  91. [byte]"M"(offsetof(CABACContext, bytestream)),
  92. [end]"M"(offsetof(CABACContext, bytestream_end)),
  93. [norm_off]"I"(H264_NORM_SHIFT_OFFSET),
  94. [lps_off]"I"(H264_LPS_RANGE_OFFSET),
  95. [mlps_off]"I"(H264_MLPS_STATE_OFFSET + 128)
  96. : "memory", "cc"
  97. );
  98. return bit & 1;
  99. }
  100. #endif /* HAVE_ARMV6T2_INLINE */
  101. #endif /* AVCODEC_ARM_CABAC_H */