FS#8961 - Anti-Aliased Fonts.
[kugel-rb/myfork.git] / apps / codecs / libspeex / fixed_bfin.h
blobaa26f6a87d02ef0d872d55a98c3735e514795a00
1 /* Copyright (C) 2005 Analog Devices
2 Author: Jean-Marc Valin */
3 /**
4 @file fixed_bfin.h
5 @brief Blackfin fixed-point operations
6 */
7 /*
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
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.
36 #ifndef FIXED_BFIN_H
37 #define FIXED_BFIN_H
39 #undef PDIV32_16
40 static inline spx_word16_t PDIV32_16(spx_word32_t a, spx_word16_t b)
42 spx_word32_t res, bb;
43 bb = b;
44 a += b>>1;
45 __asm__ (
46 "P0 = 15;\n\t"
47 "R0 = %1;\n\t"
48 "R1 = %2;\n\t"
49 //"R0 = R0 + R1;\n\t"
50 "R0 <<= 1;\n\t"
51 "DIVS (R0, R1);\n\t"
52 "LOOP divide%= LC0 = P0;\n\t"
53 "LOOP_BEGIN divide%=;\n\t"
54 "DIVQ (R0, R1);\n\t"
55 "LOOP_END divide%=;\n\t"
56 "R0 = R0.L;\n\t"
57 "%0 = R0;\n\t"
58 : "=m" (res)
59 : "m" (a), "m" (bb)
60 : "P0", "R0", "R1", "cc");
61 return res;
64 #undef DIV32_16
65 static inline spx_word16_t DIV32_16(spx_word32_t a, spx_word16_t b)
67 spx_word32_t res, bb;
68 bb = b;
69 /* Make the roundinf consistent with the C version
70 (do we need to do that?)*/
71 if (a<0)
72 a += (b-1);
73 __asm__ (
74 "P0 = 15;\n\t"
75 "R0 = %1;\n\t"
76 "R1 = %2;\n\t"
77 "R0 <<= 1;\n\t"
78 "DIVS (R0, R1);\n\t"
79 "LOOP divide%= LC0 = P0;\n\t"
80 "LOOP_BEGIN divide%=;\n\t"
81 "DIVQ (R0, R1);\n\t"
82 "LOOP_END divide%=;\n\t"
83 "R0 = R0.L;\n\t"
84 "%0 = R0;\n\t"
85 : "=m" (res)
86 : "m" (a), "m" (bb)
87 : "P0", "R0", "R1", "cc");
88 return res;
91 #undef MAX16
92 static inline spx_word16_t MAX16(spx_word16_t a, spx_word16_t b)
94 spx_word32_t res;
95 __asm__ (
96 "%1 = %1.L (X);\n\t"
97 "%2 = %2.L (X);\n\t"
98 "%0 = MAX(%1,%2);"
99 : "=d" (res)
100 : "%d" (a), "d" (b)
102 return res;
105 #undef MULT16_32_Q15
106 static inline spx_word32_t MULT16_32_Q15(spx_word16_t a, spx_word32_t b)
108 spx_word32_t res;
109 __asm__
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)
115 : "d" (a), "1" (b)
116 : "A1"
118 return res;
121 #undef MAC16_32_Q15
122 static inline spx_word32_t MAC16_32_Q15(spx_word32_t c, spx_word16_t a, spx_word32_t b)
124 spx_word32_t res;
125 __asm__
127 "A1 = %2.L*%1.L (M);\n\t"
128 "A1 = A1 >>> 15;\n\t"
129 "%0 = (A1 += %2.L*%1.H);\n\t"
130 "%0 = %0 + %4;\n\t"
131 : "=&W" (res), "=&d" (b)
132 : "d" (a), "1" (b), "d" (c)
133 : "A1"
135 return res;
138 #undef MULT16_32_Q14
139 static inline spx_word32_t MULT16_32_Q14(spx_word16_t a, spx_word32_t b)
141 spx_word32_t res;
142 __asm__
144 "%2 <<= 1;\n\t"
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)
149 : "1" (a), "2" (b)
150 : "A1"
152 return res;
155 #undef MAC16_32_Q14
156 static inline spx_word32_t MAC16_32_Q14(spx_word32_t c, spx_word16_t a, spx_word32_t b)
158 spx_word32_t res;
159 __asm__
161 "%1 <<= 1;\n\t"
162 "A1 = %2.L*%1.L (M);\n\t"
163 "A1 = A1 >>> 15;\n\t"
164 "%0 = (A1 += %2.L*%1.H);\n\t"
165 "%0 = %0 + %4;\n\t"
166 : "=&W" (res), "=&d" (b)
167 : "d" (a), "1" (b), "d" (c)
168 : "A1"
170 return res;
173 #endif