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.

114 lines
3.9KB

  1. /*
  2. * Copyright (C) 2010 Mans Rullgard <mans@mansr.com>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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 HAVE_ARMV6 && HAVE_INLINE_ASM
  30. #define vp56_rac_get_prob vp56_rac_get_prob_armv6
  31. static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
  32. {
  33. unsigned shift = ff_vp56_norm_shift[c->high];
  34. unsigned code_word = c->code_word << shift;
  35. unsigned high = c->high << shift;
  36. unsigned bit;
  37. __asm__ ("adds %3, %3, %0 \n"
  38. "itt cs \n"
  39. "cmpcs %7, %4 \n"
  40. A("ldrcsh %2, [%4], #2 \n")
  41. T("ldrhcs %2, [%4], #2 \n")
  42. "rsb %0, %6, #256 \n"
  43. "smlabb %0, %5, %6, %0 \n"
  44. T("itttt cs \n")
  45. "rev16cs %2, %2 \n"
  46. T("lslcs %2, %2, %3 \n")
  47. T("orrcs %1, %1, %2 \n")
  48. A("orrcs %1, %1, %2, lsl %3 \n")
  49. "subcs %3, %3, #16 \n"
  50. "lsr %0, %0, #8 \n"
  51. "cmp %1, %0, lsl #16 \n"
  52. "ittte ge \n"
  53. "subge %1, %1, %0, lsl #16 \n"
  54. "subge %0, %5, %0 \n"
  55. "movge %2, #1 \n"
  56. "movlt %2, #0 \n"
  57. : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit),
  58. "+&r"(c->bits), "+&r"(c->buffer)
  59. : "r"(high), "r"(pr), "r"(c->end - 1),
  60. "0"(shift), "1"(code_word)
  61. : "cc");
  62. return bit;
  63. }
  64. #define vp56_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
  65. static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
  66. {
  67. unsigned shift = ff_vp56_norm_shift[c->high];
  68. unsigned code_word = c->code_word << shift;
  69. unsigned high = c->high << shift;
  70. unsigned low;
  71. unsigned tmp;
  72. __asm__ ("adds %3, %3, %0 \n"
  73. "itt cs \n"
  74. "cmpcs %7, %4 \n"
  75. A("ldrcsh %2, [%4], #2 \n")
  76. T("ldrhcs %2, [%4], #2 \n")
  77. "rsb %0, %6, #256 \n"
  78. "smlabb %0, %5, %6, %0 \n"
  79. T("itttt cs \n")
  80. "rev16cs %2, %2 \n"
  81. T("lslcs %2, %2, %3 \n")
  82. T("orrcs %1, %1, %2 \n")
  83. A("orrcs %1, %1, %2, lsl %3 \n")
  84. "subcs %3, %3, #16 \n"
  85. "lsr %0, %0, #8 \n"
  86. "lsl %2, %0, #16 \n"
  87. : "=&r"(low), "+&r"(code_word), "=&r"(tmp),
  88. "+&r"(c->bits), "+&r"(c->buffer)
  89. : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift)
  90. : "cc");
  91. if (code_word >= tmp) {
  92. c->high = high - low;
  93. c->code_word = code_word - tmp;
  94. return 1;
  95. }
  96. c->high = low;
  97. c->code_word = code_word;
  98. return 0;
  99. }
  100. #endif
  101. #endif /* AVCODEC_ARM_VP56_ARITH_H */