bowen liu
/
mbed-os-example-blinky
ex
Fork of mbed-os-example-mbed5-blinky by
Embed:
(wiki syntax)
Show/hide line numbers
fixed_bfin.h
Go to the documentation of this file.
00001 /* Copyright (C) 2005 Analog Devices 00002 Author: Jean-Marc Valin */ 00003 /** 00004 @file fixed_bfin.h 00005 @brief Blackfin fixed-point operations 00006 */ 00007 /* 00008 Redistribution and use in source and binary forms, with or without 00009 modification, are permitted provided that the following conditions 00010 are met: 00011 00012 - Redistributions of source code must retain the above copyright 00013 notice, this list of conditions and the following disclaimer. 00014 00015 - Redistributions in binary form must reproduce the above copyright 00016 notice, this list of conditions and the following disclaimer in the 00017 documentation and/or other materials provided with the distribution. 00018 00019 - Neither the name of the Xiph.org Foundation nor the names of its 00020 contributors may be used to endorse or promote products derived from 00021 this software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00026 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 00027 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00028 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00029 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00030 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00031 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00032 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 00036 #ifndef FIXED_BFIN_H 00037 #define FIXED_BFIN_H 00038 00039 #undef PDIV32_16 00040 static inline spx_word16_t PDIV32_16(spx_word32_t a, spx_word16_t b) 00041 { 00042 spx_word32_t res, bb; 00043 bb = b; 00044 a += b>>1; 00045 __asm__ ( 00046 "P0 = 15;\n\t" 00047 "R0 = %1;\n\t" 00048 "R1 = %2;\n\t" 00049 //"R0 = R0 + R1;\n\t" 00050 "R0 <<= 1;\n\t" 00051 "DIVS (R0, R1);\n\t" 00052 "LOOP divide%= LC0 = P0;\n\t" 00053 "LOOP_BEGIN divide%=;\n\t" 00054 "DIVQ (R0, R1);\n\t" 00055 "LOOP_END divide%=;\n\t" 00056 "R0 = R0.L;\n\t" 00057 "%0 = R0;\n\t" 00058 : "=m" (res) 00059 : "m" (a), "m" (bb) 00060 : "P0", "R0", "R1", "cc"); 00061 return res; 00062 } 00063 00064 #undef DIV32_16 00065 static inline spx_word16_t DIV32_16(spx_word32_t a, spx_word16_t b) 00066 { 00067 spx_word32_t res, bb; 00068 bb = b; 00069 /* Make the roundinf consistent with the C version 00070 (do we need to do that?)*/ 00071 if (a<0) 00072 a += (b-1); 00073 __asm__ ( 00074 "P0 = 15;\n\t" 00075 "R0 = %1;\n\t" 00076 "R1 = %2;\n\t" 00077 "R0 <<= 1;\n\t" 00078 "DIVS (R0, R1);\n\t" 00079 "LOOP divide%= LC0 = P0;\n\t" 00080 "LOOP_BEGIN divide%=;\n\t" 00081 "DIVQ (R0, R1);\n\t" 00082 "LOOP_END divide%=;\n\t" 00083 "R0 = R0.L;\n\t" 00084 "%0 = R0;\n\t" 00085 : "=m" (res) 00086 : "m" (a), "m" (bb) 00087 : "P0", "R0", "R1", "cc"); 00088 return res; 00089 } 00090 00091 #undef MAX16 00092 static inline spx_word16_t MAX16(spx_word16_t a, spx_word16_t b) 00093 { 00094 spx_word32_t res; 00095 __asm__ ( 00096 "%1 = %1.L (X);\n\t" 00097 "%2 = %2.L (X);\n\t" 00098 "%0 = MAX(%1,%2);" 00099 : "=d" (res) 00100 : "%d" (a), "d" (b) 00101 ); 00102 return res; 00103 } 00104 00105 #undef MULT16_32_Q15 00106 static inline spx_word32_t MULT16_32_Q15(spx_word16_t a, spx_word32_t b) 00107 { 00108 spx_word32_t res; 00109 __asm__ 00110 ( 00111 "A1 = %2.L*%1.L (M);\n\t" 00112 "A1 = A1 >>> 15;\n\t" 00113 "%0 = (A1 += %2.L*%1.H) ;\n\t" 00114 : "=&W" (res), "=&d" (b) 00115 : "d" (a), "1" (b) 00116 : "A1" 00117 ); 00118 return res; 00119 } 00120 00121 #undef MAC16_32_Q15 00122 static inline spx_word32_t MAC16_32_Q15(spx_word32_t c, spx_word16_t a, spx_word32_t b) 00123 { 00124 spx_word32_t res; 00125 __asm__ 00126 ( 00127 "A1 = %2.L*%1.L (M);\n\t" 00128 "A1 = A1 >>> 15;\n\t" 00129 "%0 = (A1 += %2.L*%1.H);\n\t" 00130 "%0 = %0 + %4;\n\t" 00131 : "=&W" (res), "=&d" (b) 00132 : "d" (a), "1" (b), "d" (c) 00133 : "A1" 00134 ); 00135 return res; 00136 } 00137 00138 #undef MULT16_32_Q14 00139 static inline spx_word32_t MULT16_32_Q14(spx_word16_t a, spx_word32_t b) 00140 { 00141 spx_word32_t res; 00142 __asm__ 00143 ( 00144 "%2 <<= 1;\n\t" 00145 "A1 = %1.L*%2.L (M);\n\t" 00146 "A1 = A1 >>> 15;\n\t" 00147 "%0 = (A1 += %1.L*%2.H);\n\t" 00148 : "=W" (res), "=d" (a), "=d" (b) 00149 : "1" (a), "2" (b) 00150 : "A1" 00151 ); 00152 return res; 00153 } 00154 00155 #undef MAC16_32_Q14 00156 static inline spx_word32_t MAC16_32_Q14(spx_word32_t c, spx_word16_t a, spx_word32_t b) 00157 { 00158 spx_word32_t res; 00159 __asm__ 00160 ( 00161 "%1 <<= 1;\n\t" 00162 "A1 = %2.L*%1.L (M);\n\t" 00163 "A1 = A1 >>> 15;\n\t" 00164 "%0 = (A1 += %2.L*%1.H);\n\t" 00165 "%0 = %0 + %4;\n\t" 00166 : "=&W" (res), "=&d" (b) 00167 : "d" (a), "1" (b), "d" (c) 00168 : "A1" 00169 ); 00170 return res; 00171 } 00172 00173 #endif
Generated on Tue Jul 12 2022 16:28:53 by 1.7.2