cabac.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Loongson SIMD optimized h264chroma
  3. *
  4. * Copyright (c) 2018 Loongson Technology Corporation Limited
  5. * Copyright (c) 2018 Shiyou Yin <yinshiyou-hf@loongson.cn>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef AVCODEC_MIPS_CABAC_H
  24. #define AVCODEC_MIPS_CABAC_H
  25. #include "libavcodec/cabac.h"
  26. #include "libavutil/mips/asmdefs.h"
  27. #include "config.h"
  28. #define get_cabac_inline get_cabac_inline_mips
  29. static av_always_inline int get_cabac_inline_mips(CABACContext *c,
  30. uint8_t * const state){
  31. mips_reg tmp0, tmp1, tmp2, bit;
  32. __asm__ volatile (
  33. "lbu %[bit], 0(%[state]) \n\t"
  34. "and %[tmp0], %[c_range], 0xC0 \n\t"
  35. PTR_ADDU "%[tmp0], %[tmp0], %[tmp0] \n\t"
  36. PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t"
  37. PTR_ADDU "%[tmp0], %[tmp0], %[bit] \n\t"
  38. /* tmp1: RangeLPS */
  39. "lbu %[tmp1], %[lps_off](%[tmp0]) \n\t"
  40. PTR_SUBU "%[c_range], %[c_range], %[tmp1] \n\t"
  41. PTR_SLL "%[tmp0], %[c_range], 0x11 \n\t"
  42. PTR_SUBU "%[tmp0], %[tmp0], %[c_low] \n\t"
  43. /* tmp2: lps_mask */
  44. PTR_SRA "%[tmp2], %[tmp0], 0x1F \n\t"
  45. /* If tmp0 < 0, lps_mask == 0xffffffff*/
  46. /* If tmp0 >= 0, lps_mask == 0x00000000*/
  47. "beqz %[tmp2], 1f \n\t"
  48. PTR_SLL "%[tmp0], %[c_range], 0x11 \n\t"
  49. PTR_SUBU "%[c_low], %[c_low], %[tmp0] \n\t"
  50. PTR_SUBU "%[tmp0], %[tmp1], %[c_range] \n\t"
  51. PTR_ADDU "%[c_range], %[c_range], %[tmp0] \n\t"
  52. "xor %[bit], %[bit], %[tmp2] \n\t"
  53. "1: \n\t"
  54. /* tmp1: *state */
  55. PTR_ADDU "%[tmp0], %[tables], %[bit] \n\t"
  56. "lbu %[tmp1], %[mlps_off](%[tmp0]) \n\t"
  57. /* tmp2: lps_mask */
  58. PTR_ADDU "%[tmp0], %[tables], %[c_range] \n\t"
  59. "lbu %[tmp2], %[norm_off](%[tmp0]) \n\t"
  60. "sb %[tmp1], 0(%[state]) \n\t"
  61. "and %[bit], %[bit], 0x01 \n\t"
  62. PTR_SLL "%[c_range], %[c_range], %[tmp2] \n\t"
  63. PTR_SLL "%[c_low], %[c_low], %[tmp2] \n\t"
  64. "and %[tmp0], %[c_low], %[cabac_mask] \n\t"
  65. "bnez %[tmp0], 1f \n\t"
  66. PTR_ADDIU "%[tmp0], %[c_low], -0x01 \n\t"
  67. "xor %[tmp0], %[c_low], %[tmp0] \n\t"
  68. PTR_SRA "%[tmp0], %[tmp0], 0x0f \n\t"
  69. PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t"
  70. "lbu %[tmp2], %[norm_off](%[tmp0]) \n\t"
  71. #if CABAC_BITS == 16
  72. "lbu %[tmp0], 0(%[c_bytestream]) \n\t"
  73. "lbu %[tmp1], 1(%[c_bytestream]) \n\t"
  74. PTR_SLL "%[tmp0], %[tmp0], 0x09 \n\t"
  75. PTR_SLL "%[tmp1], %[tmp1], 0x01 \n\t"
  76. PTR_ADDU "%[tmp0], %[tmp0], %[tmp1] \n\t"
  77. #else
  78. "lbu %[tmp0], 0(%[c_bytestream]) \n\t"
  79. PTR_SLL "%[tmp0], %[tmp0], 0x01 \n\t"
  80. #endif
  81. PTR_SUBU "%[tmp0], %[tmp0], %[cabac_mask] \n\t"
  82. "li %[tmp1], 0x07 \n\t"
  83. PTR_SUBU "%[tmp1], %[tmp1], %[tmp2] \n\t"
  84. PTR_SLL "%[tmp0], %[tmp0], %[tmp1] \n\t"
  85. PTR_ADDU "%[c_low], %[c_low], %[tmp0] \n\t"
  86. #if !UNCHECKED_BITSTREAM_READER
  87. "bge %[c_bytestream], %[c_bytestream_end], 1f \n\t"
  88. #endif
  89. PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0X02 \n\t"
  90. "1: \n\t"
  91. : [bit]"=&r"(bit), [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2),
  92. [c_range]"+&r"(c->range), [c_low]"+&r"(c->low),
  93. [c_bytestream]"+&r"(c->bytestream)
  94. : [state]"r"(state), [tables]"r"(ff_h264_cabac_tables),
  95. #if !UNCHECKED_BITSTREAM_READER
  96. [c_bytestream_end]"r"(c->bytestream_end),
  97. #endif
  98. [lps_off]"i"(H264_LPS_RANGE_OFFSET),
  99. [mlps_off]"i"(H264_MLPS_STATE_OFFSET + 128),
  100. [norm_off]"i"(H264_NORM_SHIFT_OFFSET),
  101. [cabac_mask]"r"(CABAC_MASK)
  102. : "memory"
  103. );
  104. return bit;
  105. }
  106. #endif /* AVCODEC_MIPS_CABAC_H */