FFmpeg
Loading...
Searching...
No Matches
mpegvideo_altivec.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002 Dieter Shirley
3 *
4 * dct_unquantize_h263_altivec:
5 * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <stdlib.h>
25#include <stdio.h>
26
27#include "config.h"
28
30#include "libavutil/avassert.h"
33
36
37#include "mpegvideo_altivec.h"
38
39/* AltiVec version of dct_unquantize_h263
40 this code assumes `block' is 16 bytes-aligned */
42void dct_unquantize_h263_altivec(int16_t *block, int nb_coeffs, int qadd, int qmul)
43{
44 register const vector signed short vczero = (const vector signed short)vec_splat_s16(0);
45 DECLARE_ALIGNED(16, short, qmul8) = qmul;
46 DECLARE_ALIGNED(16, short, qadd8) = qadd;
47 register vector signed short blockv, qmulv, qaddv, nqaddv, temp1;
48 register vector bool short blockv_null, blockv_neg;
49
50 qmulv = vec_splat((vec_s16)vec_lde(0, &qmul8), 0);
51 qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0);
52 nqaddv = vec_sub(vczero, qaddv);
53
54 // vectorize all the 16 bytes-aligned blocks
55 // of 8 elements
56 for (register int j = 0; j <= nb_coeffs; j += 8) {
57 blockv = vec_ld(j << 1, block);
58 blockv_neg = vec_cmplt(blockv, vczero);
59 blockv_null = vec_cmpeq(blockv, vczero);
60 // choose between +qadd or -qadd as the third operand
61 temp1 = vec_sel(qaddv, nqaddv, blockv_neg);
62 // multiply & add (block{i,i+7} * qmul [+-] qadd)
63 temp1 = vec_mladd(blockv, qmulv, temp1);
64 // put 0 where block[{i,i+7} used to have 0
65 blockv = vec_sel(temp1, blockv, blockv_null);
66 vec_st(blockv, j << 1, block);
67 }
68}
69
70static void dct_unquantize_h263_intra_altivec(const MPVContext *s,
71 int16_t *block, int n, int qscale)
72{
73 int qadd = (qscale - 1) | 1;
74 int qmul = qscale << 1;
75 int block0 = block[0];
76 if (!s->h263_aic) {
77 block0 *= n < 4 ? s->y_dc_scale : s->c_dc_scale;
78 } else
79 qadd = 0;
80 int nb_coeffs = s->ac_pred ? 63 : s->intra_scantable.raster_end[s->block_last_index[n]];
81
82 dct_unquantize_h263_altivec(block, nb_coeffs, qadd, qmul);
83
84 // cheat. this avoid special-casing the first iteration
85 block[0] = block0;
86}
87
88static void dct_unquantize_h263_inter_altivec(const MPVContext *s,
89 int16_t *block, int n, int qscale)
90{
91 int qadd = (qscale - 1) | 1;
92 int qmul = qscale << 1;
93 av_assert2(s->block_last_index[n]>=0);
94 int nb_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
95
96 dct_unquantize_h263_altivec(block, nb_coeffs, qadd, qmul);
97}
98
100{
101 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_altivec;
102 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_altivec;
103}
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define s(width, name)
Definition cbs_vp9.c:198
static int16_t block[64]
Definition dct.c:125
Macro definitions for various function/variable attributes.
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
mpegvideo header.
static void dct_unquantize_h263_inter_altivec(const MPVContext *s, int16_t *block, int n, int qscale)
av_cold void ff_mpv_unquantize_init_altivec(MPVUnquantDSPContext *s, int bitexact)
static av_always_inline void dct_unquantize_h263_altivec(int16_t *block, int nb_coeffs, int qadd, int qmul)
static void dct_unquantize_h263_intra_altivec(const MPVContext *s, int16_t *block, int n, int qscale)
Contains misc utility macros and inline functions.
#define vec_s16