1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2012
3cabdff1aSopenharmony_ci *      MIPS Technologies, Inc., California.
4cabdff1aSopenharmony_ci *
5cabdff1aSopenharmony_ci * Redistribution and use in source and binary forms, with or without
6cabdff1aSopenharmony_ci * modification, are permitted provided that the following conditions
7cabdff1aSopenharmony_ci * are met:
8cabdff1aSopenharmony_ci * 1. Redistributions of source code must retain the above copyright
9cabdff1aSopenharmony_ci *    notice, this list of conditions and the following disclaimer.
10cabdff1aSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
11cabdff1aSopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
12cabdff1aSopenharmony_ci *    documentation and/or other materials provided with the distribution.
13cabdff1aSopenharmony_ci * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
14cabdff1aSopenharmony_ci *    contributors may be used to endorse or promote products derived from
15cabdff1aSopenharmony_ci *    this software without specific prior written permission.
16cabdff1aSopenharmony_ci *
17cabdff1aSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
18cabdff1aSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19cabdff1aSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20cabdff1aSopenharmony_ci * ARE DISCLAIMED.  IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
21cabdff1aSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22cabdff1aSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23cabdff1aSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24cabdff1aSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25cabdff1aSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26cabdff1aSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27cabdff1aSopenharmony_ci * SUCH DAMAGE.
28cabdff1aSopenharmony_ci *
29cabdff1aSopenharmony_ci * Author:  Nedeljko Babic (nbabic@mips.com)
30cabdff1aSopenharmony_ci *
31cabdff1aSopenharmony_ci * adaptive and fixed codebook vector operations for ACELP-based codecs
32cabdff1aSopenharmony_ci * optimized for MIPS
33cabdff1aSopenharmony_ci *
34cabdff1aSopenharmony_ci * This file is part of FFmpeg.
35cabdff1aSopenharmony_ci *
36cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
37cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
38cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
39cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
40cabdff1aSopenharmony_ci *
41cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
42cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
43cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
44cabdff1aSopenharmony_ci * Lesser General Public License for more details.
45cabdff1aSopenharmony_ci *
46cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
47cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
48cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
49cabdff1aSopenharmony_ci */
50cabdff1aSopenharmony_ci
51cabdff1aSopenharmony_ci/**
52cabdff1aSopenharmony_ci * @file
53cabdff1aSopenharmony_ci * Reference: libavcodec/acelp_vectors.c
54cabdff1aSopenharmony_ci */
55cabdff1aSopenharmony_ci#include "config.h"
56cabdff1aSopenharmony_ci#include "libavcodec/acelp_vectors.h"
57cabdff1aSopenharmony_ci#include "libavutil/mips/asmdefs.h"
58cabdff1aSopenharmony_ci
59cabdff1aSopenharmony_ci#if HAVE_INLINE_ASM
60cabdff1aSopenharmony_ci#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
61cabdff1aSopenharmony_cistatic void ff_weighted_vector_sumf_mips(
62cabdff1aSopenharmony_ci                  float *out, const float *in_a, const float *in_b,
63cabdff1aSopenharmony_ci                  float weight_coeff_a, float weight_coeff_b, int length)
64cabdff1aSopenharmony_ci{
65cabdff1aSopenharmony_ci    const float *a_end = in_a + length;
66cabdff1aSopenharmony_ci
67cabdff1aSopenharmony_ci    /* loop unrolled two times */
68cabdff1aSopenharmony_ci    __asm__ volatile (
69cabdff1aSopenharmony_ci        "blez   %[length], ff_weighted_vector_sumf_end%=                     \n\t"
70cabdff1aSopenharmony_ci
71cabdff1aSopenharmony_ci        "ff_weighted_vector_sumf_madd%=:                                     \n\t"
72cabdff1aSopenharmony_ci        "lwc1   $f0,       0(%[in_a])                                        \n\t"
73cabdff1aSopenharmony_ci        "lwc1   $f3,       4(%[in_a])                                        \n\t"
74cabdff1aSopenharmony_ci        "lwc1   $f1,       0(%[in_b])                                        \n\t"
75cabdff1aSopenharmony_ci        "lwc1   $f4,       4(%[in_b])                                        \n\t"
76cabdff1aSopenharmony_ci        "mul.s  $f2,       %[weight_coeff_a], $f0                            \n\t"
77cabdff1aSopenharmony_ci        "mul.s  $f5,       %[weight_coeff_a], $f3                            \n\t"
78cabdff1aSopenharmony_ci        "madd.s $f2,       $f2,               %[weight_coeff_b], $f1         \n\t"
79cabdff1aSopenharmony_ci        "madd.s $f5,       $f5,               %[weight_coeff_b], $f4         \n\t"
80cabdff1aSopenharmony_ci        PTR_ADDIU "%[in_a],8                                                 \n\t"
81cabdff1aSopenharmony_ci        PTR_ADDIU "%[in_b],8                                                 \n\t"
82cabdff1aSopenharmony_ci        "swc1   $f2,       0(%[out])                                         \n\t"
83cabdff1aSopenharmony_ci        "swc1   $f5,       4(%[out])                                         \n\t"
84cabdff1aSopenharmony_ci        PTR_ADDIU "%[out], 8                                                 \n\t"
85cabdff1aSopenharmony_ci        "bne   %[in_a],    %[a_end],          ff_weighted_vector_sumf_madd%= \n\t"
86cabdff1aSopenharmony_ci
87cabdff1aSopenharmony_ci        "ff_weighted_vector_sumf_end%=:                                      \n\t"
88cabdff1aSopenharmony_ci
89cabdff1aSopenharmony_ci        : [out] "+r" (out), [in_a] "+r" (in_a),   [in_b] "+r" (in_b)
90cabdff1aSopenharmony_ci        : [weight_coeff_a] "f" (weight_coeff_a),
91cabdff1aSopenharmony_ci          [weight_coeff_b] "f" (weight_coeff_b),
92cabdff1aSopenharmony_ci          [length] "r" (length), [a_end]"r"(a_end)
93cabdff1aSopenharmony_ci        : "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "memory"
94cabdff1aSopenharmony_ci    );
95cabdff1aSopenharmony_ci}
96cabdff1aSopenharmony_ci#endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
97cabdff1aSopenharmony_ci#endif /* HAVE_INLINE_ASM */
98cabdff1aSopenharmony_ci
99cabdff1aSopenharmony_civoid ff_acelp_vectors_init_mips(ACELPVContext *c)
100cabdff1aSopenharmony_ci{
101cabdff1aSopenharmony_ci#if HAVE_INLINE_ASM
102cabdff1aSopenharmony_ci#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
103cabdff1aSopenharmony_ci    c->weighted_vector_sumf = ff_weighted_vector_sumf_mips;
104cabdff1aSopenharmony_ci#endif
105cabdff1aSopenharmony_ci#endif
106cabdff1aSopenharmony_ci}
107