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) 2005 Analog Devices
TMBOY 47:9e361da97763 2 Author: Jean-Marc Valin */
TMBOY 47:9e361da97763 3 /**
TMBOY 47:9e361da97763 4 @file fixed_bfin.h
TMBOY 47:9e361da97763 5 @brief Blackfin fixed-point operations
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 #ifndef FIXED_BFIN_H
TMBOY 47:9e361da97763 37 #define FIXED_BFIN_H
TMBOY 47:9e361da97763 38
TMBOY 47:9e361da97763 39 #undef PDIV32_16
TMBOY 47:9e361da97763 40 static inline spx_word16_t PDIV32_16(spx_word32_t a, spx_word16_t b)
TMBOY 47:9e361da97763 41 {
TMBOY 47:9e361da97763 42 spx_word32_t res, bb;
TMBOY 47:9e361da97763 43 bb = b;
TMBOY 47:9e361da97763 44 a += b>>1;
TMBOY 47:9e361da97763 45 __asm__ (
TMBOY 47:9e361da97763 46 "P0 = 15;\n\t"
TMBOY 47:9e361da97763 47 "R0 = %1;\n\t"
TMBOY 47:9e361da97763 48 "R1 = %2;\n\t"
TMBOY 47:9e361da97763 49 //"R0 = R0 + R1;\n\t"
TMBOY 47:9e361da97763 50 "R0 <<= 1;\n\t"
TMBOY 47:9e361da97763 51 "DIVS (R0, R1);\n\t"
TMBOY 47:9e361da97763 52 "LOOP divide%= LC0 = P0;\n\t"
TMBOY 47:9e361da97763 53 "LOOP_BEGIN divide%=;\n\t"
TMBOY 47:9e361da97763 54 "DIVQ (R0, R1);\n\t"
TMBOY 47:9e361da97763 55 "LOOP_END divide%=;\n\t"
TMBOY 47:9e361da97763 56 "R0 = R0.L;\n\t"
TMBOY 47:9e361da97763 57 "%0 = R0;\n\t"
TMBOY 47:9e361da97763 58 : "=m" (res)
TMBOY 47:9e361da97763 59 : "m" (a), "m" (bb)
TMBOY 47:9e361da97763 60 : "P0", "R0", "R1", "cc");
TMBOY 47:9e361da97763 61 return res;
TMBOY 47:9e361da97763 62 }
TMBOY 47:9e361da97763 63
TMBOY 47:9e361da97763 64 #undef DIV32_16
TMBOY 47:9e361da97763 65 static inline spx_word16_t DIV32_16(spx_word32_t a, spx_word16_t b)
TMBOY 47:9e361da97763 66 {
TMBOY 47:9e361da97763 67 spx_word32_t res, bb;
TMBOY 47:9e361da97763 68 bb = b;
TMBOY 47:9e361da97763 69 /* Make the roundinf consistent with the C version
TMBOY 47:9e361da97763 70 (do we need to do that?)*/
TMBOY 47:9e361da97763 71 if (a<0)
TMBOY 47:9e361da97763 72 a += (b-1);
TMBOY 47:9e361da97763 73 __asm__ (
TMBOY 47:9e361da97763 74 "P0 = 15;\n\t"
TMBOY 47:9e361da97763 75 "R0 = %1;\n\t"
TMBOY 47:9e361da97763 76 "R1 = %2;\n\t"
TMBOY 47:9e361da97763 77 "R0 <<= 1;\n\t"
TMBOY 47:9e361da97763 78 "DIVS (R0, R1);\n\t"
TMBOY 47:9e361da97763 79 "LOOP divide%= LC0 = P0;\n\t"
TMBOY 47:9e361da97763 80 "LOOP_BEGIN divide%=;\n\t"
TMBOY 47:9e361da97763 81 "DIVQ (R0, R1);\n\t"
TMBOY 47:9e361da97763 82 "LOOP_END divide%=;\n\t"
TMBOY 47:9e361da97763 83 "R0 = R0.L;\n\t"
TMBOY 47:9e361da97763 84 "%0 = R0;\n\t"
TMBOY 47:9e361da97763 85 : "=m" (res)
TMBOY 47:9e361da97763 86 : "m" (a), "m" (bb)
TMBOY 47:9e361da97763 87 : "P0", "R0", "R1", "cc");
TMBOY 47:9e361da97763 88 return res;
TMBOY 47:9e361da97763 89 }
TMBOY 47:9e361da97763 90
TMBOY 47:9e361da97763 91 #undef MAX16
TMBOY 47:9e361da97763 92 static inline spx_word16_t MAX16(spx_word16_t a, spx_word16_t b)
TMBOY 47:9e361da97763 93 {
TMBOY 47:9e361da97763 94 spx_word32_t res;
TMBOY 47:9e361da97763 95 __asm__ (
TMBOY 47:9e361da97763 96 "%1 = %1.L (X);\n\t"
TMBOY 47:9e361da97763 97 "%2 = %2.L (X);\n\t"
TMBOY 47:9e361da97763 98 "%0 = MAX(%1,%2);"
TMBOY 47:9e361da97763 99 : "=d" (res)
TMBOY 47:9e361da97763 100 : "%d" (a), "d" (b)
TMBOY 47:9e361da97763 101 );
TMBOY 47:9e361da97763 102 return res;
TMBOY 47:9e361da97763 103 }
TMBOY 47:9e361da97763 104
TMBOY 47:9e361da97763 105 #undef MULT16_32_Q15
TMBOY 47:9e361da97763 106 static inline spx_word32_t MULT16_32_Q15(spx_word16_t a, spx_word32_t b)
TMBOY 47:9e361da97763 107 {
TMBOY 47:9e361da97763 108 spx_word32_t res;
TMBOY 47:9e361da97763 109 __asm__
TMBOY 47:9e361da97763 110 (
TMBOY 47:9e361da97763 111 "A1 = %2.L*%1.L (M);\n\t"
TMBOY 47:9e361da97763 112 "A1 = A1 >>> 15;\n\t"
TMBOY 47:9e361da97763 113 "%0 = (A1 += %2.L*%1.H) ;\n\t"
TMBOY 47:9e361da97763 114 : "=&W" (res), "=&d" (b)
TMBOY 47:9e361da97763 115 : "d" (a), "1" (b)
TMBOY 47:9e361da97763 116 : "A1"
TMBOY 47:9e361da97763 117 );
TMBOY 47:9e361da97763 118 return res;
TMBOY 47:9e361da97763 119 }
TMBOY 47:9e361da97763 120
TMBOY 47:9e361da97763 121 #undef MAC16_32_Q15
TMBOY 47:9e361da97763 122 static inline spx_word32_t MAC16_32_Q15(spx_word32_t c, spx_word16_t a, spx_word32_t b)
TMBOY 47:9e361da97763 123 {
TMBOY 47:9e361da97763 124 spx_word32_t res;
TMBOY 47:9e361da97763 125 __asm__
TMBOY 47:9e361da97763 126 (
TMBOY 47:9e361da97763 127 "A1 = %2.L*%1.L (M);\n\t"
TMBOY 47:9e361da97763 128 "A1 = A1 >>> 15;\n\t"
TMBOY 47:9e361da97763 129 "%0 = (A1 += %2.L*%1.H);\n\t"
TMBOY 47:9e361da97763 130 "%0 = %0 + %4;\n\t"
TMBOY 47:9e361da97763 131 : "=&W" (res), "=&d" (b)
TMBOY 47:9e361da97763 132 : "d" (a), "1" (b), "d" (c)
TMBOY 47:9e361da97763 133 : "A1"
TMBOY 47:9e361da97763 134 );
TMBOY 47:9e361da97763 135 return res;
TMBOY 47:9e361da97763 136 }
TMBOY 47:9e361da97763 137
TMBOY 47:9e361da97763 138 #undef MULT16_32_Q14
TMBOY 47:9e361da97763 139 static inline spx_word32_t MULT16_32_Q14(spx_word16_t a, spx_word32_t b)
TMBOY 47:9e361da97763 140 {
TMBOY 47:9e361da97763 141 spx_word32_t res;
TMBOY 47:9e361da97763 142 __asm__
TMBOY 47:9e361da97763 143 (
TMBOY 47:9e361da97763 144 "%2 <<= 1;\n\t"
TMBOY 47:9e361da97763 145 "A1 = %1.L*%2.L (M);\n\t"
TMBOY 47:9e361da97763 146 "A1 = A1 >>> 15;\n\t"
TMBOY 47:9e361da97763 147 "%0 = (A1 += %1.L*%2.H);\n\t"
TMBOY 47:9e361da97763 148 : "=W" (res), "=d" (a), "=d" (b)
TMBOY 47:9e361da97763 149 : "1" (a), "2" (b)
TMBOY 47:9e361da97763 150 : "A1"
TMBOY 47:9e361da97763 151 );
TMBOY 47:9e361da97763 152 return res;
TMBOY 47:9e361da97763 153 }
TMBOY 47:9e361da97763 154
TMBOY 47:9e361da97763 155 #undef MAC16_32_Q14
TMBOY 47:9e361da97763 156 static inline spx_word32_t MAC16_32_Q14(spx_word32_t c, spx_word16_t a, spx_word32_t b)
TMBOY 47:9e361da97763 157 {
TMBOY 47:9e361da97763 158 spx_word32_t res;
TMBOY 47:9e361da97763 159 __asm__
TMBOY 47:9e361da97763 160 (
TMBOY 47:9e361da97763 161 "%1 <<= 1;\n\t"
TMBOY 47:9e361da97763 162 "A1 = %2.L*%1.L (M);\n\t"
TMBOY 47:9e361da97763 163 "A1 = A1 >>> 15;\n\t"
TMBOY 47:9e361da97763 164 "%0 = (A1 += %2.L*%1.H);\n\t"
TMBOY 47:9e361da97763 165 "%0 = %0 + %4;\n\t"
TMBOY 47:9e361da97763 166 : "=&W" (res), "=&d" (b)
TMBOY 47:9e361da97763 167 : "d" (a), "1" (b), "d" (c)
TMBOY 47:9e361da97763 168 : "A1"
TMBOY 47:9e361da97763 169 );
TMBOY 47:9e361da97763 170 return res;
TMBOY 47:9e361da97763 171 }
TMBOY 47:9e361da97763 172
TMBOY 47:9e361da97763 173 #endif