gst_plugins_base/gst/audioresample/fixed_arm5e.h
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
     1 /* Copyright (C) 2003 Jean-Marc Valin */
       
     2 /**
       
     3    @file fixed_arm5e.h
       
     4    @brief ARM-tuned fixed-point operations
       
     5 */
       
     6 /*
       
     7    Redistribution and use in source and binary forms, with or without
       
     8    modification, are permitted provided that the following conditions
       
     9    are met:
       
    10    
       
    11    - Redistributions of source code must retain the above copyright
       
    12    notice, this list of conditions and the following disclaimer.
       
    13    
       
    14    - Redistributions in binary form must reproduce the above copyright
       
    15    notice, this list of conditions and the following disclaimer in the
       
    16    documentation and/or other materials provided with the distribution.
       
    17    
       
    18    - Neither the name of the Xiph.org Foundation nor the names of its
       
    19    contributors may be used to endorse or promote products derived from
       
    20    this software without specific prior written permission.
       
    21    
       
    22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    23    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    25    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
       
    26    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    27    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    28    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    29    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
       
    30    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
       
    31    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
       
    32    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    33 */
       
    34 
       
    35 #ifndef FIXED_ARM5E_H
       
    36 #define FIXED_ARM5E_H
       
    37 
       
    38 #undef MULT16_16
       
    39 static inline spx_word32_t
       
    40 MULT16_16 (spx_word16_t x, spx_word16_t y)
       
    41 {
       
    42   int res;
       
    43 asm ("smulbb  %0,%1,%2;\n":"=&r" (res)
       
    44 :    "%r" (x), "r" (y));
       
    45   return (res);
       
    46 }
       
    47 
       
    48 #undef MAC16_16
       
    49 static inline spx_word32_t
       
    50 MAC16_16 (spx_word32_t a, spx_word16_t x, spx_word32_t y)
       
    51 {
       
    52   int res;
       
    53 asm ("smlabb  %0,%1,%2,%3;\n":"=&r" (res)
       
    54 :    "%r" (x), "r" (y), "r" (a));
       
    55   return (res);
       
    56 }
       
    57 
       
    58 #undef MULT16_32_Q15
       
    59 static inline spx_word32_t
       
    60 MULT16_32_Q15 (spx_word16_t x, spx_word32_t y)
       
    61 {
       
    62   int res;
       
    63 asm ("smulwb  %0,%1,%2;\n":"=&r" (res)
       
    64 :    "%r" (y << 1), "r" (x));
       
    65   return (res);
       
    66 }
       
    67 
       
    68 #undef MAC16_32_Q15
       
    69 static inline spx_word32_t
       
    70 MAC16_32_Q15 (spx_word32_t a, spx_word16_t x, spx_word32_t y)
       
    71 {
       
    72   int res;
       
    73 asm ("smlawb  %0,%1,%2,%3;\n":"=&r" (res)
       
    74 :    "%r" (y << 1), "r" (x), "r" (a));
       
    75   return (res);
       
    76 }
       
    77 
       
    78 #undef MULT16_32_Q11
       
    79 static inline spx_word32_t
       
    80 MULT16_32_Q11 (spx_word16_t x, spx_word32_t y)
       
    81 {
       
    82   int res;
       
    83 asm ("smulwb  %0,%1,%2;\n":"=&r" (res)
       
    84 :    "%r" (y << 5), "r" (x));
       
    85   return (res);
       
    86 }
       
    87 
       
    88 #undef MAC16_32_Q11
       
    89 static inline spx_word32_t
       
    90 MAC16_32_Q11 (spx_word32_t a, spx_word16_t x, spx_word32_t y)
       
    91 {
       
    92   int res;
       
    93 asm ("smlawb  %0,%1,%2,%3;\n":"=&r" (res)
       
    94 :    "%r" (y << 5), "r" (x), "r" (a));
       
    95   return (res);
       
    96 }
       
    97 
       
    98 #undef DIV32_16
       
    99 static inline short
       
   100 DIV32_16 (int a, int b)
       
   101 {
       
   102   int res = 0;
       
   103   int dead1, dead2, dead3, dead4, dead5;
       
   104   __asm__ __volatile__ ("\teor %5, %0, %1\n"
       
   105       "\tmovs %4, %0\n"
       
   106       "\trsbmi %0, %0, #0 \n"
       
   107       "\tmovs %4, %1\n"
       
   108       "\trsbmi %1, %1, #0 \n"
       
   109       "\tmov %4, #1\n"
       
   110       "\tsubs %3, %0, %1, asl #14 \n"
       
   111       "\torrpl %2, %2, %4, asl #14 \n"
       
   112       "\tmovpl %0, %3 \n"
       
   113       "\tsubs %3, %0, %1, asl #13 \n"
       
   114       "\torrpl %2, %2, %4, asl #13 \n"
       
   115       "\tmovpl %0, %3 \n"
       
   116       "\tsubs %3, %0, %1, asl #12 \n"
       
   117       "\torrpl %2, %2, %4, asl #12 \n"
       
   118       "\tmovpl %0, %3 \n"
       
   119       "\tsubs %3, %0, %1, asl #11 \n"
       
   120       "\torrpl %2, %2, %4, asl #11 \n"
       
   121       "\tmovpl %0, %3 \n"
       
   122       "\tsubs %3, %0, %1, asl #10 \n"
       
   123       "\torrpl %2, %2, %4, asl #10 \n"
       
   124       "\tmovpl %0, %3 \n"
       
   125       "\tsubs %3, %0, %1, asl #9 \n"
       
   126       "\torrpl %2, %2, %4, asl #9 \n"
       
   127       "\tmovpl %0, %3 \n"
       
   128       "\tsubs %3, %0, %1, asl #8 \n"
       
   129       "\torrpl %2, %2, %4, asl #8 \n"
       
   130       "\tmovpl %0, %3 \n"
       
   131       "\tsubs %3, %0, %1, asl #7 \n"
       
   132       "\torrpl %2, %2, %4, asl #7 \n"
       
   133       "\tmovpl %0, %3 \n"
       
   134       "\tsubs %3, %0, %1, asl #6 \n"
       
   135       "\torrpl %2, %2, %4, asl #6 \n"
       
   136       "\tmovpl %0, %3 \n"
       
   137       "\tsubs %3, %0, %1, asl #5 \n"
       
   138       "\torrpl %2, %2, %4, asl #5 \n"
       
   139       "\tmovpl %0, %3 \n"
       
   140       "\tsubs %3, %0, %1, asl #4 \n"
       
   141       "\torrpl %2, %2, %4, asl #4 \n"
       
   142       "\tmovpl %0, %3 \n"
       
   143       "\tsubs %3, %0, %1, asl #3 \n"
       
   144       "\torrpl %2, %2, %4, asl #3 \n"
       
   145       "\tmovpl %0, %3 \n"
       
   146       "\tsubs %3, %0, %1, asl #2 \n"
       
   147       "\torrpl %2, %2, %4, asl #2 \n"
       
   148       "\tmovpl %0, %3 \n"
       
   149       "\tsubs %3, %0, %1, asl #1 \n"
       
   150       "\torrpl %2, %2, %4, asl #1 \n"
       
   151       "\tmovpl %0, %3 \n"
       
   152       "\tsubs %3, %0, %1 \n"
       
   153       "\torrpl %2, %2, %4 \n"
       
   154       "\tmovpl %0, %3 \n"
       
   155       "\tmovs %5, %5, lsr #31 \n"
       
   156       "\trsbne %2, %2, #0 \n":"=r" (dead1), "=r" (dead2), "=r" (res),
       
   157       "=r" (dead3), "=r" (dead4), "=r" (dead5)
       
   158       :"0" (a), "1" (b), "2" (res)
       
   159       :"memory", "cc");
       
   160   return res;
       
   161 }
       
   162 
       
   163 
       
   164 
       
   165 
       
   166 #endif