ex

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

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

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