]> git.sesse.net Git - ffmpeg/blob - libavcodec/alpha/mpegvideo_alpha.c
023aef9143f3314d7fb4ef9b091ff14b68c3c2e0
[ffmpeg] / libavcodec / alpha / mpegvideo_alpha.c
1 /*
2  * Alpha optimized DSP utils
3  * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/attributes.h"
23 #include "libavcodec/dsputil.h"
24 #include "libavcodec/mpegvideo.h"
25 #include "asm.h"
26
27 static void dct_unquantize_h263_axp(int16_t *block, int n_coeffs,
28                                     uint64_t qscale, uint64_t qadd)
29 {
30     uint64_t qmul = qscale << 1;
31     uint64_t correction = WORD_VEC(qmul * 255 >> 8);
32     int i;
33
34     qadd = WORD_VEC(qadd);
35
36     for(i = 0; i <= n_coeffs; block += 4, i += 4) {
37         uint64_t levels, negmask, zeros, add, sub;
38
39         levels = ldq(block);
40         if (levels == 0)
41             continue;
42
43 #ifdef __alpha_max__
44         /* I don't think the speed difference justifies runtime
45            detection.  */
46         negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
47         negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
48 #else
49         negmask = cmpbge(WORD_VEC(0x7fff), levels);
50         negmask &= (negmask >> 1) | (1 << 7);
51         negmask = zap(-1, negmask);
52 #endif
53
54         zeros = cmpbge(0, levels);
55         zeros &= zeros >> 1;
56         /* zeros |= zeros << 1 is not needed since qadd <= 255, so
57            zapping the lower byte suffices.  */
58
59         levels *= qmul;
60         levels -= correction & (negmask << 16);
61
62         add = qadd & ~negmask;
63         sub = qadd &  negmask;
64         /* Set qadd to 0 for levels == 0.  */
65         add = zap(add, zeros);
66         levels += add;
67         levels -= sub;
68
69         stq(levels, block);
70     }
71 }
72
73 static void dct_unquantize_h263_intra_axp(MpegEncContext *s, int16_t *block,
74                                     int n, int qscale)
75 {
76     int n_coeffs;
77     uint64_t qadd;
78     int16_t block0 = block[0];
79
80     if (!s->h263_aic) {
81         if (n < 4)
82             block0 *= s->y_dc_scale;
83         else
84             block0 *= s->c_dc_scale;
85         qadd = (qscale - 1) | 1;
86     } else {
87         qadd = 0;
88     }
89
90     if(s->ac_pred)
91         n_coeffs = 63;
92     else
93         n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
94
95     dct_unquantize_h263_axp(block, n_coeffs, qscale, qadd);
96
97     block[0] = block0;
98 }
99
100 static void dct_unquantize_h263_inter_axp(MpegEncContext *s, int16_t *block,
101                                     int n, int qscale)
102 {
103     int n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
104     dct_unquantize_h263_axp(block, n_coeffs, qscale, (qscale - 1) | 1);
105 }
106
107 av_cold void ff_MPV_common_init_axp(MpegEncContext *s)
108 {
109     s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_axp;
110     s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_axp;
111 }