Main Page | Class List | Directories | File List | Class Members | File Members

fixed_bfin.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 Analog Devices
00002    Author: Jean-Marc Valin */
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 DIV32_16
00040 static inline spx_word16_t DIV32_16(spx_word32_t a, spx_word16_t b)
00041 {
00042    spx_word32_t res, bb;
00043    bb = b;
00044    __asm__  (
00045          "P0 = 15;\n\t"
00046          "R0 = %1;\n\t"
00047          "R1 = %2;\n\t"
00048          "R0 <<= 1;\n\t"
00049          "DIVS (R0, R1);\n\t"
00050          "LOOP divide%= LC0 = P0;\n\t"
00051          "LOOP_BEGIN divide%=;\n\t"
00052             "DIVQ (R0, R1);\n\t"
00053          "LOOP_END divide%=;\n\t"
00054          "R0 = R0.L;\n\t"
00055          "%0 = R0;\n\t"
00056    : "=m" (res)
00057    : "m" (a), "m" (bb)
00058    : "P0", "R0", "R1", "cc");
00059    return res;
00060 }
00061 
00062 #undef MAX16
00063 static inline spx_word16_t MAX16(spx_word16_t a, spx_word16_t b)
00064 {
00065    spx_word32_t res;
00066    __asm__  (
00067          "%1 = %1.L (X);\n\t"
00068          "%2 = %2.L (X);\n\t"
00069          "%0 = MAX(%1,%2);"
00070    : "=d" (res)
00071    : "%d" (a), "d" (b)
00072    );
00073    return res;
00074 }
00075 
00076 #undef MULT16_32_Q15
00077 static inline spx_word32_t MULT16_32_Q15(spx_word16_t a, spx_word32_t b)
00078 {
00079    spx_word32_t res;
00080    __asm__
00081    (
00082          "%1 <<= 1;\n\t"
00083          "A1 = %2.L*%1.L (M,IS);\n\t"
00084          "A1 = A1 >>> 16;\n\t"
00085          "R1 = (A1 += %2.L*%1.H) (IS);\n\t"
00086          "%0 = R1;\n\t"
00087    : "=&d" (res), "=&d" (b)
00088    : "d" (a), "1" (b)
00089    : "A1", "R1"
00090    );
00091    return res;
00092 }
00093 
00094 #undef MAC16_32_Q15
00095 static inline spx_word32_t MAC16_32_Q15(spx_word32_t c, spx_word16_t a, spx_word32_t b)
00096 {
00097    spx_word32_t res;
00098    __asm__
00099          (
00100          "%1 <<= 1;\n\t"
00101          "A1 = %2.L*%1.L (M,IS);\n\t"
00102          "A1 = A1 >>> 16;\n\t"
00103          "R1 = (A1 += %2.L*%1.H) (IS);\n\t"
00104          "%0 = R1 + %4;\n\t"
00105    : "=&d" (res), "=&d" (b)
00106    : "d" (a), "1" (b), "d" (c)
00107    : "A1", "R1"
00108          );
00109    return res;
00110 }
00111 
00112 #undef MULT16_32_Q14
00113 static inline spx_word32_t MULT16_32_Q14(spx_word16_t a, spx_word32_t b)
00114 {
00115    spx_word32_t res;
00116    __asm__
00117          (
00118          "%2 <<= 2;\n\t"
00119          "A1 = %1.L*%2.L (M,IS);\n\t"
00120          "A1 = A1 >>> 16;\n\t"
00121          "R1 = (A1 += %1.L*%2.H) (IS);\n\t"
00122          "%0 = R1;\n\t"
00123    : "=d" (res), "=d" (a), "=d" (b)
00124    : "1" (a), "2" (b)
00125    : "A1", "R1"
00126          );
00127    return res;
00128 }
00129 
00130 #undef MAC16_32_Q14
00131 static inline spx_word32_t MAC16_32_Q14(spx_word32_t c, spx_word16_t a, spx_word32_t b)
00132 {
00133    spx_word32_t res;
00134    __asm__
00135          (
00136          "%1 <<= 2;\n\t"
00137          "A1 = %2.L*%1.L (M,IS);\n\t"
00138          "A1 = A1 >>> 16;\n\t"
00139          "R1 = (A1 += %2.L*%1.H) (IS);\n\t"
00140          "%0 = R1 + %4;\n\t"
00141    : "=&d" (res), "=&d" (b)
00142    : "d" (a), "1" (b), "d" (c)
00143    : "A1", "R1"
00144          );
00145    return res;
00146 }
00147 
00148 #endif

Generated on Thu Jun 15 13:41:59 2006 for speex by  doxygen 1.4.2