Update and activate dct_unquantize_h263_mvi. Thanks to Måns Rullgård
[libav.git] / libavcodec / alpha / mpegvideo_alpha.c
CommitLineData
1e98dffb
NK
1/*
2 * Alpha optimized DSP utils
3 * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
4 *
ff4ec49e
FB
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
1e98dffb 9 *
ff4ec49e 10 * This library is distributed in the hope that it will be useful,
1e98dffb 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff4ec49e
FB
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
1e98dffb 14 *
ff4ec49e
FB
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1e98dffb
NK
18 */
19
20#include "asm.h"
21#include "../dsputil.h"
22#include "../mpegvideo.h"
23
24extern UINT8 zigzag_end[64];
25
e0580f8c
FH
26static void dct_unquantize_h263_mvi(MpegEncContext *s, DCTELEM *block,
27 int n, int qscale)
1e98dffb 28{
e0580f8c
FH
29 int i, n_coeffs;
30 uint64_t qmul, qadd;
31 uint64_t correction;
32 DCTELEM *orig_block = block;
33 DCTELEM block0;
db42e13b
FH
34
35 ASM_ACCEPT_MVI;
e0580f8c 36
1e98dffb 37 if (s->mb_intra) {
e0580f8c
FH
38 if (!s->h263_aic) {
39 if (n < 4)
40 block0 = block[0] * s->y_dc_scale;
41 else
42 block0 = block[0] * s->c_dc_scale;
43 }
44 n_coeffs = 64; // does not always use zigzag table
1e98dffb 45 } else {
e0580f8c 46 n_coeffs = zigzag_end[s->block_last_index[n]];
1e98dffb 47 }
e0580f8c
FH
48
49 qmul = qscale << 1;
1e98dffb 50 qadd = WORD_VEC((qscale - 1) | 1);
e0580f8c
FH
51 /* This mask kills spill from negative subwords to the next subword. */
52 correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
53
54 for(i = 0; i < n_coeffs; block += 4, i += 4) {
55 uint64_t levels, negmask, zeros, add;
56
57 levels = ldq(block);
58 if (levels == 0)
59 continue;
60
61 negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
62 negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
63
64 zeros = cmpbge(0, levels);
65 zeros &= zeros >> 1;
66 /* zeros |= zeros << 1 is not needed since qadd <= 255, so
67 zapping the lower byte suffices. */
68
69 levels *= qmul;
70 levels -= correction & (negmask << 16);
71
72 /* Negate qadd for negative levels. */
73 add = qadd ^ negmask;
74 add += WORD_VEC(0x0001) & negmask;
75 /* Set qadd to 0 for levels == 0. */
76 add = zap(add, zeros);
77
78 levels += add;
79
80 stq(levels, block);
81 }
82
83 if (s->mb_intra && !s->h263_aic)
84 orig_block[0] = block0;
1e98dffb
NK
85}
86
87void MPV_common_init_axp(MpegEncContext *s)
88{
89 if (amask(AMASK_MVI) == 0) {
e0580f8c 90 s->dct_unquantize_h263 = dct_unquantize_h263_mvi;
1e98dffb
NK
91 }
92}