1 /* Copyright (C) 2005 Analog Devices
2 Author: Jean-Marc Valin */
5 @brief Blackfin fixed-point operations
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
15 - Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
19 - Neither the name of the Xiph.org Foundation nor the names of its
20 contributors may be used to endorse or promote products derived from
21 this software without specific prior written permission.
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 static inline spx_word16_t
PDIV32_16(spx_word32_t a
, spx_word16_t b
)
52 "LOOP divide%= LC0 = P0;\n\t"
53 "LOOP_BEGIN divide%=;\n\t"
55 "LOOP_END divide%=;\n\t"
60 : "P0", "R0", "R1", "cc");
65 static inline spx_word16_t
DIV32_16(spx_word32_t a
, spx_word16_t b
)
69 /* Make the roundinf consistent with the C version
70 (do we need to do that?)*/
79 "LOOP divide%= LC0 = P0;\n\t"
80 "LOOP_BEGIN divide%=;\n\t"
82 "LOOP_END divide%=;\n\t"
87 : "P0", "R0", "R1", "cc");
92 static inline spx_word16_t
MAX16(spx_word16_t a
, spx_word16_t b
)
106 static inline spx_word32_t
MULT16_32_Q15(spx_word16_t a
, spx_word32_t b
)
111 "A1 = %2.L*%1.L (M);\n\t"
112 "A1 = A1 >>> 15;\n\t"
113 "%0 = (A1 += %2.L*%1.H) ;\n\t"
114 : "=&W" (res
), "=&d" (b
)
122 static inline spx_word32_t
MAC16_32_Q15(spx_word32_t c
, spx_word16_t a
, spx_word32_t b
)
127 "A1 = %2.L*%1.L (M);\n\t"
128 "A1 = A1 >>> 15;\n\t"
129 "%0 = (A1 += %2.L*%1.H);\n\t"
131 : "=&W" (res
), "=&d" (b
)
132 : "d" (a
), "1" (b
), "d" (c
)
139 static inline spx_word32_t
MULT16_32_Q14(spx_word16_t a
, spx_word32_t b
)
145 "A1 = %1.L*%2.L (M);\n\t"
146 "A1 = A1 >>> 15;\n\t"
147 "%0 = (A1 += %1.L*%2.H);\n\t"
148 : "=W" (res
), "=d" (a
), "=d" (b
)
156 static inline spx_word32_t
MAC16_32_Q14(spx_word32_t c
, spx_word16_t a
, spx_word32_t b
)
162 "A1 = %2.L*%1.L (M);\n\t"
163 "A1 = A1 >>> 15;\n\t"
164 "%0 = (A1 += %2.L*%1.H);\n\t"
166 : "=&W" (res
), "=&d" (b
)
167 : "d" (a
), "1" (b
), "d" (c
)