vp56_arith.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2010 Mans Rullgard <mans@mansr.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_ARM_VP56_ARITH_H
  21. #define AVCODEC_ARM_VP56_ARITH_H
  22. #if CONFIG_THUMB
  23. # define A(x)
  24. # define T(x) x
  25. #else
  26. # define A(x) x
  27. # define T(x)
  28. #endif
  29. #if CONFIG_THUMB || defined __clang__
  30. # define L(x)
  31. # define U(x) x
  32. #else
  33. # define L(x) x
  34. # define U(x)
  35. #endif
  36. #if HAVE_ARMV6_INLINE
  37. #define vp56_rac_get_prob vp56_rac_get_prob_armv6
  38. static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
  39. {
  40. unsigned shift = ff_vp56_norm_shift[c->high];
  41. unsigned code_word = c->code_word << shift;
  42. unsigned high = c->high << shift;
  43. unsigned bit;
  44. __asm__ ("adds %3, %3, %0 \n"
  45. "itt cs \n"
  46. "cmpcs %7, %4 \n"
  47. L("ldrcsh %2, [%4], #2 \n")
  48. U("ldrhcs %2, [%4], #2 \n")
  49. "rsb %0, %6, #256 \n"
  50. "smlabb %0, %5, %6, %0 \n"
  51. T("itttt cs \n")
  52. "rev16cs %2, %2 \n"
  53. T("lslcs %2, %2, %3 \n")
  54. T("orrcs %1, %1, %2 \n")
  55. A("orrcs %1, %1, %2, lsl %3 \n")
  56. "subcs %3, %3, #16 \n"
  57. "lsr %0, %0, #8 \n"
  58. "cmp %1, %0, lsl #16 \n"
  59. "ittte ge \n"
  60. "subge %1, %1, %0, lsl #16 \n"
  61. "subge %0, %5, %0 \n"
  62. "movge %2, #1 \n"
  63. "movlt %2, #0 \n"
  64. : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit),
  65. "+&r"(c->bits), "+&r"(c->buffer)
  66. : "r"(high), "r"(pr), "r"(c->end - 1),
  67. "0"(shift), "1"(code_word)
  68. : "cc");
  69. return bit;
  70. }
  71. #define vp56_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
  72. static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
  73. {
  74. unsigned shift = ff_vp56_norm_shift[c->high];
  75. unsigned code_word = c->code_word << shift;
  76. unsigned high = c->high << shift;
  77. unsigned low;
  78. unsigned tmp;
  79. __asm__ ("adds %3, %3, %0 \n"
  80. "itt cs \n"
  81. "cmpcs %7, %4 \n"
  82. L("ldrcsh %2, [%4], #2 \n")
  83. U("ldrhcs %2, [%4], #2 \n")
  84. "rsb %0, %6, #256 \n"
  85. "smlabb %0, %5, %6, %0 \n"
  86. T("itttt cs \n")
  87. "rev16cs %2, %2 \n"
  88. T("lslcs %2, %2, %3 \n")
  89. T("orrcs %1, %1, %2 \n")
  90. A("orrcs %1, %1, %2, lsl %3 \n")
  91. "subcs %3, %3, #16 \n"
  92. "lsr %0, %0, #8 \n"
  93. "lsl %2, %0, #16 \n"
  94. : "=&r"(low), "+&r"(code_word), "=&r"(tmp),
  95. "+&r"(c->bits), "+&r"(c->buffer)
  96. : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift)
  97. : "cc");
  98. if (code_word >= tmp) {
  99. c->high = high - low;
  100. c->code_word = code_word - tmp;
  101. return 1;
  102. }
  103. c->high = low;
  104. c->code_word = code_word;
  105. return 0;
  106. }
  107. #endif
  108. #endif /* AVCODEC_ARM_VP56_ARITH_H */