ex

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fixed_arm5e.h Source File

fixed_arm5e.h

Go to the documentation of this file.
00001 /* Copyright (C) 2003 Jean-Marc Valin */
00002 /**
00003    @file fixed_arm5e.h
00004    @brief ARM-tuned fixed-point operations
00005 */
00006 /*
00007    Redistribution and use in source and binary forms, with or without
00008    modification, are permitted provided that the following conditions
00009    are met:
00010    
00011    - Redistributions of source code must retain the above copyright
00012    notice, this list of conditions and the following disclaimer.
00013    
00014    - Redistributions in binary form must reproduce the above copyright
00015    notice, this list of conditions and the following disclaimer in the
00016    documentation and/or other materials provided with the distribution.
00017    
00018    - Neither the name of the Xiph.org Foundation nor the names of its
00019    contributors may be used to endorse or promote products derived from
00020    this software without specific prior written permission.
00021    
00022    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
00026    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 */
00034 
00035 #ifndef FIXED_ARM5E_H
00036 #define FIXED_ARM5E_H
00037 
00038 #undef MULT16_16
00039 static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) {
00040   int res;
00041   asm ("smulbb  %0,%1,%2;\n"
00042               : "=&r"(res)
00043               : "%r"(x),"r"(y));
00044   return(res);
00045 }
00046 
00047 #undef MAC16_16
00048 static inline spx_word32_t MAC16_16(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
00049   int res;
00050   asm ("smlabb  %0,%1,%2,%3;\n"
00051               : "=&r"(res)
00052                : "%r"(x),"r"(y),"r"(a));
00053   return(res);
00054 }
00055 
00056 #undef MULT16_32_Q15
00057 static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) {
00058   int res;
00059   asm ("smulwb  %0,%1,%2;\n"
00060               : "=&r"(res)
00061                : "%r"(y<<1),"r"(x));
00062   return(res);
00063 }
00064 
00065 #undef MAC16_32_Q15
00066 static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
00067   int res;
00068   asm ("smlawb  %0,%1,%2,%3;\n"
00069               : "=&r"(res)
00070                : "%r"(y<<1),"r"(x),"r"(a));
00071   return(res);
00072 }
00073 
00074 #undef MULT16_32_Q11
00075 static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) {
00076   int res;
00077   asm ("smulwb  %0,%1,%2;\n"
00078               : "=&r"(res)
00079                : "%r"(y<<5),"r"(x));
00080   return(res);
00081 }
00082 
00083 #undef MAC16_32_Q11
00084 static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
00085   int res;
00086   asm ("smlawb  %0,%1,%2,%3;\n"
00087               : "=&r"(res)
00088                : "%r"(y<<5),"r"(x),"r"(a));
00089   return(res);
00090 }
00091 
00092 #undef DIV32_16
00093 static inline short DIV32_16(int a, int b)
00094 {
00095    int res=0;
00096    int dead1, dead2, dead3, dead4, dead5;
00097    __asm__ __volatile__ (
00098          "\teor %5, %0, %1\n"
00099          "\tmovs %4, %0\n"
00100          "\trsbmi %0, %0, #0 \n"
00101          "\tmovs %4, %1\n"
00102          "\trsbmi %1, %1, #0 \n"
00103          "\tmov %4, #1\n"
00104 
00105          "\tsubs %3, %0, %1, asl #14 \n"
00106          "\torrpl %2, %2, %4, asl #14 \n"
00107          "\tmovpl %0, %3 \n"
00108 
00109          "\tsubs %3, %0, %1, asl #13 \n"
00110          "\torrpl %2, %2, %4, asl #13 \n"
00111          "\tmovpl %0, %3 \n"
00112 
00113          "\tsubs %3, %0, %1, asl #12 \n"
00114          "\torrpl %2, %2, %4, asl #12 \n"
00115          "\tmovpl %0, %3 \n"
00116 
00117          "\tsubs %3, %0, %1, asl #11 \n"
00118          "\torrpl %2, %2, %4, asl #11 \n"
00119          "\tmovpl %0, %3 \n"
00120 
00121          "\tsubs %3, %0, %1, asl #10 \n"
00122          "\torrpl %2, %2, %4, asl #10 \n"
00123          "\tmovpl %0, %3 \n"
00124 
00125          "\tsubs %3, %0, %1, asl #9 \n"
00126          "\torrpl %2, %2, %4, asl #9 \n"
00127          "\tmovpl %0, %3 \n"
00128 
00129          "\tsubs %3, %0, %1, asl #8 \n"
00130          "\torrpl %2, %2, %4, asl #8 \n"
00131          "\tmovpl %0, %3 \n"
00132 
00133          "\tsubs %3, %0, %1, asl #7 \n"
00134          "\torrpl %2, %2, %4, asl #7 \n"
00135          "\tmovpl %0, %3 \n"
00136 
00137          "\tsubs %3, %0, %1, asl #6 \n"
00138          "\torrpl %2, %2, %4, asl #6 \n"
00139          "\tmovpl %0, %3 \n"
00140 
00141          "\tsubs %3, %0, %1, asl #5 \n"
00142          "\torrpl %2, %2, %4, asl #5 \n"
00143          "\tmovpl %0, %3 \n"
00144 
00145          "\tsubs %3, %0, %1, asl #4 \n"
00146          "\torrpl %2, %2, %4, asl #4 \n"
00147          "\tmovpl %0, %3 \n"
00148 
00149          "\tsubs %3, %0, %1, asl #3 \n"
00150          "\torrpl %2, %2, %4, asl #3 \n"
00151          "\tmovpl %0, %3 \n"
00152 
00153          "\tsubs %3, %0, %1, asl #2 \n"
00154          "\torrpl %2, %2, %4, asl #2 \n"
00155          "\tmovpl %0, %3 \n"
00156 
00157          "\tsubs %3, %0, %1, asl #1 \n"
00158          "\torrpl %2, %2, %4, asl #1 \n"
00159          "\tmovpl %0, %3 \n"
00160 
00161          "\tsubs %3, %0, %1 \n"
00162          "\torrpl %2, %2, %4 \n"
00163          "\tmovpl %0, %3 \n"
00164          
00165          "\tmovs %5, %5, lsr #31 \n"
00166          "\trsbne %2, %2, #0 \n"
00167    : "=r" (dead1), "=r" (dead2), "=r" (res),
00168    "=r" (dead3), "=r" (dead4), "=r" (dead5)
00169    : "0" (a), "1" (b), "2" (res)
00170    : "memory", "cc"
00171                         );
00172    return res;
00173 }
00174 
00175 
00176 
00177 
00178 #endif