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.

103 lines
4.9KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; 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. "ldr %[r_b] , [%[c], %[end]] \n\t"
  58. "ldrh %[tmp] , [%[r_c]] \n\t"
  59. "cmp %[r_c] , %[r_b] \n\t"
  60. "itt lt \n\t"
  61. "addlt %[r_c] , %[r_c] , #2 \n\t"
  62. "strlt %[r_c] , [%[c], %[byte]] \n\t"
  63. "sub %[r_c] , %[low] , #1 \n\t"
  64. "add %[r_b] , %[tables] , %[norm_off] \n\t"
  65. "eor %[r_c] , %[low] , %[r_c] \n\t"
  66. "rev %[tmp] , %[tmp] \n\t"
  67. "lsr %[r_c] , %[r_c] , #15 \n\t"
  68. "lsr %[tmp] , %[tmp] , #15 \n\t"
  69. "ldrb %[r_c] , [%[r_b], %[r_c]] \n\t"
  70. "movw %[r_b] , #0xFFFF \n\t"
  71. "sub %[tmp] , %[tmp] , %[r_b] \n\t"
  72. "rsb %[r_c] , %[r_c] , #7 \n\t"
  73. "lsl %[tmp] , %[tmp] , %[r_c] \n\t"
  74. "add %[low] , %[low] , %[tmp] \n\t"
  75. "2: \n\t"
  76. : [bit]"=&r"(bit),
  77. [low]"+&r"(c->low),
  78. [range]"+&r"(c->range),
  79. [r_b]"=&r"(reg_b),
  80. [r_c]"=&r"(reg_c),
  81. [tmp]"=&r"(tmp)
  82. : [c]"r"(c),
  83. [state]"r"(state),
  84. [tables]"r"(ff_h264_cabac_tables),
  85. [byte]"M"(offsetof(CABACContext, bytestream)),
  86. [end]"M"(offsetof(CABACContext, bytestream_end)),
  87. [norm_off]"I"(H264_NORM_SHIFT_OFFSET),
  88. [lps_off]"I"(H264_LPS_RANGE_OFFSET),
  89. [mlps_off]"I"(H264_MLPS_STATE_OFFSET + 128)
  90. : "memory", "cc"
  91. );
  92. return bit & 1;
  93. }
  94. #endif /* HAVE_ARMV6T2_INLINE */
  95. #endif /* AVCODEC_ARM_CABAC_H */