1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
12
WebRtcSpl_CrossCorrelation_mips(int32_t * cross_correlation,const int16_t * seq1,const int16_t * seq2,size_t dim_seq,size_t dim_cross_correlation,int right_shifts,int step_seq2)13 void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
14 const int16_t* seq1,
15 const int16_t* seq2,
16 size_t dim_seq,
17 size_t dim_cross_correlation,
18 int right_shifts,
19 int step_seq2) {
20
21 int32_t t0 = 0, t1 = 0, t2 = 0, t3 = 0, sum = 0;
22 int16_t *pseq2 = NULL;
23 int16_t *pseq1 = NULL;
24 int16_t *pseq1_0 = (int16_t*)&seq1[0];
25 int16_t *pseq2_0 = (int16_t*)&seq2[0];
26 int k = 0;
27
28 __asm __volatile (
29 ".set push \n\t"
30 ".set noreorder \n\t"
31 "sll %[step_seq2], %[step_seq2], 1 \n\t"
32 "andi %[t0], %[dim_seq], 1 \n\t"
33 "bgtz %[t0], 3f \n\t"
34 " nop \n\t"
35 "1: \n\t"
36 "move %[pseq1], %[pseq1_0] \n\t"
37 "move %[pseq2], %[pseq2_0] \n\t"
38 "sra %[k], %[dim_seq], 1 \n\t"
39 "addiu %[dim_cc], %[dim_cc], -1 \n\t"
40 "xor %[sum], %[sum], %[sum] \n\t"
41 "2: \n\t"
42 "lh %[t0], 0(%[pseq1]) \n\t"
43 "lh %[t1], 0(%[pseq2]) \n\t"
44 "lh %[t2], 2(%[pseq1]) \n\t"
45 "lh %[t3], 2(%[pseq2]) \n\t"
46 "mul %[t0], %[t0], %[t1] \n\t"
47 "addiu %[k], %[k], -1 \n\t"
48 "mul %[t2], %[t2], %[t3] \n\t"
49 "addiu %[pseq1], %[pseq1], 4 \n\t"
50 "addiu %[pseq2], %[pseq2], 4 \n\t"
51 "srav %[t0], %[t0], %[right_shifts] \n\t"
52 "addu %[sum], %[sum], %[t0] \n\t"
53 "srav %[t2], %[t2], %[right_shifts] \n\t"
54 "bgtz %[k], 2b \n\t"
55 " addu %[sum], %[sum], %[t2] \n\t"
56 "addu %[pseq2_0], %[pseq2_0], %[step_seq2] \n\t"
57 "sw %[sum], 0(%[cc]) \n\t"
58 "bgtz %[dim_cc], 1b \n\t"
59 " addiu %[cc], %[cc], 4 \n\t"
60 "b 6f \n\t"
61 " nop \n\t"
62 "3: \n\t"
63 "move %[pseq1], %[pseq1_0] \n\t"
64 "move %[pseq2], %[pseq2_0] \n\t"
65 "sra %[k], %[dim_seq], 1 \n\t"
66 "addiu %[dim_cc], %[dim_cc], -1 \n\t"
67 "beqz %[k], 5f \n\t"
68 " xor %[sum], %[sum], %[sum] \n\t"
69 "4: \n\t"
70 "lh %[t0], 0(%[pseq1]) \n\t"
71 "lh %[t1], 0(%[pseq2]) \n\t"
72 "lh %[t2], 2(%[pseq1]) \n\t"
73 "lh %[t3], 2(%[pseq2]) \n\t"
74 "mul %[t0], %[t0], %[t1] \n\t"
75 "addiu %[k], %[k], -1 \n\t"
76 "mul %[t2], %[t2], %[t3] \n\t"
77 "addiu %[pseq1], %[pseq1], 4 \n\t"
78 "addiu %[pseq2], %[pseq2], 4 \n\t"
79 "srav %[t0], %[t0], %[right_shifts] \n\t"
80 "addu %[sum], %[sum], %[t0] \n\t"
81 "srav %[t2], %[t2], %[right_shifts] \n\t"
82 "bgtz %[k], 4b \n\t"
83 " addu %[sum], %[sum], %[t2] \n\t"
84 "5: \n\t"
85 "lh %[t0], 0(%[pseq1]) \n\t"
86 "lh %[t1], 0(%[pseq2]) \n\t"
87 "mul %[t0], %[t0], %[t1] \n\t"
88 "srav %[t0], %[t0], %[right_shifts] \n\t"
89 "addu %[sum], %[sum], %[t0] \n\t"
90 "addu %[pseq2_0], %[pseq2_0], %[step_seq2] \n\t"
91 "sw %[sum], 0(%[cc]) \n\t"
92 "bgtz %[dim_cc], 3b \n\t"
93 " addiu %[cc], %[cc], 4 \n\t"
94 "6: \n\t"
95 ".set pop \n\t"
96 : [step_seq2] "+r" (step_seq2), [t0] "=&r" (t0), [t1] "=&r" (t1),
97 [t2] "=&r" (t2), [t3] "=&r" (t3), [pseq1] "=&r" (pseq1),
98 [pseq2] "=&r" (pseq2), [pseq1_0] "+r" (pseq1_0), [pseq2_0] "+r" (pseq2_0),
99 [k] "=&r" (k), [dim_cc] "+r" (dim_cross_correlation), [sum] "=&r" (sum),
100 [cc] "+r" (cross_correlation)
101 : [dim_seq] "r" (dim_seq), [right_shifts] "r" (right_shifts)
102 : "hi", "lo", "memory"
103 );
104 }
105