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.

135 lines
4.1KB

  1. /*
  2. * Copyright (c) 2010 Mans Rullgard
  3. * Copyright (c) 2014 James Yu <james.yu@linaro.org>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <arm_neon.h>
  22. #include "config.h"
  23. #include "libavutil/cpu.h"
  24. #if ARCH_AARCH64
  25. # include "libavutil/aarch64/cpu.h"
  26. #elif ARCH_ARM
  27. # include "libavutil/arm/cpu.h"
  28. #endif
  29. #include "libavcodec/mpegvideo.h"
  30. static void inline ff_dct_unquantize_h263_neon(int qscale, int qadd, int nCoeffs,
  31. int16_t *block)
  32. {
  33. int16x8_t q0s16, q2s16, q3s16, q8s16, q10s16, q11s16, q13s16;
  34. int16x8_t q14s16, q15s16, qzs16;
  35. int16x4_t d0s16, d2s16, d3s16, dzs16;
  36. uint16x8_t q1u16, q9u16;
  37. uint16x4_t d1u16;
  38. dzs16 = vdup_n_s16(0);
  39. qzs16 = vdupq_n_s16(0);
  40. q15s16 = vdupq_n_s16(qscale << 1);
  41. q14s16 = vdupq_n_s16(qadd);
  42. q13s16 = vnegq_s16(q14s16);
  43. if (nCoeffs > 4) {
  44. for (; nCoeffs > 8; nCoeffs -= 16, block += 16) {
  45. q0s16 = vld1q_s16(block);
  46. q3s16 = vreinterpretq_s16_u16(vcltq_s16(q0s16, qzs16));
  47. q8s16 = vld1q_s16(block + 8);
  48. q1u16 = vceqq_s16(q0s16, qzs16);
  49. q2s16 = vmulq_s16(q0s16, q15s16);
  50. q11s16 = vreinterpretq_s16_u16(vcltq_s16(q8s16, qzs16));
  51. q10s16 = vmulq_s16(q8s16, q15s16);
  52. q3s16 = vbslq_s16(vreinterpretq_u16_s16(q3s16), q13s16, q14s16);
  53. q11s16 = vbslq_s16(vreinterpretq_u16_s16(q11s16), q13s16, q14s16);
  54. q2s16 = vaddq_s16(q2s16, q3s16);
  55. q9u16 = vceqq_s16(q8s16, qzs16);
  56. q10s16 = vaddq_s16(q10s16, q11s16);
  57. q0s16 = vbslq_s16(q1u16, q0s16, q2s16);
  58. q8s16 = vbslq_s16(q9u16, q8s16, q10s16);
  59. vst1q_s16(block, q0s16);
  60. vst1q_s16(block + 8, q8s16);
  61. }
  62. }
  63. if (nCoeffs <= 0)
  64. return;
  65. d0s16 = vld1_s16(block);
  66. d3s16 = vreinterpret_s16_u16(vclt_s16(d0s16, dzs16));
  67. d1u16 = vceq_s16(d0s16, dzs16);
  68. d2s16 = vmul_s16(d0s16, vget_high_s16(q15s16));
  69. d3s16 = vbsl_s16(vreinterpret_u16_s16(d3s16),
  70. vget_high_s16(q13s16), vget_high_s16(q14s16));
  71. d2s16 = vadd_s16(d2s16, d3s16);
  72. d0s16 = vbsl_s16(d1u16, d0s16, d2s16);
  73. vst1_s16(block, d0s16);
  74. }
  75. static void dct_unquantize_h263_inter_neon(MpegEncContext *s, int16_t *block,
  76. int n, int qscale)
  77. {
  78. int nCoeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
  79. int qadd = (qscale - 1) | 1;
  80. ff_dct_unquantize_h263_neon(qscale, qadd, nCoeffs + 1, block);
  81. }
  82. static void dct_unquantize_h263_intra_neon(MpegEncContext *s, int16_t *block,
  83. int n, int qscale)
  84. {
  85. int qadd;
  86. int nCoeffs, blk0;
  87. if (!s->h263_aic) {
  88. if (n < 4)
  89. block[0] *= s->y_dc_scale;
  90. else
  91. block[0] *= s->c_dc_scale;
  92. qadd = (qscale - 1) | 1;
  93. } else {
  94. qadd = 0;
  95. }
  96. if (s->ac_pred) {
  97. nCoeffs = 63;
  98. } else {
  99. nCoeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
  100. if (nCoeffs <= 0)
  101. return;
  102. }
  103. blk0 = block[0];
  104. ff_dct_unquantize_h263_neon(qscale, qadd, nCoeffs + 1, block);
  105. block[0] = blk0;
  106. }
  107. av_cold void ff_mpv_common_init_neon(MpegEncContext *s)
  108. {
  109. int cpu_flags = av_get_cpu_flags();
  110. if (have_neon(cpu_flags)) {
  111. s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_neon;
  112. s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_neon;
  113. }
  114. }