ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 /* Copyright (C) 2006 David Rowe */
TMBOY 47:9e361da97763 2 /**
TMBOY 47:9e361da97763 3 @file quant_lsp_bfin.h
TMBOY 47:9e361da97763 4 @author David Rowe
TMBOY 47:9e361da97763 5 @brief Various compatibility routines for Speex (Blackfin version)
TMBOY 47:9e361da97763 6 */
TMBOY 47:9e361da97763 7 /*
TMBOY 47:9e361da97763 8 Redistribution and use in source and binary forms, with or without
TMBOY 47:9e361da97763 9 modification, are permitted provided that the following conditions
TMBOY 47:9e361da97763 10 are met:
TMBOY 47:9e361da97763 11
TMBOY 47:9e361da97763 12 - Redistributions of source code must retain the above copyright
TMBOY 47:9e361da97763 13 notice, this list of conditions and the following disclaimer.
TMBOY 47:9e361da97763 14
TMBOY 47:9e361da97763 15 - Redistributions in binary form must reproduce the above copyright
TMBOY 47:9e361da97763 16 notice, this list of conditions and the following disclaimer in the
TMBOY 47:9e361da97763 17 documentation and/or other materials provided with the distribution.
TMBOY 47:9e361da97763 18
TMBOY 47:9e361da97763 19 - Neither the name of the Xiph.org Foundation nor the names of its
TMBOY 47:9e361da97763 20 contributors may be used to endorse or promote products derived from
TMBOY 47:9e361da97763 21 this software without specific prior written permission.
TMBOY 47:9e361da97763 22
TMBOY 47:9e361da97763 23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
TMBOY 47:9e361da97763 24 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
TMBOY 47:9e361da97763 25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
TMBOY 47:9e361da97763 26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
TMBOY 47:9e361da97763 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
TMBOY 47:9e361da97763 28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
TMBOY 47:9e361da97763 29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
TMBOY 47:9e361da97763 30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
TMBOY 47:9e361da97763 31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
TMBOY 47:9e361da97763 32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
TMBOY 47:9e361da97763 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TMBOY 47:9e361da97763 34 */
TMBOY 47:9e361da97763 35
TMBOY 47:9e361da97763 36 #define OVERRIDE_LSP_QUANT
TMBOY 47:9e361da97763 37 #ifdef OVERRIDE_LSP_QUANT
TMBOY 47:9e361da97763 38
TMBOY 47:9e361da97763 39 /*
TMBOY 47:9e361da97763 40 Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
TMBOY 47:9e361da97763 41 well tell you all the magic resgister constraints used below
TMBOY 47:9e361da97763 42 for gcc in-line asm.
TMBOY 47:9e361da97763 43 */
TMBOY 47:9e361da97763 44
TMBOY 47:9e361da97763 45 static int lsp_quant(
TMBOY 47:9e361da97763 46 spx_word16_t *x,
TMBOY 47:9e361da97763 47 const signed char *cdbk,
TMBOY 47:9e361da97763 48 int nbVec,
TMBOY 47:9e361da97763 49 int nbDim
TMBOY 47:9e361da97763 50 )
TMBOY 47:9e361da97763 51 {
TMBOY 47:9e361da97763 52 int j;
TMBOY 47:9e361da97763 53 spx_word32_t best_dist=1<<30;
TMBOY 47:9e361da97763 54 int best_id=0;
TMBOY 47:9e361da97763 55
TMBOY 47:9e361da97763 56 __asm__ __volatile__
TMBOY 47:9e361da97763 57 (
TMBOY 47:9e361da97763 58 " %0 = 1 (X);\n\t" /* %0: best_dist */
TMBOY 47:9e361da97763 59 " %0 <<= 30;\n\t"
TMBOY 47:9e361da97763 60 " %1 = 0 (X);\n\t" /* %1: best_i */
TMBOY 47:9e361da97763 61 " P2 = %3\n\t" /* P2: ptr to cdbk */
TMBOY 47:9e361da97763 62 " R5 = 0;\n\t" /* R5: best cb entry */
TMBOY 47:9e361da97763 63
TMBOY 47:9e361da97763 64 " R0 = %5;\n\t" /* set up circ addr */
TMBOY 47:9e361da97763 65 " R0 <<= 1;\n\t"
TMBOY 47:9e361da97763 66 " L0 = R0;\n\t"
TMBOY 47:9e361da97763 67 " I0 = %2;\n\t" /* %2: &x[0] */
TMBOY 47:9e361da97763 68 " B0 = %2;\n\t"
TMBOY 47:9e361da97763 69
TMBOY 47:9e361da97763 70 " R2.L = W [I0++];\n\t"
TMBOY 47:9e361da97763 71 " LSETUP (lq1, lq2) LC0 = %4;\n\t"
TMBOY 47:9e361da97763 72 "lq1: R3 = 0;\n\t" /* R3: dist */
TMBOY 47:9e361da97763 73 " LSETUP (lq3, lq4) LC1 = %5;\n\t"
TMBOY 47:9e361da97763 74 "lq3: R1 = B [P2++] (X);\n\t"
TMBOY 47:9e361da97763 75 " R1 <<= 5;\n\t"
TMBOY 47:9e361da97763 76 " R0.L = R2.L - R1.L || R2.L = W [I0++];\n\t"
TMBOY 47:9e361da97763 77 " R0 = R0.L*R0.L;\n\t"
TMBOY 47:9e361da97763 78 "lq4: R3 = R3 + R0;\n\t"
TMBOY 47:9e361da97763 79
TMBOY 47:9e361da97763 80 " cc =R3<%0;\n\t"
TMBOY 47:9e361da97763 81 " if cc %0=R3;\n\t"
TMBOY 47:9e361da97763 82 " if cc %1=R5;\n\t"
TMBOY 47:9e361da97763 83 "lq2: R5 += 1;\n\t"
TMBOY 47:9e361da97763 84 " L0 = 0;\n\t"
TMBOY 47:9e361da97763 85 : "=&d" (best_dist), "=&d" (best_id)
TMBOY 47:9e361da97763 86 : "a" (x), "b" (cdbk), "a" (nbVec), "a" (nbDim)
TMBOY 47:9e361da97763 87 : "I0", "P2", "R0", "R1", "R2", "R3", "R5", "L0", "B0", "A0"
TMBOY 47:9e361da97763 88 );
TMBOY 47:9e361da97763 89
TMBOY 47:9e361da97763 90 for (j=0;j<nbDim;j++) {
TMBOY 47:9e361da97763 91 x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
TMBOY 47:9e361da97763 92 }
TMBOY 47:9e361da97763 93 return best_id;
TMBOY 47:9e361da97763 94 }
TMBOY 47:9e361da97763 95 #endif
TMBOY 47:9e361da97763 96
TMBOY 47:9e361da97763 97 #define OVERRIDE_LSP_WEIGHT_QUANT
TMBOY 47:9e361da97763 98 #ifdef OVERRIDE_LSP_WEIGHT_QUANT
TMBOY 47:9e361da97763 99
TMBOY 47:9e361da97763 100 /*
TMBOY 47:9e361da97763 101 Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
TMBOY 47:9e361da97763 102 well tell you all the magic resgister constraints used below
TMBOY 47:9e361da97763 103 for gcc in-line asm.
TMBOY 47:9e361da97763 104 */
TMBOY 47:9e361da97763 105
TMBOY 47:9e361da97763 106 static int lsp_weight_quant(
TMBOY 47:9e361da97763 107 spx_word16_t *x,
TMBOY 47:9e361da97763 108 spx_word16_t *weight,
TMBOY 47:9e361da97763 109 const signed char *cdbk,
TMBOY 47:9e361da97763 110 int nbVec,
TMBOY 47:9e361da97763 111 int nbDim
TMBOY 47:9e361da97763 112 )
TMBOY 47:9e361da97763 113 {
TMBOY 47:9e361da97763 114 int j;
TMBOY 47:9e361da97763 115 spx_word32_t best_dist=1<<30;
TMBOY 47:9e361da97763 116 int best_id=0;
TMBOY 47:9e361da97763 117
TMBOY 47:9e361da97763 118 __asm__ __volatile__
TMBOY 47:9e361da97763 119 (
TMBOY 47:9e361da97763 120 " %0 = 1 (X);\n\t" /* %0: best_dist */
TMBOY 47:9e361da97763 121 " %0 <<= 30;\n\t"
TMBOY 47:9e361da97763 122 " %1 = 0 (X);\n\t" /* %1: best_i */
TMBOY 47:9e361da97763 123 " P2 = %4\n\t" /* P2: ptr to cdbk */
TMBOY 47:9e361da97763 124 " R5 = 0;\n\t" /* R5: best cb entry */
TMBOY 47:9e361da97763 125
TMBOY 47:9e361da97763 126 " R0 = %6;\n\t" /* set up circ addr */
TMBOY 47:9e361da97763 127 " R0 <<= 1;\n\t"
TMBOY 47:9e361da97763 128 " L0 = R0;\n\t"
TMBOY 47:9e361da97763 129 " L1 = R0;\n\t"
TMBOY 47:9e361da97763 130 " I0 = %2;\n\t" /* %2: &x[0] */
TMBOY 47:9e361da97763 131 " I1 = %3;\n\t" /* %3: &weight[0] */
TMBOY 47:9e361da97763 132 " B0 = %2;\n\t"
TMBOY 47:9e361da97763 133 " B1 = %3;\n\t"
TMBOY 47:9e361da97763 134
TMBOY 47:9e361da97763 135 " LSETUP (lwq1, lwq2) LC0 = %5;\n\t"
TMBOY 47:9e361da97763 136 "lwq1: R3 = 0 (X);\n\t" /* R3: dist */
TMBOY 47:9e361da97763 137 " LSETUP (lwq3, lwq4) LC1 = %6;\n\t"
TMBOY 47:9e361da97763 138 "lwq3: R0.L = W [I0++] || R2.L = W [I1++];\n\t"
TMBOY 47:9e361da97763 139 " R1 = B [P2++] (X);\n\t"
TMBOY 47:9e361da97763 140 " R1 <<= 5;\n\t"
TMBOY 47:9e361da97763 141 " R0.L = R0.L - R1.L;\n\t"
TMBOY 47:9e361da97763 142 " R0 = R0.L*R0.L;\n\t"
TMBOY 47:9e361da97763 143 " A1 = R2.L*R0.L (M,IS);\n\t"
TMBOY 47:9e361da97763 144 " A1 = A1 >>> 16;\n\t"
TMBOY 47:9e361da97763 145 " R1 = (A1 += R2.L*R0.H) (IS);\n\t"
TMBOY 47:9e361da97763 146 "lwq4: R3 = R3 + R1;\n\t"
TMBOY 47:9e361da97763 147
TMBOY 47:9e361da97763 148 " cc =R3<%0;\n\t"
TMBOY 47:9e361da97763 149 " if cc %0=R3;\n\t"
TMBOY 47:9e361da97763 150 " if cc %1=R5;\n\t"
TMBOY 47:9e361da97763 151 "lwq2: R5 += 1;\n\t"
TMBOY 47:9e361da97763 152 " L0 = 0;\n\t"
TMBOY 47:9e361da97763 153 " L1 = 0;\n\t"
TMBOY 47:9e361da97763 154 : "=&d" (best_dist), "=&d" (best_id)
TMBOY 47:9e361da97763 155 : "a" (x), "a" (weight), "b" (cdbk), "a" (nbVec), "a" (nbDim)
TMBOY 47:9e361da97763 156 : "I0", "I1", "P2", "R0", "R1", "R2", "R3", "R5", "A1",
TMBOY 47:9e361da97763 157 "L0", "L1", "B0", "B1"
TMBOY 47:9e361da97763 158 );
TMBOY 47:9e361da97763 159
TMBOY 47:9e361da97763 160 for (j=0;j<nbDim;j++) {
TMBOY 47:9e361da97763 161 x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
TMBOY 47:9e361da97763 162 }
TMBOY 47:9e361da97763 163 return best_id;
TMBOY 47:9e361da97763 164 }
TMBOY 47:9e361da97763 165 #endif