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) 2004 Jean-Marc Valin */
TMBOY 47:9e361da97763 2 /**
TMBOY 47:9e361da97763 3 @file vq_sse.h
TMBOY 47:9e361da97763 4 @brief SSE-optimized vq routine
TMBOY 47:9e361da97763 5 */
TMBOY 47:9e361da97763 6 /*
TMBOY 47:9e361da97763 7 Redistribution and use in source and binary forms, with or without
TMBOY 47:9e361da97763 8 modification, are permitted provided that the following conditions
TMBOY 47:9e361da97763 9 are met:
TMBOY 47:9e361da97763 10
TMBOY 47:9e361da97763 11 - Redistributions of source code must retain the above copyright
TMBOY 47:9e361da97763 12 notice, this list of conditions and the following disclaimer.
TMBOY 47:9e361da97763 13
TMBOY 47:9e361da97763 14 - Redistributions in binary form must reproduce the above copyright
TMBOY 47:9e361da97763 15 notice, this list of conditions and the following disclaimer in the
TMBOY 47:9e361da97763 16 documentation and/or other materials provided with the distribution.
TMBOY 47:9e361da97763 17
TMBOY 47:9e361da97763 18 - Neither the name of the Xiph.org Foundation nor the names of its
TMBOY 47:9e361da97763 19 contributors may be used to endorse or promote products derived from
TMBOY 47:9e361da97763 20 this software without specific prior written permission.
TMBOY 47:9e361da97763 21
TMBOY 47:9e361da97763 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
TMBOY 47:9e361da97763 23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
TMBOY 47:9e361da97763 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
TMBOY 47:9e361da97763 25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
TMBOY 47:9e361da97763 26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
TMBOY 47:9e361da97763 27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
TMBOY 47:9e361da97763 28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
TMBOY 47:9e361da97763 29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
TMBOY 47:9e361da97763 30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
TMBOY 47:9e361da97763 31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
TMBOY 47:9e361da97763 32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TMBOY 47:9e361da97763 33 */
TMBOY 47:9e361da97763 34
TMBOY 47:9e361da97763 35 #define OVERRIDE_VQ_NBEST
TMBOY 47:9e361da97763 36 void vq_nbest(spx_word16_t *_in, const __m128 *codebook, int len, int entries, __m128 *E, int N, int *nbest, spx_word32_t *best_dist, char *stack)
TMBOY 47:9e361da97763 37 {
TMBOY 47:9e361da97763 38 int i,j,k,used;
TMBOY 47:9e361da97763 39 VARDECL(float *dist);
TMBOY 47:9e361da97763 40 VARDECL(__m128 *in);
TMBOY 47:9e361da97763 41 __m128 half;
TMBOY 47:9e361da97763 42 used = 0;
TMBOY 47:9e361da97763 43 ALLOC(dist, entries, float);
TMBOY 47:9e361da97763 44 half = _mm_set_ps1(.5f);
TMBOY 47:9e361da97763 45 ALLOC(in, len, __m128);
TMBOY 47:9e361da97763 46 for (i=0;i<len;i++)
TMBOY 47:9e361da97763 47 in[i] = _mm_set_ps1(_in[i]);
TMBOY 47:9e361da97763 48 for (i=0;i<entries>>2;i++)
TMBOY 47:9e361da97763 49 {
TMBOY 47:9e361da97763 50 __m128 d = _mm_mul_ps(E[i], half);
TMBOY 47:9e361da97763 51 for (j=0;j<len;j++)
TMBOY 47:9e361da97763 52 d = _mm_sub_ps(d, _mm_mul_ps(in[j], *codebook++));
TMBOY 47:9e361da97763 53 _mm_storeu_ps(dist+4*i, d);
TMBOY 47:9e361da97763 54 }
TMBOY 47:9e361da97763 55 for (i=0;i<entries;i++)
TMBOY 47:9e361da97763 56 {
TMBOY 47:9e361da97763 57 if (i<N || dist[i]<best_dist[N-1])
TMBOY 47:9e361da97763 58 {
TMBOY 47:9e361da97763 59 for (k=N-1; (k >= 1) && (k > used || dist[i] < best_dist[k-1]); k--)
TMBOY 47:9e361da97763 60 {
TMBOY 47:9e361da97763 61 best_dist[k]=best_dist[k-1];
TMBOY 47:9e361da97763 62 nbest[k] = nbest[k-1];
TMBOY 47:9e361da97763 63 }
TMBOY 47:9e361da97763 64 best_dist[k]=dist[i];
TMBOY 47:9e361da97763 65 nbest[k]=i;
TMBOY 47:9e361da97763 66 used++;
TMBOY 47:9e361da97763 67 }
TMBOY 47:9e361da97763 68 }
TMBOY 47:9e361da97763 69 }
TMBOY 47:9e361da97763 70
TMBOY 47:9e361da97763 71
TMBOY 47:9e361da97763 72
TMBOY 47:9e361da97763 73
TMBOY 47:9e361da97763 74 #define OVERRIDE_VQ_NBEST_SIGN
TMBOY 47:9e361da97763 75 void vq_nbest_sign(spx_word16_t *_in, const __m128 *codebook, int len, int entries, __m128 *E, int N, int *nbest, spx_word32_t *best_dist, char *stack)
TMBOY 47:9e361da97763 76 {
TMBOY 47:9e361da97763 77 int i,j,k,used;
TMBOY 47:9e361da97763 78 VARDECL(float *dist);
TMBOY 47:9e361da97763 79 VARDECL(__m128 *in);
TMBOY 47:9e361da97763 80 __m128 half;
TMBOY 47:9e361da97763 81 used = 0;
TMBOY 47:9e361da97763 82 ALLOC(dist, entries, float);
TMBOY 47:9e361da97763 83 half = _mm_set_ps1(.5f);
TMBOY 47:9e361da97763 84 ALLOC(in, len, __m128);
TMBOY 47:9e361da97763 85 for (i=0;i<len;i++)
TMBOY 47:9e361da97763 86 in[i] = _mm_set_ps1(_in[i]);
TMBOY 47:9e361da97763 87 for (i=0;i<entries>>2;i++)
TMBOY 47:9e361da97763 88 {
TMBOY 47:9e361da97763 89 __m128 d = _mm_setzero_ps();
TMBOY 47:9e361da97763 90 for (j=0;j<len;j++)
TMBOY 47:9e361da97763 91 d = _mm_add_ps(d, _mm_mul_ps(in[j], *codebook++));
TMBOY 47:9e361da97763 92 _mm_storeu_ps(dist+4*i, d);
TMBOY 47:9e361da97763 93 }
TMBOY 47:9e361da97763 94 for (i=0;i<entries;i++)
TMBOY 47:9e361da97763 95 {
TMBOY 47:9e361da97763 96 int sign;
TMBOY 47:9e361da97763 97 if (dist[i]>0)
TMBOY 47:9e361da97763 98 {
TMBOY 47:9e361da97763 99 sign=0;
TMBOY 47:9e361da97763 100 dist[i]=-dist[i];
TMBOY 47:9e361da97763 101 } else
TMBOY 47:9e361da97763 102 {
TMBOY 47:9e361da97763 103 sign=1;
TMBOY 47:9e361da97763 104 }
TMBOY 47:9e361da97763 105 dist[i] += .5f*((float*)E)[i];
TMBOY 47:9e361da97763 106 if (i<N || dist[i]<best_dist[N-1])
TMBOY 47:9e361da97763 107 {
TMBOY 47:9e361da97763 108 for (k=N-1; (k >= 1) && (k > used || dist[i] < best_dist[k-1]); k--)
TMBOY 47:9e361da97763 109 {
TMBOY 47:9e361da97763 110 best_dist[k]=best_dist[k-1];
TMBOY 47:9e361da97763 111 nbest[k] = nbest[k-1];
TMBOY 47:9e361da97763 112 }
TMBOY 47:9e361da97763 113 best_dist[k]=dist[i];
TMBOY 47:9e361da97763 114 nbest[k]=i;
TMBOY 47:9e361da97763 115 used++;
TMBOY 47:9e361da97763 116 if (sign)
TMBOY 47:9e361da97763 117 nbest[k]+=entries;
TMBOY 47:9e361da97763 118 }
TMBOY 47:9e361da97763 119 }
TMBOY 47:9e361da97763 120 }