2 * Copyright (c) 2007 Luca Barbato <lu_zero@gentoo.org>
4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * miscellaneous integer operations
31 #include "libavutil/attributes.h"
32 #include "libavutil/ppc/types_altivec.h"
33 #include "libavutil/ppc/util_altivec.h"
34 #include "libavcodec/dsputil.h"
35 #include "dsputil_altivec.h"
37 static int32_t scalarproduct_int16_altivec(const int16_t *v1, const int16_t *v2,
42 register vec_s16 vec1;
43 register vec_s32 res = vec_splat_s32(0), t;
46 for (i = 0; i < order; i += 8) {
47 vec1 = vec_unaligned_load(v1);
48 t = vec_msum(vec1, vec_ld(0, v2), zero_s32v);
49 res = vec_sums(t, res);
53 res = vec_splat(res, 3);
54 vec_ste(res, 0, &ires);
59 static int32_t scalarproduct_and_madd_int16_altivec(int16_t *v1,
65 vec_s16 *pv1 = (vec_s16 *) v1;
66 register vec_s16 muls = { mul, mul, mul, mul, mul, mul, mul, mul };
67 register vec_s16 t0, t1, i0, i1, i4;
68 register vec_s16 i2 = vec_ld(0, v2), i3 = vec_ld(0, v3);
69 register vec_s32 res = zero_s32v;
70 register vec_u8 align = vec_lvsl(0, v2);
76 t0 = vec_perm(i2, i1, align);
78 t1 = vec_perm(i1, i2, align);
81 res = vec_msum(t0, i0, res);
82 res = vec_msum(t1, i1, res);
84 t0 = vec_perm(i3, i4, align);
86 t1 = vec_perm(i4, i3, align);
87 pv1[0] = vec_mladd(t0, muls, i0);
88 pv1[1] = vec_mladd(t1, muls, i1);
93 res = vec_splat(vec_sums(res, zero_s32v), 3);
94 vec_ste(res, 0, &ires);
99 av_cold void ff_int_init_altivec(DSPContext *c, AVCodecContext *avctx)
101 c->scalarproduct_int16 = scalarproduct_int16_altivec;
103 c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_altivec;