2 * Alpha optimized DSP utils
3 * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
5 * This file is part of Libav.
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.
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.
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
22 #include "libavutil/attributes.h"
23 #include "libavcodec/dsputil.h"
24 #include "libavcodec/mpegvideo.h"
27 static void dct_unquantize_h263_axp(int16_t *block, int n_coeffs,
28 uint64_t qscale, uint64_t qadd)
30 uint64_t qmul = qscale << 1;
31 uint64_t correction = WORD_VEC(qmul * 255 >> 8);
34 qadd = WORD_VEC(qadd);
36 for(i = 0; i <= n_coeffs; block += 4, i += 4) {
37 uint64_t levels, negmask, zeros, add, sub;
44 /* I don't think the speed difference justifies runtime
46 negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
47 negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
49 negmask = cmpbge(WORD_VEC(0x7fff), levels);
50 negmask &= (negmask >> 1) | (1 << 7);
51 negmask = zap(-1, negmask);
54 zeros = cmpbge(0, levels);
56 /* zeros |= zeros << 1 is not needed since qadd <= 255, so
57 zapping the lower byte suffices. */
60 levels -= correction & (negmask << 16);
62 add = qadd & ~negmask;
64 /* Set qadd to 0 for levels == 0. */
65 add = zap(add, zeros);
73 static void dct_unquantize_h263_intra_axp(MpegEncContext *s, int16_t *block,
78 int16_t block0 = block[0];
82 block0 *= s->y_dc_scale;
84 block0 *= s->c_dc_scale;
85 qadd = (qscale - 1) | 1;
93 n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
95 dct_unquantize_h263_axp(block, n_coeffs, qscale, qadd);
100 static void dct_unquantize_h263_inter_axp(MpegEncContext *s, int16_t *block,
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);
107 av_cold void ff_MPV_common_init_axp(MpegEncContext *s)
109 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_axp;
110 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_axp;