• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3               2023 Amazon
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 - Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 - Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 - Neither the name of Internet Society, IETF or IETF Trust, nor the
13 names of specific contributors, may be used to endorse or promote
14 products derived from this software without specific prior written
15 permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27 ***********************************************************************/
28 
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include "SigProc_FLP.h"
34 #include <immintrin.h>
35 
36 
37 /* inner product of two silk_float arrays, with result as double */
silk_inner_product_FLP_avx2(const silk_float * data1,const silk_float * data2,opus_int dataSize)38 double silk_inner_product_FLP_avx2(
39     const silk_float    *data1,
40     const silk_float    *data2,
41     opus_int            dataSize
42 )
43 {
44     opus_int i;
45     __m256d accum1, accum2;
46     double   result;
47 
48     /* 4x unrolled loop */
49     result = 0.0;
50     accum1 = accum2 = _mm256_setzero_pd();
51     for( i = 0; i < dataSize - 7; i += 8 ) {
52         __m128  x1f, x2f;
53         __m256d x1d, x2d;
54         x1f = _mm_loadu_ps( &data1[ i ] );
55         x2f = _mm_loadu_ps( &data2[ i ] );
56         x1d = _mm256_cvtps_pd( x1f );
57         x2d = _mm256_cvtps_pd( x2f );
58         accum1 = _mm256_fmadd_pd( x1d, x2d, accum1 );
59         x1f = _mm_loadu_ps( &data1[ i + 4 ] );
60         x2f = _mm_loadu_ps( &data2[ i + 4 ] );
61         x1d = _mm256_cvtps_pd( x1f );
62         x2d = _mm256_cvtps_pd( x2f );
63         accum2 = _mm256_fmadd_pd( x1d, x2d, accum2 );
64     }
65     for( ; i < dataSize - 3; i += 4 ) {
66         __m128  x1f, x2f;
67         __m256d x1d, x2d;
68         x1f = _mm_loadu_ps( &data1[ i ] );
69         x2f = _mm_loadu_ps( &data2[ i ] );
70         x1d = _mm256_cvtps_pd( x1f );
71         x2d = _mm256_cvtps_pd( x2f );
72         accum1 = _mm256_fmadd_pd( x1d, x2d, accum1 );
73     }
74     accum1 = _mm256_add_pd(accum1, accum2);
75     accum1 = _mm256_add_pd(accum1, _mm256_permute2f128_pd(accum1, accum1, 1));
76     accum1 = _mm256_hadd_pd(accum1,accum1);
77     result = _mm256_cvtsd_f64(accum1);
78 
79     /* add any remaining products */
80     for( ; i < dataSize; i++ ) {
81         result += data1[ i ] * (double)data2[ i ];
82     }
83 
84     return result;
85 }
86