c syntax update patch by (mru at users dot sourceforge dot net (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
2dbe7ec8 24static void dct_unquantize_h263_axp(MpegEncContext *s, DCTELEM *block,
e0580f8c 25 int n, int qscale)
1e98dffb 26{
e0580f8c
FH
27 int i, n_coeffs;
28 uint64_t qmul, qadd;
29 uint64_t correction;
30 DCTELEM *orig_block = block;
31 DCTELEM block0;
db42e13b 32
1e98dffb 33 if (s->mb_intra) {
e0580f8c
FH
34 if (!s->h263_aic) {
35 if (n < 4)
36 block0 = block[0] * s->y_dc_scale;
37 else
38 block0 = block[0] * s->c_dc_scale;
39 }
40 n_coeffs = 64; // does not always use zigzag table
1e98dffb 41 } else {
6c383066 42 n_coeffs = s->intra_scantable.raster_end[s->block_last_index[n]];
1e98dffb 43 }
e0580f8c
FH
44
45 qmul = qscale << 1;
1e98dffb 46 qadd = WORD_VEC((qscale - 1) | 1);
e0580f8c
FH
47 /* This mask kills spill from negative subwords to the next subword. */
48 correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
49
50 for(i = 0; i < n_coeffs; block += 4, i += 4) {
51 uint64_t levels, negmask, zeros, add;
52
53 levels = ldq(block);
54 if (levels == 0)
55 continue;
56
2dbe7ec8
FH
57#ifdef __alpha_max__
58 /* I don't think the speed difference justifies runtime
59 detection. */
60 ASM_ACCEPT_MVI;
e0580f8c
FH
61 negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
62 negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
2dbe7ec8
FH
63#else
64 negmask = cmpbge(WORD_VEC(0x7fff), levels);
65 negmask &= (negmask >> 1) | (1 << 7);
66 negmask = zap(-1, negmask);
67#endif
e0580f8c
FH
68
69 zeros = cmpbge(0, levels);
70 zeros &= zeros >> 1;
71 /* zeros |= zeros << 1 is not needed since qadd <= 255, so
72 zapping the lower byte suffices. */
73
74 levels *= qmul;
75 levels -= correction & (negmask << 16);
76
77 /* Negate qadd for negative levels. */
78 add = qadd ^ negmask;
79 add += WORD_VEC(0x0001) & negmask;
80 /* Set qadd to 0 for levels == 0. */
81 add = zap(add, zeros);
82
83 levels += add;
84
85 stq(levels, block);
86 }
87
88 if (s->mb_intra && !s->h263_aic)
89 orig_block[0] = block0;
1e98dffb
NK
90}
91
92void MPV_common_init_axp(MpegEncContext *s)
93{
6c383066
FH
94 /* disabled for now, buggy */
95 //s->dct_unquantize_h263 = dct_unquantize_h263_axp;
1e98dffb 96}