]> git.sesse.net Git - ffmpeg/blob - libavcodec/alpha/mpegvideo_alpha.c
350b53f62f7b6f2feb83e5ccbb051aa79598d9e3
[ffmpeg] / libavcodec / alpha / mpegvideo_alpha.c
1 /*
2  * Alpha optimized DSP utils
3  * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
4  *
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.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
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
18  */
19
20 #include "asm.h"
21 #include "../dsputil.h"
22 #include "../mpegvideo.h"
23
24 extern void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block);
25 extern void simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block);
26   
27 static void dct_unquantize_h263_axp(MpegEncContext *s, DCTELEM *block,
28                                     int n, int qscale)
29 {
30     int i, n_coeffs;
31     uint64_t qmul, qadd;
32     uint64_t correction;
33     DCTELEM *orig_block = block;
34     DCTELEM block0;
35
36     qadd = WORD_VEC((qscale - 1) | 1);
37     qmul = qscale << 1;
38     /* This mask kills spill from negative subwords to the next subword.  */ 
39     correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
40
41     if (s->mb_intra) {
42         if (!s->h263_aic) {
43             if (n < 4) 
44                 block0 = block[0] * s->y_dc_scale;
45             else
46                 block0 = block[0] * s->c_dc_scale;
47         } else {
48             qadd = 0;
49         }
50         n_coeffs = 63; // does not always use zigzag table 
51     } else {
52         n_coeffs = s->intra_scantable.raster_end[s->block_last_index[n]];
53     }
54
55     for(i = 0; i <= n_coeffs; block += 4, i += 4) {
56         uint64_t levels, negmask, zeros, add;
57
58         levels = ldq(block);
59         if (levels == 0)
60             continue;
61
62 #ifdef __alpha_max__
63         /* I don't think the speed difference justifies runtime
64            detection.  */
65         ASM_ACCEPT_MVI;
66         negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
67         negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
68 #else
69         negmask = cmpbge(WORD_VEC(0x7fff), levels);
70         negmask &= (negmask >> 1) | (1 << 7);
71         negmask = zap(-1, negmask);
72 #endif
73
74         zeros = cmpbge(0, levels);
75         zeros &= zeros >> 1;
76         /* zeros |= zeros << 1 is not needed since qadd <= 255, so
77            zapping the lower byte suffices.  */
78
79         levels *= qmul;
80         levels -= correction & (negmask << 16);
81
82         /* Negate qadd for negative levels.  */
83         add = qadd ^ negmask;
84         add += WORD_VEC(0x0001) & negmask;
85         /* Set qadd to 0 for levels == 0.  */
86         add = zap(add, zeros);
87
88         levels += add;
89
90         stq(levels, block);
91     }
92
93     if (s->mb_intra && !s->h263_aic)
94         orig_block[0] = block0;
95 }
96
97 void MPV_common_init_axp(MpegEncContext *s)
98 {
99     s->dct_unquantize_h263 = dct_unquantize_h263_axp;
100     s->idct_put = simple_idct_put_axp;
101     s->idct_add = simple_idct_add_axp;
102 }