Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* Copyright (C) 2004 Jean-Marc Valin */ |
| 2 | /** |
| 3 | @file fixed_arm4.h |
| 4 | @brief ARM4 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_ARM4_H |
| 36 | #define FIXED_ARM4_H |
| 37 | |
| 38 | #undef MULT16_32_Q14 |
| 39 | static inline spx_word32_t MULT16_32_Q14(spx_word16_t x, spx_word32_t y) { |
| 40 | int res; |
| 41 | int dummy; |
| 42 | asm ( |
| 43 | "smull %0,%1,%2,%3 \n\t" |
| 44 | "mov %0, %0, lsr #14 \n\t" |
| 45 | "add %0, %0, %1, lsl #18 \n\t" |
| 46 | : "=&r"(res), "=&r" (dummy) |
| 47 | : "r"(y),"r"((int)x)); |
| 48 | return(res); |
| 49 | } |
| 50 | |
| 51 | #undef MULT16_32_Q15 |
| 52 | static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) { |
| 53 | int res; |
| 54 | int dummy; |
| 55 | asm ( |
| 56 | "smull %0,%1,%2,%3 \n\t" |
| 57 | "mov %0, %0, lsr #15 \n\t" |
| 58 | "add %0, %0, %1, lsl #17 \n\t" |
| 59 | : "=&r"(res), "=&r" (dummy) |
| 60 | : "r"(y),"r"((int)x)); |
| 61 | return(res); |
| 62 | } |
| 63 | |
| 64 | #undef DIV32_16 |
| 65 | static inline short DIV32_16(int a, int b) |
| 66 | { |
| 67 | int res=0; |
| 68 | int dead1, dead2, dead3, dead4, dead5; |
| 69 | __asm__ __volatile__ ( |
| 70 | "\teor %5, %0, %1\n" |
| 71 | "\tmovs %4, %0\n" |
| 72 | "\trsbmi %0, %0, #0 \n" |
| 73 | "\tmovs %4, %1\n" |
| 74 | "\trsbmi %1, %1, #0 \n" |
| 75 | "\tmov %4, #1\n" |
| 76 | |
| 77 | "\tsubs %3, %0, %1, asl #14 \n" |
| 78 | "\tmovpl %0, %3 \n" |
| 79 | "\torrpl %2, %2, %4, asl #14 \n" |
| 80 | |
| 81 | "\tsubs %3, %0, %1, asl #13 \n" |
| 82 | "\tmovpl %0, %3 \n" |
| 83 | "\torrpl %2, %2, %4, asl #13 \n" |
| 84 | |
| 85 | "\tsubs %3, %0, %1, asl #12 \n" |
| 86 | "\tmovpl %0, %3 \n" |
| 87 | "\torrpl %2, %2, %4, asl #12 \n" |
| 88 | |
| 89 | "\tsubs %3, %0, %1, asl #11 \n" |
| 90 | "\tmovpl %0, %3 \n" |
| 91 | "\torrpl %2, %2, %4, asl #11 \n" |
| 92 | |
| 93 | "\tsubs %3, %0, %1, asl #10 \n" |
| 94 | "\tmovpl %0, %3 \n" |
| 95 | "\torrpl %2, %2, %4, asl #10 \n" |
| 96 | |
| 97 | "\tsubs %3, %0, %1, asl #9 \n" |
| 98 | "\tmovpl %0, %3 \n" |
| 99 | "\torrpl %2, %2, %4, asl #9 \n" |
| 100 | |
| 101 | "\tsubs %3, %0, %1, asl #8 \n" |
| 102 | "\tmovpl %0, %3 \n" |
| 103 | "\torrpl %2, %2, %4, asl #8 \n" |
| 104 | |
| 105 | "\tsubs %3, %0, %1, asl #7 \n" |
| 106 | "\tmovpl %0, %3 \n" |
| 107 | "\torrpl %2, %2, %4, asl #7 \n" |
| 108 | |
| 109 | "\tsubs %3, %0, %1, asl #6 \n" |
| 110 | "\tmovpl %0, %3 \n" |
| 111 | "\torrpl %2, %2, %4, asl #6 \n" |
| 112 | |
| 113 | "\tsubs %3, %0, %1, asl #5 \n" |
| 114 | "\tmovpl %0, %3 \n" |
| 115 | "\torrpl %2, %2, %4, asl #5 \n" |
| 116 | |
| 117 | "\tsubs %3, %0, %1, asl #4 \n" |
| 118 | "\tmovpl %0, %3 \n" |
| 119 | "\torrpl %2, %2, %4, asl #4 \n" |
| 120 | |
| 121 | "\tsubs %3, %0, %1, asl #3 \n" |
| 122 | "\tmovpl %0, %3 \n" |
| 123 | "\torrpl %2, %2, %4, asl #3 \n" |
| 124 | |
| 125 | "\tsubs %3, %0, %1, asl #2 \n" |
| 126 | "\tmovpl %0, %3 \n" |
| 127 | "\torrpl %2, %2, %4, asl #2 \n" |
| 128 | |
| 129 | "\tsubs %3, %0, %1, asl #1 \n" |
| 130 | "\tmovpl %0, %3 \n" |
| 131 | "\torrpl %2, %2, %4, asl #1 \n" |
| 132 | |
| 133 | "\tsubs %3, %0, %1 \n" |
| 134 | "\tmovpl %0, %3 \n" |
| 135 | "\torrpl %2, %2, %4 \n" |
| 136 | |
| 137 | "\tmovs %5, %5, lsr #31 \n" |
| 138 | "\trsbne %2, %2, #0 \n" |
| 139 | : "=r" (dead1), "=r" (dead2), "=r" (res), |
| 140 | "=r" (dead3), "=r" (dead4), "=r" (dead5) |
| 141 | : "0" (a), "1" (b), "2" (res) |
| 142 | : "cc" |
| 143 | ); |
| 144 | return res; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | #endif |