ex

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fixed_arm4.h Source File

fixed_arm4.h

Go to the documentation of this file.
00001 /* Copyright (C) 2004 Jean-Marc Valin */
00002 /**
00003    @file fixed_arm4.h
00004    @brief ARM4 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_ARM4_H
00036 #define FIXED_ARM4_H
00037 
00038 #undef MULT16_32_Q14
00039 static inline spx_word32_t MULT16_32_Q14(spx_word16_t x, spx_word32_t y) {
00040   int res;
00041   int dummy;
00042   asm (
00043         "smull  %0,%1,%2,%3 \n\t"
00044         "mov %0, %0, lsr #14 \n\t"
00045         "add %0, %0, %1, lsl #18 \n\t"
00046    : "=&r"(res), "=&r" (dummy)
00047    : "r"(y),"r"((int)x));
00048   return(res);
00049 }
00050 
00051 #undef MULT16_32_Q15
00052 static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) {
00053   int res;
00054   int dummy;
00055   asm (
00056         "smull  %0,%1,%2,%3 \n\t"
00057         "mov %0, %0, lsr #15 \n\t"
00058         "add %0, %0, %1, lsl #17 \n\t"
00059    : "=&r"(res), "=&r" (dummy)
00060    : "r"(y),"r"((int)x));
00061   return(res);
00062 }
00063 
00064 #undef DIV32_16
00065 static inline short DIV32_16(int a, int b)
00066 {
00067    int res=0;
00068    int dead1, dead2, dead3, dead4, dead5;
00069    __asm__ __volatile__ (
00070          "\teor %5, %0, %1\n"
00071          "\tmovs %4, %0\n"
00072          "\trsbmi %0, %0, #0 \n"
00073          "\tmovs %4, %1\n"
00074          "\trsbmi %1, %1, #0 \n"
00075          "\tmov %4, #1\n"
00076 
00077          "\tsubs %3, %0, %1, asl #14 \n"
00078          "\tmovpl %0, %3 \n"
00079          "\torrpl %2, %2, %4, asl #14 \n"
00080 
00081          "\tsubs %3, %0, %1, asl #13 \n"
00082          "\tmovpl %0, %3 \n"
00083          "\torrpl %2, %2, %4, asl #13 \n"
00084 
00085          "\tsubs %3, %0, %1, asl #12 \n"
00086          "\tmovpl %0, %3 \n"
00087          "\torrpl %2, %2, %4, asl #12 \n"
00088 
00089          "\tsubs %3, %0, %1, asl #11 \n"
00090          "\tmovpl %0, %3 \n"
00091          "\torrpl %2, %2, %4, asl #11 \n"
00092 
00093          "\tsubs %3, %0, %1, asl #10 \n"
00094          "\tmovpl %0, %3 \n"
00095          "\torrpl %2, %2, %4, asl #10 \n"
00096 
00097          "\tsubs %3, %0, %1, asl #9 \n"
00098          "\tmovpl %0, %3 \n"
00099          "\torrpl %2, %2, %4, asl #9 \n"
00100 
00101          "\tsubs %3, %0, %1, asl #8 \n"
00102          "\tmovpl %0, %3 \n"
00103          "\torrpl %2, %2, %4, asl #8 \n"
00104 
00105          "\tsubs %3, %0, %1, asl #7 \n"
00106          "\tmovpl %0, %3 \n"
00107          "\torrpl %2, %2, %4, asl #7 \n"
00108 
00109          "\tsubs %3, %0, %1, asl #6 \n"
00110          "\tmovpl %0, %3 \n"
00111          "\torrpl %2, %2, %4, asl #6 \n"
00112          
00113          "\tsubs %3, %0, %1, asl #5 \n"
00114          "\tmovpl %0, %3 \n"
00115          "\torrpl %2, %2, %4, asl #5 \n"
00116 
00117          "\tsubs %3, %0, %1, asl #4 \n"
00118          "\tmovpl %0, %3 \n"
00119          "\torrpl %2, %2, %4, asl #4 \n"
00120 
00121          "\tsubs %3, %0, %1, asl #3 \n"
00122          "\tmovpl %0, %3 \n"
00123          "\torrpl %2, %2, %4, asl #3 \n"
00124 
00125          "\tsubs %3, %0, %1, asl #2 \n"
00126          "\tmovpl %0, %3 \n"
00127          "\torrpl %2, %2, %4, asl #2 \n"
00128 
00129          "\tsubs %3, %0, %1, asl #1 \n"
00130          "\tmovpl %0, %3 \n"
00131          "\torrpl %2, %2, %4, asl #1 \n"
00132 
00133          "\tsubs %3, %0, %1 \n"
00134          "\tmovpl %0, %3 \n"
00135          "\torrpl %2, %2, %4 \n"
00136 
00137          "\tmovs %5, %5, lsr #31 \n"
00138          "\trsbne %2, %2, #0 \n"
00139    : "=r" (dead1), "=r" (dead2), "=r" (res),
00140    "=r" (dead3), "=r" (dead4), "=r" (dead5)
00141    : "0" (a), "1" (b), "2" (res)
00142    : "cc"
00143                         );
00144    return res;
00145 }
00146 
00147 
00148 #endif