1/*
2 *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <arm_neon.h>
12
13void idct_dequant_0_2x_neon(
14        int16_t *q,
15        int16_t dq,
16        unsigned char *dst,
17        int stride) {
18    unsigned char *dst0;
19    int i, a0, a1;
20    int16x8x2_t q2Add;
21    int32x2_t d2s32, d4s32;
22    uint8x8_t d2u8, d4u8;
23    uint16x8_t q1u16, q2u16;
24
25    a0 = ((q[0] * dq) + 4) >> 3;
26    a1 = ((q[16] * dq) + 4) >> 3;
27    q[0] = q[16] = 0;
28    q2Add.val[0] = vdupq_n_s16((int16_t)a0);
29    q2Add.val[1] = vdupq_n_s16((int16_t)a1);
30
31    for (i = 0; i < 2; i++, dst += 4) {
32        dst0 = dst;
33        d2s32 = vld1_lane_s32((const int32_t *)dst0, d2s32, 0);
34        dst0 += stride;
35        d2s32 = vld1_lane_s32((const int32_t *)dst0, d2s32, 1);
36        dst0 += stride;
37        d4s32 = vld1_lane_s32((const int32_t *)dst0, d4s32, 0);
38        dst0 += stride;
39        d4s32 = vld1_lane_s32((const int32_t *)dst0, d4s32, 1);
40
41        q1u16 = vaddw_u8(vreinterpretq_u16_s16(q2Add.val[i]),
42                         vreinterpret_u8_s32(d2s32));
43        q2u16 = vaddw_u8(vreinterpretq_u16_s16(q2Add.val[i]),
44                         vreinterpret_u8_s32(d4s32));
45
46        d2u8 = vqmovun_s16(vreinterpretq_s16_u16(q1u16));
47        d4u8 = vqmovun_s16(vreinterpretq_s16_u16(q2u16));
48
49        d2s32 = vreinterpret_s32_u8(d2u8);
50        d4s32 = vreinterpret_s32_u8(d4u8);
51
52        dst0 = dst;
53        vst1_lane_s32((int32_t *)dst0, d2s32, 0);
54        dst0 += stride;
55        vst1_lane_s32((int32_t *)dst0, d2s32, 1);
56        dst0 += stride;
57        vst1_lane_s32((int32_t *)dst0, d4s32, 0);
58        dst0 += stride;
59        vst1_lane_s32((int32_t *)dst0, d4s32, 1);
60    }
61    return;
62}
63