1/*
2 *  Copyright (c) 2010 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 "vpx_config.h"
12#include "vp8_rtcd.h"
13#include "vp8/common/blockd.h"
14#include "vpx_mem/vpx_mem.h"
15
16extern void vp8_dequantize_b_impl_mmx(short *sq, short *dq, short *q);
17
18void vp8_dequantize_b_mmx(BLOCKD *d, short *DQC)
19{
20    short *sq = (short *) d->qcoeff;
21    short *dq = (short *) d->dqcoeff;
22
23    vp8_dequantize_b_impl_mmx(sq, dq, DQC);
24}
25
26void vp8_dequant_idct_add_y_block_mmx
27            (short *q, short *dq,
28             unsigned char *dst, int stride, char *eobs)
29{
30    int i;
31
32    for (i = 0; i < 4; i++)
33    {
34        if (eobs[0] > 1)
35            vp8_dequant_idct_add_mmx (q, dq, dst, stride);
36        else if (eobs[0] == 1)
37        {
38            vp8_dc_only_idct_add_mmx (q[0]*dq[0], dst, stride, dst, stride);
39            vpx_memset(q, 0, 2 * sizeof(q[0]));
40        }
41
42        if (eobs[1] > 1)
43            vp8_dequant_idct_add_mmx (q+16, dq, dst+4, stride);
44        else if (eobs[1] == 1)
45        {
46            vp8_dc_only_idct_add_mmx (q[16]*dq[0], dst+4, stride,
47                                      dst+4, stride);
48            vpx_memset(q + 16, 0, 2 * sizeof(q[0]));
49        }
50
51        if (eobs[2] > 1)
52            vp8_dequant_idct_add_mmx (q+32, dq, dst+8, stride);
53        else if (eobs[2] == 1)
54        {
55            vp8_dc_only_idct_add_mmx (q[32]*dq[0], dst+8, stride,
56                                      dst+8, stride);
57            vpx_memset(q + 32, 0, 2 * sizeof(q[0]));
58        }
59
60        if (eobs[3] > 1)
61            vp8_dequant_idct_add_mmx (q+48, dq, dst+12, stride);
62        else if (eobs[3] == 1)
63        {
64            vp8_dc_only_idct_add_mmx (q[48]*dq[0], dst+12, stride,
65                                      dst+12, stride);
66            vpx_memset(q + 48, 0, 2 * sizeof(q[0]));
67        }
68
69        q    += 64;
70        dst  += 4*stride;
71        eobs += 4;
72    }
73}
74
75void vp8_dequant_idct_add_uv_block_mmx
76            (short *q, short *dq,
77             unsigned char *dstu, unsigned char *dstv, int stride, char *eobs)
78{
79    int i;
80
81    for (i = 0; i < 2; i++)
82    {
83        if (eobs[0] > 1)
84            vp8_dequant_idct_add_mmx (q, dq, dstu, stride);
85        else if (eobs[0] == 1)
86        {
87            vp8_dc_only_idct_add_mmx (q[0]*dq[0], dstu, stride, dstu, stride);
88            vpx_memset(q, 0, 2 * sizeof(q[0]));
89        }
90
91        if (eobs[1] > 1)
92            vp8_dequant_idct_add_mmx (q+16, dq, dstu+4, stride);
93        else if (eobs[1] == 1)
94        {
95            vp8_dc_only_idct_add_mmx (q[16]*dq[0], dstu+4, stride,
96                                      dstu+4, stride);
97            vpx_memset(q + 16, 0, 2 * sizeof(q[0]));
98        }
99
100        q    += 32;
101        dstu += 4*stride;
102        eobs += 2;
103    }
104
105    for (i = 0; i < 2; i++)
106    {
107        if (eobs[0] > 1)
108            vp8_dequant_idct_add_mmx (q, dq, dstv, stride);
109        else if (eobs[0] == 1)
110        {
111            vp8_dc_only_idct_add_mmx (q[0]*dq[0], dstv, stride, dstv, stride);
112            vpx_memset(q, 0, 2 * sizeof(q[0]));
113        }
114
115        if (eobs[1] > 1)
116            vp8_dequant_idct_add_mmx (q+16, dq, dstv+4, stride);
117        else if (eobs[1] == 1)
118        {
119            vp8_dc_only_idct_add_mmx (q[16]*dq[0], dstv+4, stride,
120                                      dstv+4, stride);
121            vpx_memset(q + 16, 0, 2 * sizeof(q[0]));
122        }
123
124        q    += 32;
125        dstv += 4*stride;
126        eobs += 2;
127    }
128}
129