annotate include/longlong.h @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1991-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of the GNU C Library.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 The GNU C Library is free software; you can redistribute it and/or
kono
parents:
diff changeset
7 modify it under the terms of the GNU Lesser General Public
kono
parents:
diff changeset
8 License as published by the Free Software Foundation; either
kono
parents:
diff changeset
9 version 2.1 of the License, or (at your option) any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 In addition to the permissions in the GNU Lesser General Public
kono
parents:
diff changeset
12 License, the Free Software Foundation gives you unlimited
kono
parents:
diff changeset
13 permission to link the compiled version of this file into
kono
parents:
diff changeset
14 combinations with other programs, and to distribute those
kono
parents:
diff changeset
15 combinations without any restriction coming from the use of this
kono
parents:
diff changeset
16 file. (The Lesser General Public License restrictions do apply in
kono
parents:
diff changeset
17 other respects; for example, they cover modification of the file,
kono
parents:
diff changeset
18 and distribution when not linked into a combine executable.)
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 The GNU C Library is distributed in the hope that it will be useful,
kono
parents:
diff changeset
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kono
parents:
diff changeset
23 Lesser General Public License for more details.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 You should have received a copy of the GNU Lesser General Public
kono
parents:
diff changeset
26 License along with the GNU C Library; if not, see
kono
parents:
diff changeset
27 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 /* You have to define the following before including this file:
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 UWtype -- An unsigned type, default type for operations (typically a "word")
kono
parents:
diff changeset
32 UHWtype -- An unsigned type, at least half the size of UWtype.
kono
parents:
diff changeset
33 UDWtype -- An unsigned type, at least twice as large a UWtype
kono
parents:
diff changeset
34 W_TYPE_SIZE -- size in bits of UWtype
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 UQItype -- Unsigned 8 bit type.
kono
parents:
diff changeset
37 SItype, USItype -- Signed and unsigned 32 bit types.
kono
parents:
diff changeset
38 DItype, UDItype -- Signed and unsigned 64 bit types.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 On a 32 bit machine UWtype should typically be USItype;
kono
parents:
diff changeset
41 on a 64 bit machine, UWtype should typically be UDItype. */
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 #define __BITS4 (W_TYPE_SIZE / 4)
kono
parents:
diff changeset
44 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
kono
parents:
diff changeset
45 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
kono
parents:
diff changeset
46 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 #ifndef W_TYPE_SIZE
kono
parents:
diff changeset
49 #define W_TYPE_SIZE 32
kono
parents:
diff changeset
50 #define UWtype USItype
kono
parents:
diff changeset
51 #define UHWtype USItype
kono
parents:
diff changeset
52 #define UDWtype UDItype
kono
parents:
diff changeset
53 #endif
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 /* Used in glibc only. */
kono
parents:
diff changeset
56 #ifndef attribute_hidden
kono
parents:
diff changeset
57 #define attribute_hidden
kono
parents:
diff changeset
58 #endif
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 extern const UQItype __clz_tab[256] attribute_hidden;
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 /* Define auxiliary asm macros.
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 1) umul_ppmm(high_prod, low_prod, multiplier, multiplicand) multiplies two
kono
parents:
diff changeset
65 UWtype integers MULTIPLIER and MULTIPLICAND, and generates a two UWtype
kono
parents:
diff changeset
66 word product in HIGH_PROD and LOW_PROD.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
kono
parents:
diff changeset
69 UDWtype product. This is just a variant of umul_ppmm.
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
kono
parents:
diff changeset
72 denominator) divides a UDWtype, composed by the UWtype integers
kono
parents:
diff changeset
73 HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
kono
parents:
diff changeset
74 in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
kono
parents:
diff changeset
75 than DENOMINATOR for correct operation. If, in addition, the most
kono
parents:
diff changeset
76 significant bit of DENOMINATOR must be 1, then the pre-processor symbol
kono
parents:
diff changeset
77 UDIV_NEEDS_NORMALIZATION is defined to 1.
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
kono
parents:
diff changeset
80 denominator). Like udiv_qrnnd but the numbers are signed. The quotient
kono
parents:
diff changeset
81 is rounded towards 0.
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 5) count_leading_zeros(count, x) counts the number of zero-bits from the
kono
parents:
diff changeset
84 msb to the first nonzero bit in the UWtype X. This is the number of
kono
parents:
diff changeset
85 steps X needs to be shifted left to set the msb. Undefined for X == 0,
kono
parents:
diff changeset
86 unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
kono
parents:
diff changeset
89 from the least significant end.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
kono
parents:
diff changeset
92 high_addend_2, low_addend_2) adds two UWtype integers, composed by
kono
parents:
diff changeset
93 HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
kono
parents:
diff changeset
94 respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow
kono
parents:
diff changeset
95 (i.e. carry out) is not stored anywhere, and is lost.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
kono
parents:
diff changeset
98 high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
kono
parents:
diff changeset
99 composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
kono
parents:
diff changeset
100 LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE
kono
parents:
diff changeset
101 and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
kono
parents:
diff changeset
102 and is lost.
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 If any of these macros are left undefined for a particular CPU,
kono
parents:
diff changeset
105 C macros are used. */
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 /* The CPUs come in alphabetical order below.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 Please add support for more CPUs here, or improve the current support
kono
parents:
diff changeset
110 for the CPUs below!
kono
parents:
diff changeset
111 (E.g. WE32100, IBM360.) */
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 #if defined (__GNUC__) && !defined (NO_ASM)
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 /* We sometimes need to clobber "cc" with gcc2, but that would not be
kono
parents:
diff changeset
116 understood by gcc1. Use cpp to avoid major code duplication. */
kono
parents:
diff changeset
117 #if __GNUC__ < 2
kono
parents:
diff changeset
118 #define __CLOBBER_CC
kono
parents:
diff changeset
119 #define __AND_CLOBBER_CC
kono
parents:
diff changeset
120 #else /* __GNUC__ >= 2 */
kono
parents:
diff changeset
121 #define __CLOBBER_CC : "cc"
kono
parents:
diff changeset
122 #define __AND_CLOBBER_CC , "cc"
kono
parents:
diff changeset
123 #endif /* __GNUC__ < 2 */
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 #if defined (__aarch64__)
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 #if W_TYPE_SIZE == 32
kono
parents:
diff changeset
128 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
kono
parents:
diff changeset
129 #define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X))
kono
parents:
diff changeset
130 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
131 #endif /* W_TYPE_SIZE == 32 */
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 #if W_TYPE_SIZE == 64
kono
parents:
diff changeset
134 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clzll (X))
kono
parents:
diff changeset
135 #define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctzll (X))
kono
parents:
diff changeset
136 #define COUNT_LEADING_ZEROS_0 64
kono
parents:
diff changeset
137 #endif /* W_TYPE_SIZE == 64 */
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 #endif /* __aarch64__ */
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 #if defined (__alpha) && W_TYPE_SIZE == 64
kono
parents:
diff changeset
142 /* There is a bug in g++ before version 5 that
kono
parents:
diff changeset
143 errors on __builtin_alpha_umulh. */
kono
parents:
diff changeset
144 #if !defined(__cplusplus) || __GNUC__ >= 5
kono
parents:
diff changeset
145 #define umul_ppmm(ph, pl, m0, m1) \
kono
parents:
diff changeset
146 do { \
kono
parents:
diff changeset
147 UDItype __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
148 (ph) = __builtin_alpha_umulh (__m0, __m1); \
kono
parents:
diff changeset
149 (pl) = __m0 * __m1; \
kono
parents:
diff changeset
150 } while (0)
kono
parents:
diff changeset
151 #define UMUL_TIME 46
kono
parents:
diff changeset
152 #endif /* !c++ */
kono
parents:
diff changeset
153 #ifndef LONGLONG_STANDALONE
kono
parents:
diff changeset
154 #define udiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
155 do { UDItype __r; \
kono
parents:
diff changeset
156 (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \
kono
parents:
diff changeset
157 (r) = __r; \
kono
parents:
diff changeset
158 } while (0)
kono
parents:
diff changeset
159 extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
kono
parents:
diff changeset
160 #define UDIV_TIME 220
kono
parents:
diff changeset
161 #endif /* LONGLONG_STANDALONE */
kono
parents:
diff changeset
162 #ifdef __alpha_cix__
kono
parents:
diff changeset
163 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clzl (X))
kono
parents:
diff changeset
164 #define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctzl (X))
kono
parents:
diff changeset
165 #define COUNT_LEADING_ZEROS_0 64
kono
parents:
diff changeset
166 #else
kono
parents:
diff changeset
167 #define count_leading_zeros(COUNT,X) \
kono
parents:
diff changeset
168 do { \
kono
parents:
diff changeset
169 UDItype __xr = (X), __t, __a; \
kono
parents:
diff changeset
170 __t = __builtin_alpha_cmpbge (0, __xr); \
kono
parents:
diff changeset
171 __a = __clz_tab[__t ^ 0xff] - 1; \
kono
parents:
diff changeset
172 __t = __builtin_alpha_extbl (__xr, __a); \
kono
parents:
diff changeset
173 (COUNT) = 64 - (__clz_tab[__t] + __a*8); \
kono
parents:
diff changeset
174 } while (0)
kono
parents:
diff changeset
175 #define count_trailing_zeros(COUNT,X) \
kono
parents:
diff changeset
176 do { \
kono
parents:
diff changeset
177 UDItype __xr = (X), __t, __a; \
kono
parents:
diff changeset
178 __t = __builtin_alpha_cmpbge (0, __xr); \
kono
parents:
diff changeset
179 __t = ~__t & -~__t; \
kono
parents:
diff changeset
180 __a = ((__t & 0xCC) != 0) * 2; \
kono
parents:
diff changeset
181 __a += ((__t & 0xF0) != 0) * 4; \
kono
parents:
diff changeset
182 __a += ((__t & 0xAA) != 0); \
kono
parents:
diff changeset
183 __t = __builtin_alpha_extbl (__xr, __a); \
kono
parents:
diff changeset
184 __a <<= 3; \
kono
parents:
diff changeset
185 __t &= -__t; \
kono
parents:
diff changeset
186 __a += ((__t & 0xCC) != 0) * 2; \
kono
parents:
diff changeset
187 __a += ((__t & 0xF0) != 0) * 4; \
kono
parents:
diff changeset
188 __a += ((__t & 0xAA) != 0); \
kono
parents:
diff changeset
189 (COUNT) = __a; \
kono
parents:
diff changeset
190 } while (0)
kono
parents:
diff changeset
191 #endif /* __alpha_cix__ */
kono
parents:
diff changeset
192 #endif /* __alpha */
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 #if defined (__arc__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
195 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
196 __asm__ ("add.f %1, %4, %5\n\tadc %0, %2, %3" \
kono
parents:
diff changeset
197 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
198 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
199 : "%r" ((USItype) (ah)), \
kono
parents:
diff changeset
200 "rICal" ((USItype) (bh)), \
kono
parents:
diff changeset
201 "%r" ((USItype) (al)), \
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
202 "rICal" ((USItype) (bl)) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
203 : "cc")
111
kono
parents:
diff changeset
204 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
205 __asm__ ("sub.f %1, %4, %5\n\tsbc %0, %2, %3" \
kono
parents:
diff changeset
206 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
207 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
208 : "r" ((USItype) (ah)), \
kono
parents:
diff changeset
209 "rICal" ((USItype) (bh)), \
kono
parents:
diff changeset
210 "r" ((USItype) (al)), \
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
211 "rICal" ((USItype) (bl)) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
212 : "cc")
111
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 #define __umulsidi3(u,v) ((UDItype)(USItype)u*(USItype)v)
kono
parents:
diff changeset
215 #ifdef __ARC_NORM__
kono
parents:
diff changeset
216 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
217 do \
kono
parents:
diff changeset
218 { \
kono
parents:
diff changeset
219 SItype c_; \
kono
parents:
diff changeset
220 \
kono
parents:
diff changeset
221 __asm__ ("norm.f\t%0,%1\n\tmov.mi\t%0,-1" : "=r" (c_) : "r" (x) : "cc");\
kono
parents:
diff changeset
222 (count) = c_ + 1; \
kono
parents:
diff changeset
223 } \
kono
parents:
diff changeset
224 while (0)
kono
parents:
diff changeset
225 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
226 #endif /* __ARC_NORM__ */
kono
parents:
diff changeset
227 #endif /* __arc__ */
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 #if defined (__arm__) && (defined (__thumb2__) || !defined (__thumb__)) \
kono
parents:
diff changeset
230 && W_TYPE_SIZE == 32
kono
parents:
diff changeset
231 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
232 __asm__ ("adds %1, %4, %5\n\tadc %0, %2, %3" \
kono
parents:
diff changeset
233 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
234 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
235 : "%r" ((USItype) (ah)), \
kono
parents:
diff changeset
236 "rI" ((USItype) (bh)), \
kono
parents:
diff changeset
237 "%r" ((USItype) (al)), \
kono
parents:
diff changeset
238 "rI" ((USItype) (bl)) __CLOBBER_CC)
kono
parents:
diff changeset
239 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
240 __asm__ ("subs %1, %4, %5\n\tsbc %0, %2, %3" \
kono
parents:
diff changeset
241 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
242 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
243 : "r" ((USItype) (ah)), \
kono
parents:
diff changeset
244 "rI" ((USItype) (bh)), \
kono
parents:
diff changeset
245 "r" ((USItype) (al)), \
kono
parents:
diff changeset
246 "rI" ((USItype) (bl)) __CLOBBER_CC)
kono
parents:
diff changeset
247 # if defined(__ARM_ARCH_2__) || defined(__ARM_ARCH_2A__) \
kono
parents:
diff changeset
248 || defined(__ARM_ARCH_3__)
kono
parents:
diff changeset
249 # define umul_ppmm(xh, xl, a, b) \
kono
parents:
diff changeset
250 do { \
kono
parents:
diff changeset
251 register USItype __t0, __t1, __t2; \
kono
parents:
diff changeset
252 __asm__ ("%@ Inlined umul_ppmm\n" \
kono
parents:
diff changeset
253 " mov %2, %5, lsr #16\n" \
kono
parents:
diff changeset
254 " mov %0, %6, lsr #16\n" \
kono
parents:
diff changeset
255 " bic %3, %5, %2, lsl #16\n" \
kono
parents:
diff changeset
256 " bic %4, %6, %0, lsl #16\n" \
kono
parents:
diff changeset
257 " mul %1, %3, %4\n" \
kono
parents:
diff changeset
258 " mul %4, %2, %4\n" \
kono
parents:
diff changeset
259 " mul %3, %0, %3\n" \
kono
parents:
diff changeset
260 " mul %0, %2, %0\n" \
kono
parents:
diff changeset
261 " adds %3, %4, %3\n" \
kono
parents:
diff changeset
262 " addcs %0, %0, #65536\n" \
kono
parents:
diff changeset
263 " adds %1, %1, %3, lsl #16\n" \
kono
parents:
diff changeset
264 " adc %0, %0, %3, lsr #16" \
kono
parents:
diff changeset
265 : "=&r" ((USItype) (xh)), \
kono
parents:
diff changeset
266 "=r" ((USItype) (xl)), \
kono
parents:
diff changeset
267 "=&r" (__t0), "=&r" (__t1), "=r" (__t2) \
kono
parents:
diff changeset
268 : "r" ((USItype) (a)), \
kono
parents:
diff changeset
269 "r" ((USItype) (b)) __CLOBBER_CC ); \
kono
parents:
diff changeset
270 } while (0)
kono
parents:
diff changeset
271 # define UMUL_TIME 20
kono
parents:
diff changeset
272 # else
kono
parents:
diff changeset
273 # define umul_ppmm(xh, xl, a, b) \
kono
parents:
diff changeset
274 do { \
kono
parents:
diff changeset
275 /* Generate umull, under compiler control. */ \
kono
parents:
diff changeset
276 register UDItype __t0 = (UDItype)(USItype)(a) * (USItype)(b); \
kono
parents:
diff changeset
277 (xl) = (USItype)__t0; \
kono
parents:
diff changeset
278 (xh) = (USItype)(__t0 >> 32); \
kono
parents:
diff changeset
279 } while (0)
kono
parents:
diff changeset
280 # define UMUL_TIME 3
kono
parents:
diff changeset
281 # endif
kono
parents:
diff changeset
282 # define UDIV_TIME 100
kono
parents:
diff changeset
283 #endif /* __arm__ */
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 #if defined(__arm__)
kono
parents:
diff changeset
286 /* Let gcc decide how best to implement count_leading_zeros. */
kono
parents:
diff changeset
287 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
kono
parents:
diff changeset
288 #define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctz (X))
kono
parents:
diff changeset
289 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
290 #endif
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 #if defined (__AVR__)
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 #if W_TYPE_SIZE == 16
kono
parents:
diff changeset
295 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
kono
parents:
diff changeset
296 #define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctz (X))
kono
parents:
diff changeset
297 #define COUNT_LEADING_ZEROS_0 16
kono
parents:
diff changeset
298 #endif /* W_TYPE_SIZE == 16 */
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 #if W_TYPE_SIZE == 32
kono
parents:
diff changeset
301 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clzl (X))
kono
parents:
diff changeset
302 #define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctzl (X))
kono
parents:
diff changeset
303 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
304 #endif /* W_TYPE_SIZE == 32 */
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 #if W_TYPE_SIZE == 64
kono
parents:
diff changeset
307 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clzll (X))
kono
parents:
diff changeset
308 #define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctzll (X))
kono
parents:
diff changeset
309 #define COUNT_LEADING_ZEROS_0 64
kono
parents:
diff changeset
310 #endif /* W_TYPE_SIZE == 64 */
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 #endif /* defined (__AVR__) */
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 #if defined (__CRIS__)
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 #if __CRIS_arch_version >= 3
kono
parents:
diff changeset
317 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
kono
parents:
diff changeset
318 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
319 #endif /* __CRIS_arch_version >= 3 */
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 #if __CRIS_arch_version >= 8
kono
parents:
diff changeset
322 #define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X))
kono
parents:
diff changeset
323 #endif /* __CRIS_arch_version >= 8 */
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 #if __CRIS_arch_version >= 10
kono
parents:
diff changeset
326 #define __umulsidi3(u,v) ((UDItype)(USItype) (u) * (UDItype)(USItype) (v))
kono
parents:
diff changeset
327 #else
kono
parents:
diff changeset
328 #define __umulsidi3 __umulsidi3
kono
parents:
diff changeset
329 extern UDItype __umulsidi3 (USItype, USItype);
kono
parents:
diff changeset
330 #endif /* __CRIS_arch_version >= 10 */
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
333 do { \
kono
parents:
diff changeset
334 UDItype __x = __umulsidi3 (u, v); \
kono
parents:
diff changeset
335 (w0) = (USItype) (__x); \
kono
parents:
diff changeset
336 (w1) = (USItype) (__x >> 32); \
kono
parents:
diff changeset
337 } while (0)
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 /* FIXME: defining add_ssaaaa and sub_ddmmss should be advantageous for
kono
parents:
diff changeset
340 DFmode ("double" intrinsics, avoiding two of the three insns handling
kono
parents:
diff changeset
341 carry), but defining them as open-code C composing and doing the
kono
parents:
diff changeset
342 operation in DImode (UDImode) shows that the DImode needs work:
kono
parents:
diff changeset
343 register pressure from requiring neighboring registers and the
kono
parents:
diff changeset
344 traffic to and from them come to dominate, in the 4.7 series. */
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 #endif /* defined (__CRIS__) */
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 #if defined (__hppa) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
349 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
350 __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0" \
kono
parents:
diff changeset
351 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
352 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
353 : "%rM" ((USItype) (ah)), \
kono
parents:
diff changeset
354 "rM" ((USItype) (bh)), \
kono
parents:
diff changeset
355 "%rM" ((USItype) (al)), \
kono
parents:
diff changeset
356 "rM" ((USItype) (bl)))
kono
parents:
diff changeset
357 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
358 __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0" \
kono
parents:
diff changeset
359 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
360 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
361 : "rM" ((USItype) (ah)), \
kono
parents:
diff changeset
362 "rM" ((USItype) (bh)), \
kono
parents:
diff changeset
363 "rM" ((USItype) (al)), \
kono
parents:
diff changeset
364 "rM" ((USItype) (bl)))
kono
parents:
diff changeset
365 #if defined (_PA_RISC1_1)
kono
parents:
diff changeset
366 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
367 do { \
kono
parents:
diff changeset
368 union \
kono
parents:
diff changeset
369 { \
kono
parents:
diff changeset
370 UDItype __f; \
kono
parents:
diff changeset
371 struct {USItype __w1, __w0;} __w1w0; \
kono
parents:
diff changeset
372 } __t; \
kono
parents:
diff changeset
373 __asm__ ("xmpyu %1,%2,%0" \
kono
parents:
diff changeset
374 : "=x" (__t.__f) \
kono
parents:
diff changeset
375 : "x" ((USItype) (u)), \
kono
parents:
diff changeset
376 "x" ((USItype) (v))); \
kono
parents:
diff changeset
377 (w1) = __t.__w1w0.__w1; \
kono
parents:
diff changeset
378 (w0) = __t.__w1w0.__w0; \
kono
parents:
diff changeset
379 } while (0)
kono
parents:
diff changeset
380 #define UMUL_TIME 8
kono
parents:
diff changeset
381 #else
kono
parents:
diff changeset
382 #define UMUL_TIME 30
kono
parents:
diff changeset
383 #endif
kono
parents:
diff changeset
384 #define UDIV_TIME 40
kono
parents:
diff changeset
385 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
386 do { \
kono
parents:
diff changeset
387 USItype __tmp; \
kono
parents:
diff changeset
388 __asm__ ( \
kono
parents:
diff changeset
389 "ldi 1,%0\n" \
kono
parents:
diff changeset
390 " extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
kono
parents:
diff changeset
391 " extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n"\
kono
parents:
diff changeset
392 " ldo 16(%0),%0 ; Yes. Perform add.\n" \
kono
parents:
diff changeset
393 " extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
kono
parents:
diff changeset
394 " extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n"\
kono
parents:
diff changeset
395 " ldo 8(%0),%0 ; Yes. Perform add.\n" \
kono
parents:
diff changeset
396 " extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
kono
parents:
diff changeset
397 " extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n"\
kono
parents:
diff changeset
398 " ldo 4(%0),%0 ; Yes. Perform add.\n" \
kono
parents:
diff changeset
399 " extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
kono
parents:
diff changeset
400 " extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n"\
kono
parents:
diff changeset
401 " ldo 2(%0),%0 ; Yes. Perform add.\n" \
kono
parents:
diff changeset
402 " extru %1,30,1,%1 ; Extract bit 1.\n" \
kono
parents:
diff changeset
403 " sub %0,%1,%0 ; Subtract it.\n" \
kono
parents:
diff changeset
404 : "=r" (count), "=r" (__tmp) : "1" (x)); \
kono
parents:
diff changeset
405 } while (0)
kono
parents:
diff changeset
406 #endif
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 #if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
409 #if !defined (__zarch__)
kono
parents:
diff changeset
410 #define smul_ppmm(xh, xl, m0, m1) \
kono
parents:
diff changeset
411 do { \
kono
parents:
diff changeset
412 union {DItype __ll; \
kono
parents:
diff changeset
413 struct {USItype __h, __l;} __i; \
kono
parents:
diff changeset
414 } __x; \
kono
parents:
diff changeset
415 __asm__ ("lr %N0,%1\n\tmr %0,%2" \
kono
parents:
diff changeset
416 : "=&r" (__x.__ll) \
kono
parents:
diff changeset
417 : "r" (m0), "r" (m1)); \
kono
parents:
diff changeset
418 (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
kono
parents:
diff changeset
419 } while (0)
kono
parents:
diff changeset
420 #define sdiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
421 do { \
kono
parents:
diff changeset
422 union {DItype __ll; \
kono
parents:
diff changeset
423 struct {USItype __h, __l;} __i; \
kono
parents:
diff changeset
424 } __x; \
kono
parents:
diff changeset
425 __x.__i.__h = n1; __x.__i.__l = n0; \
kono
parents:
diff changeset
426 __asm__ ("dr %0,%2" \
kono
parents:
diff changeset
427 : "=r" (__x.__ll) \
kono
parents:
diff changeset
428 : "0" (__x.__ll), "r" (d)); \
kono
parents:
diff changeset
429 (q) = __x.__i.__l; (r) = __x.__i.__h; \
kono
parents:
diff changeset
430 } while (0)
kono
parents:
diff changeset
431 #else
kono
parents:
diff changeset
432 #define smul_ppmm(xh, xl, m0, m1) \
kono
parents:
diff changeset
433 do { \
kono
parents:
diff changeset
434 register SItype __r0 __asm__ ("0"); \
kono
parents:
diff changeset
435 register SItype __r1 __asm__ ("1") = (m0); \
kono
parents:
diff changeset
436 \
kono
parents:
diff changeset
437 __asm__ ("mr\t%%r0,%3" \
kono
parents:
diff changeset
438 : "=r" (__r0), "=r" (__r1) \
kono
parents:
diff changeset
439 : "r" (__r1), "r" (m1)); \
kono
parents:
diff changeset
440 (xh) = __r0; (xl) = __r1; \
kono
parents:
diff changeset
441 } while (0)
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 #define sdiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
444 do { \
kono
parents:
diff changeset
445 register SItype __r0 __asm__ ("0") = (n1); \
kono
parents:
diff changeset
446 register SItype __r1 __asm__ ("1") = (n0); \
kono
parents:
diff changeset
447 \
kono
parents:
diff changeset
448 __asm__ ("dr\t%%r0,%4" \
kono
parents:
diff changeset
449 : "=r" (__r0), "=r" (__r1) \
kono
parents:
diff changeset
450 : "r" (__r0), "r" (__r1), "r" (d)); \
kono
parents:
diff changeset
451 (q) = __r1; (r) = __r0; \
kono
parents:
diff changeset
452 } while (0)
kono
parents:
diff changeset
453 #endif /* __zarch__ */
kono
parents:
diff changeset
454 #endif
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
457 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
458 __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}" \
kono
parents:
diff changeset
459 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
460 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
461 : "%0" ((USItype) (ah)), \
kono
parents:
diff changeset
462 "g" ((USItype) (bh)), \
kono
parents:
diff changeset
463 "%1" ((USItype) (al)), \
kono
parents:
diff changeset
464 "g" ((USItype) (bl)))
kono
parents:
diff changeset
465 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
466 __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}" \
kono
parents:
diff changeset
467 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
468 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
469 : "0" ((USItype) (ah)), \
kono
parents:
diff changeset
470 "g" ((USItype) (bh)), \
kono
parents:
diff changeset
471 "1" ((USItype) (al)), \
kono
parents:
diff changeset
472 "g" ((USItype) (bl)))
kono
parents:
diff changeset
473 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
474 __asm__ ("mul{l} %3" \
kono
parents:
diff changeset
475 : "=a" ((USItype) (w0)), \
kono
parents:
diff changeset
476 "=d" ((USItype) (w1)) \
kono
parents:
diff changeset
477 : "%0" ((USItype) (u)), \
kono
parents:
diff changeset
478 "rm" ((USItype) (v)))
kono
parents:
diff changeset
479 #define udiv_qrnnd(q, r, n1, n0, dv) \
kono
parents:
diff changeset
480 __asm__ ("div{l} %4" \
kono
parents:
diff changeset
481 : "=a" ((USItype) (q)), \
kono
parents:
diff changeset
482 "=d" ((USItype) (r)) \
kono
parents:
diff changeset
483 : "0" ((USItype) (n0)), \
kono
parents:
diff changeset
484 "1" ((USItype) (n1)), \
kono
parents:
diff changeset
485 "rm" ((USItype) (dv)))
kono
parents:
diff changeset
486 #define count_leading_zeros(count, x) ((count) = __builtin_clz (x))
kono
parents:
diff changeset
487 #define count_trailing_zeros(count, x) ((count) = __builtin_ctz (x))
kono
parents:
diff changeset
488 #define UMUL_TIME 40
kono
parents:
diff changeset
489 #define UDIV_TIME 40
kono
parents:
diff changeset
490 #endif /* 80x86 */
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 #if defined (__x86_64__) && W_TYPE_SIZE == 64
kono
parents:
diff changeset
493 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
494 __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}" \
kono
parents:
diff changeset
495 : "=r" ((UDItype) (sh)), \
kono
parents:
diff changeset
496 "=&r" ((UDItype) (sl)) \
kono
parents:
diff changeset
497 : "%0" ((UDItype) (ah)), \
kono
parents:
diff changeset
498 "rme" ((UDItype) (bh)), \
kono
parents:
diff changeset
499 "%1" ((UDItype) (al)), \
kono
parents:
diff changeset
500 "rme" ((UDItype) (bl)))
kono
parents:
diff changeset
501 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
502 __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}" \
kono
parents:
diff changeset
503 : "=r" ((UDItype) (sh)), \
kono
parents:
diff changeset
504 "=&r" ((UDItype) (sl)) \
kono
parents:
diff changeset
505 : "0" ((UDItype) (ah)), \
kono
parents:
diff changeset
506 "rme" ((UDItype) (bh)), \
kono
parents:
diff changeset
507 "1" ((UDItype) (al)), \
kono
parents:
diff changeset
508 "rme" ((UDItype) (bl)))
kono
parents:
diff changeset
509 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
510 __asm__ ("mul{q} %3" \
kono
parents:
diff changeset
511 : "=a" ((UDItype) (w0)), \
kono
parents:
diff changeset
512 "=d" ((UDItype) (w1)) \
kono
parents:
diff changeset
513 : "%0" ((UDItype) (u)), \
kono
parents:
diff changeset
514 "rm" ((UDItype) (v)))
kono
parents:
diff changeset
515 #define udiv_qrnnd(q, r, n1, n0, dv) \
kono
parents:
diff changeset
516 __asm__ ("div{q} %4" \
kono
parents:
diff changeset
517 : "=a" ((UDItype) (q)), \
kono
parents:
diff changeset
518 "=d" ((UDItype) (r)) \
kono
parents:
diff changeset
519 : "0" ((UDItype) (n0)), \
kono
parents:
diff changeset
520 "1" ((UDItype) (n1)), \
kono
parents:
diff changeset
521 "rm" ((UDItype) (dv)))
kono
parents:
diff changeset
522 #define count_leading_zeros(count, x) ((count) = __builtin_clzll (x))
kono
parents:
diff changeset
523 #define count_trailing_zeros(count, x) ((count) = __builtin_ctzll (x))
kono
parents:
diff changeset
524 #define UMUL_TIME 40
kono
parents:
diff changeset
525 #define UDIV_TIME 40
kono
parents:
diff changeset
526 #endif /* x86_64 */
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 #if defined (__i960__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
529 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
530 ({union {UDItype __ll; \
kono
parents:
diff changeset
531 struct {USItype __l, __h;} __i; \
kono
parents:
diff changeset
532 } __xx; \
kono
parents:
diff changeset
533 __asm__ ("emul %2,%1,%0" \
kono
parents:
diff changeset
534 : "=d" (__xx.__ll) \
kono
parents:
diff changeset
535 : "%dI" ((USItype) (u)), \
kono
parents:
diff changeset
536 "dI" ((USItype) (v))); \
kono
parents:
diff changeset
537 (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
kono
parents:
diff changeset
538 #define __umulsidi3(u, v) \
kono
parents:
diff changeset
539 ({UDItype __w; \
kono
parents:
diff changeset
540 __asm__ ("emul %2,%1,%0" \
kono
parents:
diff changeset
541 : "=d" (__w) \
kono
parents:
diff changeset
542 : "%dI" ((USItype) (u)), \
kono
parents:
diff changeset
543 "dI" ((USItype) (v))); \
kono
parents:
diff changeset
544 __w; })
kono
parents:
diff changeset
545 #endif /* __i960__ */
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 #if defined (__ia64) && W_TYPE_SIZE == 64
kono
parents:
diff changeset
548 /* This form encourages gcc (pre-release 3.4 at least) to emit predicated
kono
parents:
diff changeset
549 "sub r=r,r" and "sub r=r,r,1", giving a 2 cycle latency. The generic
kono
parents:
diff changeset
550 code using "al<bl" arithmetically comes out making an actual 0 or 1 in a
kono
parents:
diff changeset
551 register, which takes an extra cycle. */
kono
parents:
diff changeset
552 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
553 do { \
kono
parents:
diff changeset
554 UWtype __x; \
kono
parents:
diff changeset
555 __x = (al) - (bl); \
kono
parents:
diff changeset
556 if ((al) < (bl)) \
kono
parents:
diff changeset
557 (sh) = (ah) - (bh) - 1; \
kono
parents:
diff changeset
558 else \
kono
parents:
diff changeset
559 (sh) = (ah) - (bh); \
kono
parents:
diff changeset
560 (sl) = __x; \
kono
parents:
diff changeset
561 } while (0)
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 /* Do both product parts in assembly, since that gives better code with
kono
parents:
diff changeset
564 all gcc versions. Some callers will just use the upper part, and in
kono
parents:
diff changeset
565 that situation we waste an instruction, but not any cycles. */
kono
parents:
diff changeset
566 #define umul_ppmm(ph, pl, m0, m1) \
kono
parents:
diff changeset
567 __asm__ ("xma.hu %0 = %2, %3, f0\n\txma.l %1 = %2, %3, f0" \
kono
parents:
diff changeset
568 : "=&f" (ph), "=f" (pl) \
kono
parents:
diff changeset
569 : "f" (m0), "f" (m1))
kono
parents:
diff changeset
570 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
571 do { \
kono
parents:
diff changeset
572 UWtype _x = (x), _y, _a, _c; \
kono
parents:
diff changeset
573 __asm__ ("mux1 %0 = %1, @rev" : "=r" (_y) : "r" (_x)); \
kono
parents:
diff changeset
574 __asm__ ("czx1.l %0 = %1" : "=r" (_a) : "r" (-_y | _y)); \
kono
parents:
diff changeset
575 _c = (_a - 1) << 3; \
kono
parents:
diff changeset
576 _x >>= _c; \
kono
parents:
diff changeset
577 if (_x >= 1 << 4) \
kono
parents:
diff changeset
578 _x >>= 4, _c += 4; \
kono
parents:
diff changeset
579 if (_x >= 1 << 2) \
kono
parents:
diff changeset
580 _x >>= 2, _c += 2; \
kono
parents:
diff changeset
581 _c += _x >> 1; \
kono
parents:
diff changeset
582 (count) = W_TYPE_SIZE - 1 - _c; \
kono
parents:
diff changeset
583 } while (0)
kono
parents:
diff changeset
584 /* similar to what gcc does for __builtin_ffs, but 0 based rather than 1
kono
parents:
diff changeset
585 based, and we don't need a special case for x==0 here */
kono
parents:
diff changeset
586 #define count_trailing_zeros(count, x) \
kono
parents:
diff changeset
587 do { \
kono
parents:
diff changeset
588 UWtype __ctz_x = (x); \
kono
parents:
diff changeset
589 __asm__ ("popcnt %0 = %1" \
kono
parents:
diff changeset
590 : "=r" (count) \
kono
parents:
diff changeset
591 : "r" ((__ctz_x-1) & ~__ctz_x)); \
kono
parents:
diff changeset
592 } while (0)
kono
parents:
diff changeset
593 #define UMUL_TIME 14
kono
parents:
diff changeset
594 #endif
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 #if defined (__M32R__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
597 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
598 /* The cmp clears the condition bit. */ \
kono
parents:
diff changeset
599 __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3" \
kono
parents:
diff changeset
600 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
601 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
602 : "0" ((USItype) (ah)), \
kono
parents:
diff changeset
603 "r" ((USItype) (bh)), \
kono
parents:
diff changeset
604 "1" ((USItype) (al)), \
kono
parents:
diff changeset
605 "r" ((USItype) (bl)) \
kono
parents:
diff changeset
606 : "cbit")
kono
parents:
diff changeset
607 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
608 /* The cmp clears the condition bit. */ \
kono
parents:
diff changeset
609 __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3" \
kono
parents:
diff changeset
610 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
611 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
612 : "0" ((USItype) (ah)), \
kono
parents:
diff changeset
613 "r" ((USItype) (bh)), \
kono
parents:
diff changeset
614 "1" ((USItype) (al)), \
kono
parents:
diff changeset
615 "r" ((USItype) (bl)) \
kono
parents:
diff changeset
616 : "cbit")
kono
parents:
diff changeset
617 #endif /* __M32R__ */
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 #if defined (__mc68000__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
620 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
621 __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0" \
kono
parents:
diff changeset
622 : "=d" ((USItype) (sh)), \
kono
parents:
diff changeset
623 "=&d" ((USItype) (sl)) \
kono
parents:
diff changeset
624 : "%0" ((USItype) (ah)), \
kono
parents:
diff changeset
625 "d" ((USItype) (bh)), \
kono
parents:
diff changeset
626 "%1" ((USItype) (al)), \
kono
parents:
diff changeset
627 "g" ((USItype) (bl)))
kono
parents:
diff changeset
628 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
629 __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0" \
kono
parents:
diff changeset
630 : "=d" ((USItype) (sh)), \
kono
parents:
diff changeset
631 "=&d" ((USItype) (sl)) \
kono
parents:
diff changeset
632 : "0" ((USItype) (ah)), \
kono
parents:
diff changeset
633 "d" ((USItype) (bh)), \
kono
parents:
diff changeset
634 "1" ((USItype) (al)), \
kono
parents:
diff changeset
635 "g" ((USItype) (bl)))
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 /* The '020, '030, '040, '060 and CPU32 have 32x32->64 and 64/32->32q-32r. */
kono
parents:
diff changeset
638 #if (defined (__mc68020__) && !defined (__mc68060__))
kono
parents:
diff changeset
639 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
640 __asm__ ("mulu%.l %3,%1:%0" \
kono
parents:
diff changeset
641 : "=d" ((USItype) (w0)), \
kono
parents:
diff changeset
642 "=d" ((USItype) (w1)) \
kono
parents:
diff changeset
643 : "%0" ((USItype) (u)), \
kono
parents:
diff changeset
644 "dmi" ((USItype) (v)))
kono
parents:
diff changeset
645 #define UMUL_TIME 45
kono
parents:
diff changeset
646 #define udiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
647 __asm__ ("divu%.l %4,%1:%0" \
kono
parents:
diff changeset
648 : "=d" ((USItype) (q)), \
kono
parents:
diff changeset
649 "=d" ((USItype) (r)) \
kono
parents:
diff changeset
650 : "0" ((USItype) (n0)), \
kono
parents:
diff changeset
651 "1" ((USItype) (n1)), \
kono
parents:
diff changeset
652 "dmi" ((USItype) (d)))
kono
parents:
diff changeset
653 #define UDIV_TIME 90
kono
parents:
diff changeset
654 #define sdiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
655 __asm__ ("divs%.l %4,%1:%0" \
kono
parents:
diff changeset
656 : "=d" ((USItype) (q)), \
kono
parents:
diff changeset
657 "=d" ((USItype) (r)) \
kono
parents:
diff changeset
658 : "0" ((USItype) (n0)), \
kono
parents:
diff changeset
659 "1" ((USItype) (n1)), \
kono
parents:
diff changeset
660 "dmi" ((USItype) (d)))
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 #elif defined (__mcoldfire__) /* not mc68020 */
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 #define umul_ppmm(xh, xl, a, b) \
kono
parents:
diff changeset
665 __asm__ ("| Inlined umul_ppmm\n" \
kono
parents:
diff changeset
666 " move%.l %2,%/d0\n" \
kono
parents:
diff changeset
667 " move%.l %3,%/d1\n" \
kono
parents:
diff changeset
668 " move%.l %/d0,%/d2\n" \
kono
parents:
diff changeset
669 " swap %/d0\n" \
kono
parents:
diff changeset
670 " move%.l %/d1,%/d3\n" \
kono
parents:
diff changeset
671 " swap %/d1\n" \
kono
parents:
diff changeset
672 " move%.w %/d2,%/d4\n" \
kono
parents:
diff changeset
673 " mulu %/d3,%/d4\n" \
kono
parents:
diff changeset
674 " mulu %/d1,%/d2\n" \
kono
parents:
diff changeset
675 " mulu %/d0,%/d3\n" \
kono
parents:
diff changeset
676 " mulu %/d0,%/d1\n" \
kono
parents:
diff changeset
677 " move%.l %/d4,%/d0\n" \
kono
parents:
diff changeset
678 " clr%.w %/d0\n" \
kono
parents:
diff changeset
679 " swap %/d0\n" \
kono
parents:
diff changeset
680 " add%.l %/d0,%/d2\n" \
kono
parents:
diff changeset
681 " add%.l %/d3,%/d2\n" \
kono
parents:
diff changeset
682 " jcc 1f\n" \
kono
parents:
diff changeset
683 " add%.l %#65536,%/d1\n" \
kono
parents:
diff changeset
684 "1: swap %/d2\n" \
kono
parents:
diff changeset
685 " moveq %#0,%/d0\n" \
kono
parents:
diff changeset
686 " move%.w %/d2,%/d0\n" \
kono
parents:
diff changeset
687 " move%.w %/d4,%/d2\n" \
kono
parents:
diff changeset
688 " move%.l %/d2,%1\n" \
kono
parents:
diff changeset
689 " add%.l %/d1,%/d0\n" \
kono
parents:
diff changeset
690 " move%.l %/d0,%0" \
kono
parents:
diff changeset
691 : "=g" ((USItype) (xh)), \
kono
parents:
diff changeset
692 "=g" ((USItype) (xl)) \
kono
parents:
diff changeset
693 : "g" ((USItype) (a)), \
kono
parents:
diff changeset
694 "g" ((USItype) (b)) \
kono
parents:
diff changeset
695 : "d0", "d1", "d2", "d3", "d4")
kono
parents:
diff changeset
696 #define UMUL_TIME 100
kono
parents:
diff changeset
697 #define UDIV_TIME 400
kono
parents:
diff changeset
698 #else /* not ColdFire */
kono
parents:
diff changeset
699 /* %/ inserts REGISTER_PREFIX, %# inserts IMMEDIATE_PREFIX. */
kono
parents:
diff changeset
700 #define umul_ppmm(xh, xl, a, b) \
kono
parents:
diff changeset
701 __asm__ ("| Inlined umul_ppmm\n" \
kono
parents:
diff changeset
702 " move%.l %2,%/d0\n" \
kono
parents:
diff changeset
703 " move%.l %3,%/d1\n" \
kono
parents:
diff changeset
704 " move%.l %/d0,%/d2\n" \
kono
parents:
diff changeset
705 " swap %/d0\n" \
kono
parents:
diff changeset
706 " move%.l %/d1,%/d3\n" \
kono
parents:
diff changeset
707 " swap %/d1\n" \
kono
parents:
diff changeset
708 " move%.w %/d2,%/d4\n" \
kono
parents:
diff changeset
709 " mulu %/d3,%/d4\n" \
kono
parents:
diff changeset
710 " mulu %/d1,%/d2\n" \
kono
parents:
diff changeset
711 " mulu %/d0,%/d3\n" \
kono
parents:
diff changeset
712 " mulu %/d0,%/d1\n" \
kono
parents:
diff changeset
713 " move%.l %/d4,%/d0\n" \
kono
parents:
diff changeset
714 " eor%.w %/d0,%/d0\n" \
kono
parents:
diff changeset
715 " swap %/d0\n" \
kono
parents:
diff changeset
716 " add%.l %/d0,%/d2\n" \
kono
parents:
diff changeset
717 " add%.l %/d3,%/d2\n" \
kono
parents:
diff changeset
718 " jcc 1f\n" \
kono
parents:
diff changeset
719 " add%.l %#65536,%/d1\n" \
kono
parents:
diff changeset
720 "1: swap %/d2\n" \
kono
parents:
diff changeset
721 " moveq %#0,%/d0\n" \
kono
parents:
diff changeset
722 " move%.w %/d2,%/d0\n" \
kono
parents:
diff changeset
723 " move%.w %/d4,%/d2\n" \
kono
parents:
diff changeset
724 " move%.l %/d2,%1\n" \
kono
parents:
diff changeset
725 " add%.l %/d1,%/d0\n" \
kono
parents:
diff changeset
726 " move%.l %/d0,%0" \
kono
parents:
diff changeset
727 : "=g" ((USItype) (xh)), \
kono
parents:
diff changeset
728 "=g" ((USItype) (xl)) \
kono
parents:
diff changeset
729 : "g" ((USItype) (a)), \
kono
parents:
diff changeset
730 "g" ((USItype) (b)) \
kono
parents:
diff changeset
731 : "d0", "d1", "d2", "d3", "d4")
kono
parents:
diff changeset
732 #define UMUL_TIME 100
kono
parents:
diff changeset
733 #define UDIV_TIME 400
kono
parents:
diff changeset
734
kono
parents:
diff changeset
735 #endif /* not mc68020 */
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 /* The '020, '030, '040 and '060 have bitfield insns.
kono
parents:
diff changeset
738 cpu32 disguises as a 68020, but lacks them. */
kono
parents:
diff changeset
739 #if defined (__mc68020__) && !defined (__mcpu32__)
kono
parents:
diff changeset
740 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
741 __asm__ ("bfffo %1{%b2:%b2},%0" \
kono
parents:
diff changeset
742 : "=d" ((USItype) (count)) \
kono
parents:
diff changeset
743 : "od" ((USItype) (x)), "n" (0))
kono
parents:
diff changeset
744 /* Some ColdFire architectures have a ff1 instruction supported via
kono
parents:
diff changeset
745 __builtin_clz. */
kono
parents:
diff changeset
746 #elif defined (__mcfisaaplus__) || defined (__mcfisac__)
kono
parents:
diff changeset
747 #define count_leading_zeros(count,x) ((count) = __builtin_clz (x))
kono
parents:
diff changeset
748 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
749 #endif
kono
parents:
diff changeset
750 #endif /* mc68000 */
kono
parents:
diff changeset
751
kono
parents:
diff changeset
752 #if defined (__m88000__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
753 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
754 __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3" \
kono
parents:
diff changeset
755 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
756 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
757 : "%rJ" ((USItype) (ah)), \
kono
parents:
diff changeset
758 "rJ" ((USItype) (bh)), \
kono
parents:
diff changeset
759 "%rJ" ((USItype) (al)), \
kono
parents:
diff changeset
760 "rJ" ((USItype) (bl)))
kono
parents:
diff changeset
761 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
762 __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3" \
kono
parents:
diff changeset
763 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
764 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
765 : "rJ" ((USItype) (ah)), \
kono
parents:
diff changeset
766 "rJ" ((USItype) (bh)), \
kono
parents:
diff changeset
767 "rJ" ((USItype) (al)), \
kono
parents:
diff changeset
768 "rJ" ((USItype) (bl)))
kono
parents:
diff changeset
769 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
770 do { \
kono
parents:
diff changeset
771 USItype __cbtmp; \
kono
parents:
diff changeset
772 __asm__ ("ff1 %0,%1" \
kono
parents:
diff changeset
773 : "=r" (__cbtmp) \
kono
parents:
diff changeset
774 : "r" ((USItype) (x))); \
kono
parents:
diff changeset
775 (count) = __cbtmp ^ 31; \
kono
parents:
diff changeset
776 } while (0)
kono
parents:
diff changeset
777 #define COUNT_LEADING_ZEROS_0 63 /* sic */
kono
parents:
diff changeset
778 #if defined (__mc88110__)
kono
parents:
diff changeset
779 #define umul_ppmm(wh, wl, u, v) \
kono
parents:
diff changeset
780 do { \
kono
parents:
diff changeset
781 union {UDItype __ll; \
kono
parents:
diff changeset
782 struct {USItype __h, __l;} __i; \
kono
parents:
diff changeset
783 } __xx; \
kono
parents:
diff changeset
784 __asm__ ("mulu.d %0,%1,%2" \
kono
parents:
diff changeset
785 : "=r" (__xx.__ll) \
kono
parents:
diff changeset
786 : "r" ((USItype) (u)), \
kono
parents:
diff changeset
787 "r" ((USItype) (v))); \
kono
parents:
diff changeset
788 (wh) = __xx.__i.__h; \
kono
parents:
diff changeset
789 (wl) = __xx.__i.__l; \
kono
parents:
diff changeset
790 } while (0)
kono
parents:
diff changeset
791 #define udiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
792 ({union {UDItype __ll; \
kono
parents:
diff changeset
793 struct {USItype __h, __l;} __i; \
kono
parents:
diff changeset
794 } __xx; \
kono
parents:
diff changeset
795 USItype __q; \
kono
parents:
diff changeset
796 __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
kono
parents:
diff changeset
797 __asm__ ("divu.d %0,%1,%2" \
kono
parents:
diff changeset
798 : "=r" (__q) \
kono
parents:
diff changeset
799 : "r" (__xx.__ll), \
kono
parents:
diff changeset
800 "r" ((USItype) (d))); \
kono
parents:
diff changeset
801 (r) = (n0) - __q * (d); (q) = __q; })
kono
parents:
diff changeset
802 #define UMUL_TIME 5
kono
parents:
diff changeset
803 #define UDIV_TIME 25
kono
parents:
diff changeset
804 #else
kono
parents:
diff changeset
805 #define UMUL_TIME 17
kono
parents:
diff changeset
806 #define UDIV_TIME 150
kono
parents:
diff changeset
807 #endif /* __mc88110__ */
kono
parents:
diff changeset
808 #endif /* __m88000__ */
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 #if defined (__mn10300__)
kono
parents:
diff changeset
811 # if defined (__AM33__)
kono
parents:
diff changeset
812 # define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
kono
parents:
diff changeset
813 # define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
814 asm("mulu %3,%2,%1,%0" : "=r"(w0), "=r"(w1) : "r"(u), "r"(v))
kono
parents:
diff changeset
815 # define smul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
816 asm("mul %3,%2,%1,%0" : "=r"(w0), "=r"(w1) : "r"(u), "r"(v))
kono
parents:
diff changeset
817 # else
kono
parents:
diff changeset
818 # define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
819 asm("nop; nop; mulu %3,%0" : "=d"(w0), "=z"(w1) : "%0"(u), "d"(v))
kono
parents:
diff changeset
820 # define smul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
821 asm("nop; nop; mul %3,%0" : "=d"(w0), "=z"(w1) : "%0"(u), "d"(v))
kono
parents:
diff changeset
822 # endif
kono
parents:
diff changeset
823 # define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
824 do { \
kono
parents:
diff changeset
825 DWunion __s, __a, __b; \
kono
parents:
diff changeset
826 __a.s.low = (al); __a.s.high = (ah); \
kono
parents:
diff changeset
827 __b.s.low = (bl); __b.s.high = (bh); \
kono
parents:
diff changeset
828 __s.ll = __a.ll + __b.ll; \
kono
parents:
diff changeset
829 (sl) = __s.s.low; (sh) = __s.s.high; \
kono
parents:
diff changeset
830 } while (0)
kono
parents:
diff changeset
831 # define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
832 do { \
kono
parents:
diff changeset
833 DWunion __s, __a, __b; \
kono
parents:
diff changeset
834 __a.s.low = (al); __a.s.high = (ah); \
kono
parents:
diff changeset
835 __b.s.low = (bl); __b.s.high = (bh); \
kono
parents:
diff changeset
836 __s.ll = __a.ll - __b.ll; \
kono
parents:
diff changeset
837 (sl) = __s.s.low; (sh) = __s.s.high; \
kono
parents:
diff changeset
838 } while (0)
kono
parents:
diff changeset
839 # define udiv_qrnnd(q, r, nh, nl, d) \
kono
parents:
diff changeset
840 asm("divu %2,%0" : "=D"(q), "=z"(r) : "D"(d), "0"(nl), "1"(nh))
kono
parents:
diff changeset
841 # define sdiv_qrnnd(q, r, nh, nl, d) \
kono
parents:
diff changeset
842 asm("div %2,%0" : "=D"(q), "=z"(r) : "D"(d), "0"(nl), "1"(nh))
kono
parents:
diff changeset
843 # define UMUL_TIME 3
kono
parents:
diff changeset
844 # define UDIV_TIME 38
kono
parents:
diff changeset
845 #endif
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 #if defined (__mips__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
848 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
849 do { \
kono
parents:
diff changeset
850 UDItype __x = (UDItype) (USItype) (u) * (USItype) (v); \
kono
parents:
diff changeset
851 (w1) = (USItype) (__x >> 32); \
kono
parents:
diff changeset
852 (w0) = (USItype) (__x); \
kono
parents:
diff changeset
853 } while (0)
kono
parents:
diff changeset
854 #define UMUL_TIME 10
kono
parents:
diff changeset
855 #define UDIV_TIME 100
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 #if (__mips == 32 || __mips == 64) && ! defined (__mips16)
kono
parents:
diff changeset
858 #define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
kono
parents:
diff changeset
859 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
860 #endif
kono
parents:
diff changeset
861 #endif /* __mips__ */
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 /* FIXME: We should test _IBMR2 here when we add assembly support for the
kono
parents:
diff changeset
864 system vendor compilers.
kono
parents:
diff changeset
865 FIXME: What's needed for gcc PowerPC VxWorks? __vxworks__ is not good
kono
parents:
diff changeset
866 enough, since that hits ARM and m68k too. */
kono
parents:
diff changeset
867 #if (defined (_ARCH_PPC) /* AIX */ \
kono
parents:
diff changeset
868 || defined (__powerpc__) /* gcc */ \
kono
parents:
diff changeset
869 || defined (__POWERPC__) /* BEOS */ \
kono
parents:
diff changeset
870 || defined (__ppc__) /* Darwin */ \
kono
parents:
diff changeset
871 || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */ \
kono
parents:
diff changeset
872 || (defined (PPC) && defined (CPU_FAMILY) /* VxWorks */ \
kono
parents:
diff changeset
873 && CPU_FAMILY == PPC) \
kono
parents:
diff changeset
874 ) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
875 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
876 do { \
kono
parents:
diff changeset
877 if (__builtin_constant_p (bh) && (bh) == 0) \
kono
parents:
diff changeset
878 __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2" \
kono
parents:
diff changeset
879 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
kono
parents:
diff changeset
880 else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
kono
parents:
diff changeset
881 __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2" \
kono
parents:
diff changeset
882 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
kono
parents:
diff changeset
883 else \
kono
parents:
diff changeset
884 __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3" \
kono
parents:
diff changeset
885 : "=r" (sh), "=&r" (sl) \
kono
parents:
diff changeset
886 : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
kono
parents:
diff changeset
887 } while (0)
kono
parents:
diff changeset
888 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
889 do { \
kono
parents:
diff changeset
890 if (__builtin_constant_p (ah) && (ah) == 0) \
kono
parents:
diff changeset
891 __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2" \
kono
parents:
diff changeset
892 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
893 else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \
kono
parents:
diff changeset
894 __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2" \
kono
parents:
diff changeset
895 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
896 else if (__builtin_constant_p (bh) && (bh) == 0) \
kono
parents:
diff changeset
897 __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2" \
kono
parents:
diff changeset
898 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
899 else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
kono
parents:
diff changeset
900 __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2" \
kono
parents:
diff changeset
901 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
902 else \
kono
parents:
diff changeset
903 __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2" \
kono
parents:
diff changeset
904 : "=r" (sh), "=&r" (sl) \
kono
parents:
diff changeset
905 : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
kono
parents:
diff changeset
906 } while (0)
kono
parents:
diff changeset
907 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
908 __asm__ ("cntlzw %0,%1" : "=r" (count) : "r" (x))
kono
parents:
diff changeset
909 #define COUNT_LEADING_ZEROS_0 32
kono
parents:
diff changeset
910 #if defined (_ARCH_PPC) || defined (__powerpc__) || defined (__POWERPC__) \
kono
parents:
diff changeset
911 || defined (__ppc__) \
kono
parents:
diff changeset
912 || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */ \
kono
parents:
diff changeset
913 || (defined (PPC) && defined (CPU_FAMILY) /* VxWorks */ \
kono
parents:
diff changeset
914 && CPU_FAMILY == PPC)
kono
parents:
diff changeset
915 #define umul_ppmm(ph, pl, m0, m1) \
kono
parents:
diff changeset
916 do { \
kono
parents:
diff changeset
917 USItype __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
918 __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
kono
parents:
diff changeset
919 (pl) = __m0 * __m1; \
kono
parents:
diff changeset
920 } while (0)
kono
parents:
diff changeset
921 #define UMUL_TIME 15
kono
parents:
diff changeset
922 #define smul_ppmm(ph, pl, m0, m1) \
kono
parents:
diff changeset
923 do { \
kono
parents:
diff changeset
924 SItype __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
925 __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
kono
parents:
diff changeset
926 (pl) = __m0 * __m1; \
kono
parents:
diff changeset
927 } while (0)
kono
parents:
diff changeset
928 #define SMUL_TIME 14
kono
parents:
diff changeset
929 #define UDIV_TIME 120
kono
parents:
diff changeset
930 #endif
kono
parents:
diff changeset
931 #endif /* 32-bit POWER architecture variants. */
kono
parents:
diff changeset
932
kono
parents:
diff changeset
933 /* We should test _IBMR2 here when we add assembly support for the system
kono
parents:
diff changeset
934 vendor compilers. */
kono
parents:
diff changeset
935 #if (defined (_ARCH_PPC64) || defined (__powerpc64__)) && W_TYPE_SIZE == 64
kono
parents:
diff changeset
936 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
937 do { \
kono
parents:
diff changeset
938 if (__builtin_constant_p (bh) && (bh) == 0) \
kono
parents:
diff changeset
939 __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2" \
kono
parents:
diff changeset
940 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
kono
parents:
diff changeset
941 else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
kono
parents:
diff changeset
942 __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2" \
kono
parents:
diff changeset
943 : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
kono
parents:
diff changeset
944 else \
kono
parents:
diff changeset
945 __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3" \
kono
parents:
diff changeset
946 : "=r" (sh), "=&r" (sl) \
kono
parents:
diff changeset
947 : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
kono
parents:
diff changeset
948 } while (0)
kono
parents:
diff changeset
949 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
950 do { \
kono
parents:
diff changeset
951 if (__builtin_constant_p (ah) && (ah) == 0) \
kono
parents:
diff changeset
952 __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2" \
kono
parents:
diff changeset
953 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
954 else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \
kono
parents:
diff changeset
955 __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2" \
kono
parents:
diff changeset
956 : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
957 else if (__builtin_constant_p (bh) && (bh) == 0) \
kono
parents:
diff changeset
958 __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2" \
kono
parents:
diff changeset
959 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
960 else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
kono
parents:
diff changeset
961 __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2" \
kono
parents:
diff changeset
962 : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
kono
parents:
diff changeset
963 else \
kono
parents:
diff changeset
964 __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2" \
kono
parents:
diff changeset
965 : "=r" (sh), "=&r" (sl) \
kono
parents:
diff changeset
966 : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
kono
parents:
diff changeset
967 } while (0)
kono
parents:
diff changeset
968 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
969 __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
kono
parents:
diff changeset
970 #define COUNT_LEADING_ZEROS_0 64
kono
parents:
diff changeset
971 #define umul_ppmm(ph, pl, m0, m1) \
kono
parents:
diff changeset
972 do { \
kono
parents:
diff changeset
973 UDItype __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
974 __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
kono
parents:
diff changeset
975 (pl) = __m0 * __m1; \
kono
parents:
diff changeset
976 } while (0)
kono
parents:
diff changeset
977 #define UMUL_TIME 15
kono
parents:
diff changeset
978 #define smul_ppmm(ph, pl, m0, m1) \
kono
parents:
diff changeset
979 do { \
kono
parents:
diff changeset
980 DItype __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
981 __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
kono
parents:
diff changeset
982 (pl) = __m0 * __m1; \
kono
parents:
diff changeset
983 } while (0)
kono
parents:
diff changeset
984 #define SMUL_TIME 14 /* ??? */
kono
parents:
diff changeset
985 #define UDIV_TIME 120 /* ??? */
kono
parents:
diff changeset
986 #endif /* 64-bit PowerPC. */
kono
parents:
diff changeset
987
kono
parents:
diff changeset
988 #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
kono
parents:
diff changeset
989 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
990 __asm__ ("a %1,%5\n\tae %0,%3" \
kono
parents:
diff changeset
991 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
992 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
993 : "%0" ((USItype) (ah)), \
kono
parents:
diff changeset
994 "r" ((USItype) (bh)), \
kono
parents:
diff changeset
995 "%1" ((USItype) (al)), \
kono
parents:
diff changeset
996 "r" ((USItype) (bl)))
kono
parents:
diff changeset
997 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
998 __asm__ ("s %1,%5\n\tse %0,%3" \
kono
parents:
diff changeset
999 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
1000 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
1001 : "0" ((USItype) (ah)), \
kono
parents:
diff changeset
1002 "r" ((USItype) (bh)), \
kono
parents:
diff changeset
1003 "1" ((USItype) (al)), \
kono
parents:
diff changeset
1004 "r" ((USItype) (bl)))
kono
parents:
diff changeset
1005 #define umul_ppmm(ph, pl, m0, m1) \
kono
parents:
diff changeset
1006 do { \
kono
parents:
diff changeset
1007 USItype __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
1008 __asm__ ( \
kono
parents:
diff changeset
1009 "s r2,r2\n" \
kono
parents:
diff changeset
1010 " mts r10,%2\n" \
kono
parents:
diff changeset
1011 " m r2,%3\n" \
kono
parents:
diff changeset
1012 " m r2,%3\n" \
kono
parents:
diff changeset
1013 " m r2,%3\n" \
kono
parents:
diff changeset
1014 " m r2,%3\n" \
kono
parents:
diff changeset
1015 " m r2,%3\n" \
kono
parents:
diff changeset
1016 " m r2,%3\n" \
kono
parents:
diff changeset
1017 " m r2,%3\n" \
kono
parents:
diff changeset
1018 " m r2,%3\n" \
kono
parents:
diff changeset
1019 " m r2,%3\n" \
kono
parents:
diff changeset
1020 " m r2,%3\n" \
kono
parents:
diff changeset
1021 " m r2,%3\n" \
kono
parents:
diff changeset
1022 " m r2,%3\n" \
kono
parents:
diff changeset
1023 " m r2,%3\n" \
kono
parents:
diff changeset
1024 " m r2,%3\n" \
kono
parents:
diff changeset
1025 " m r2,%3\n" \
kono
parents:
diff changeset
1026 " m r2,%3\n" \
kono
parents:
diff changeset
1027 " cas %0,r2,r0\n" \
kono
parents:
diff changeset
1028 " mfs r10,%1" \
kono
parents:
diff changeset
1029 : "=r" ((USItype) (ph)), \
kono
parents:
diff changeset
1030 "=r" ((USItype) (pl)) \
kono
parents:
diff changeset
1031 : "%r" (__m0), \
kono
parents:
diff changeset
1032 "r" (__m1) \
kono
parents:
diff changeset
1033 : "r2"); \
kono
parents:
diff changeset
1034 (ph) += ((((SItype) __m0 >> 31) & __m1) \
kono
parents:
diff changeset
1035 + (((SItype) __m1 >> 31) & __m0)); \
kono
parents:
diff changeset
1036 } while (0)
kono
parents:
diff changeset
1037 #define UMUL_TIME 20
kono
parents:
diff changeset
1038 #define UDIV_TIME 200
kono
parents:
diff changeset
1039 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
1040 do { \
kono
parents:
diff changeset
1041 if ((x) >= 0x10000) \
kono
parents:
diff changeset
1042 __asm__ ("clz %0,%1" \
kono
parents:
diff changeset
1043 : "=r" ((USItype) (count)) \
kono
parents:
diff changeset
1044 : "r" ((USItype) (x) >> 16)); \
kono
parents:
diff changeset
1045 else \
kono
parents:
diff changeset
1046 { \
kono
parents:
diff changeset
1047 __asm__ ("clz %0,%1" \
kono
parents:
diff changeset
1048 : "=r" ((USItype) (count)) \
kono
parents:
diff changeset
1049 : "r" ((USItype) (x))); \
kono
parents:
diff changeset
1050 (count) += 16; \
kono
parents:
diff changeset
1051 } \
kono
parents:
diff changeset
1052 } while (0)
kono
parents:
diff changeset
1053 #endif
kono
parents:
diff changeset
1054
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1055 #if defined(__riscv)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1056 #ifdef __riscv_mul
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1057 #define __umulsidi3(u,v) ((UDWtype)(UWtype)(u) * (UWtype)(v))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1058 #define __muluw3(a, b) ((UWtype)(a) * (UWtype)(b))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1059 #else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1060 #if __riscv_xlen == 32
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1061 #define MULUW3 "call __mulsi3"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1062 #elif __riscv_xlen == 64
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1063 #define MULUW3 "call __muldi3"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1064 #else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1065 #error unsupport xlen
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1066 #endif /* __riscv_xlen */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1067 /* We rely on the fact that MULUW3 doesn't clobber the t-registers.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1068 It can get better register allocation result. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1069 #define __muluw3(a, b) \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1070 ({ \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1071 register UWtype __op0 asm ("a0") = a; \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1072 register UWtype __op1 asm ("a1") = b; \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1073 asm volatile (MULUW3 \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1074 : "+r" (__op0), "+r" (__op1) \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1075 : \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1076 : "ra", "a2", "a3"); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1077 __op0; \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1078 })
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1079 #endif /* __riscv_mul */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1080 #define umul_ppmm(w1, w0, u, v) \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1081 do { \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1082 UWtype __x0, __x1, __x2, __x3; \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1083 UHWtype __ul, __vl, __uh, __vh; \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1084 \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1085 __ul = __ll_lowpart (u); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1086 __uh = __ll_highpart (u); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1087 __vl = __ll_lowpart (v); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1088 __vh = __ll_highpart (v); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1089 \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1090 __x0 = __muluw3 (__ul, __vl); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1091 __x1 = __muluw3 (__ul, __vh); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1092 __x2 = __muluw3 (__uh, __vl); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1093 __x3 = __muluw3 (__uh, __vh); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1094 \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1095 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1096 __x1 += __x2; /* but this indeed can */ \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1097 if (__x1 < __x2) /* did we get it? */ \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1098 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1099 \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1100 (w1) = __x3 + __ll_highpart (__x1); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1101 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1102 } while (0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1103 #endif /* __riscv */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1104
111
kono
parents:
diff changeset
1105 #if defined(__sh__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
1106 #ifndef __sh1__
kono
parents:
diff changeset
1107 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1108 __asm__ ( \
kono
parents:
diff changeset
1109 "dmulu.l %2,%3\n\tsts%M1 macl,%1\n\tsts%M0 mach,%0" \
kono
parents:
diff changeset
1110 : "=r<" ((USItype)(w1)), \
kono
parents:
diff changeset
1111 "=r<" ((USItype)(w0)) \
kono
parents:
diff changeset
1112 : "r" ((USItype)(u)), \
kono
parents:
diff changeset
1113 "r" ((USItype)(v)) \
kono
parents:
diff changeset
1114 : "macl", "mach")
kono
parents:
diff changeset
1115 #define UMUL_TIME 5
kono
parents:
diff changeset
1116 #endif
kono
parents:
diff changeset
1117
kono
parents:
diff changeset
1118 /* This is the same algorithm as __udiv_qrnnd_c. */
kono
parents:
diff changeset
1119 #define UDIV_NEEDS_NORMALIZATION 1
kono
parents:
diff changeset
1120
kono
parents:
diff changeset
1121 #ifdef __FDPIC__
kono
parents:
diff changeset
1122 /* FDPIC needs a special version of the asm fragment to extract the
kono
parents:
diff changeset
1123 code address from the function descriptor. __udiv_qrnnd_16 is
kono
parents:
diff changeset
1124 assumed to be local and not to use the GOT, so loading r12 is
kono
parents:
diff changeset
1125 not needed. */
kono
parents:
diff changeset
1126 #define udiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
1127 do { \
kono
parents:
diff changeset
1128 extern UWtype __udiv_qrnnd_16 (UWtype, UWtype) \
kono
parents:
diff changeset
1129 __attribute__ ((visibility ("hidden"))); \
kono
parents:
diff changeset
1130 /* r0: rn r1: qn */ /* r0: n1 r4: n0 r5: d r6: d1 */ /* r2: __m */ \
kono
parents:
diff changeset
1131 __asm__ ( \
kono
parents:
diff changeset
1132 "mov%M4 %4,r5\n" \
kono
parents:
diff changeset
1133 " swap.w %3,r4\n" \
kono
parents:
diff changeset
1134 " swap.w r5,r6\n" \
kono
parents:
diff changeset
1135 " mov.l @%5,r2\n" \
kono
parents:
diff changeset
1136 " jsr @r2\n" \
kono
parents:
diff changeset
1137 " shll16 r6\n" \
kono
parents:
diff changeset
1138 " swap.w r4,r4\n" \
kono
parents:
diff changeset
1139 " mov.l @%5,r2\n" \
kono
parents:
diff changeset
1140 " jsr @r2\n" \
kono
parents:
diff changeset
1141 " swap.w r1,%0\n" \
kono
parents:
diff changeset
1142 " or r1,%0" \
kono
parents:
diff changeset
1143 : "=r" (q), "=&z" (r) \
kono
parents:
diff changeset
1144 : "1" (n1), "r" (n0), "rm" (d), "r" (&__udiv_qrnnd_16) \
kono
parents:
diff changeset
1145 : "r1", "r2", "r4", "r5", "r6", "pr", "t"); \
kono
parents:
diff changeset
1146 } while (0)
kono
parents:
diff changeset
1147 #else
kono
parents:
diff changeset
1148 #define udiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
1149 do { \
kono
parents:
diff changeset
1150 extern UWtype __udiv_qrnnd_16 (UWtype, UWtype) \
kono
parents:
diff changeset
1151 __attribute__ ((visibility ("hidden"))); \
kono
parents:
diff changeset
1152 /* r0: rn r1: qn */ /* r0: n1 r4: n0 r5: d r6: d1 */ /* r2: __m */ \
kono
parents:
diff changeset
1153 __asm__ ( \
kono
parents:
diff changeset
1154 "mov%M4 %4,r5\n" \
kono
parents:
diff changeset
1155 " swap.w %3,r4\n" \
kono
parents:
diff changeset
1156 " swap.w r5,r6\n" \
kono
parents:
diff changeset
1157 " jsr @%5\n" \
kono
parents:
diff changeset
1158 " shll16 r6\n" \
kono
parents:
diff changeset
1159 " swap.w r4,r4\n" \
kono
parents:
diff changeset
1160 " jsr @%5\n" \
kono
parents:
diff changeset
1161 " swap.w r1,%0\n" \
kono
parents:
diff changeset
1162 " or r1,%0" \
kono
parents:
diff changeset
1163 : "=r" (q), "=&z" (r) \
kono
parents:
diff changeset
1164 : "1" (n1), "r" (n0), "rm" (d), "r" (&__udiv_qrnnd_16) \
kono
parents:
diff changeset
1165 : "r1", "r2", "r4", "r5", "r6", "pr", "t"); \
kono
parents:
diff changeset
1166 } while (0)
kono
parents:
diff changeset
1167 #endif /* __FDPIC__ */
kono
parents:
diff changeset
1168
kono
parents:
diff changeset
1169 #define UDIV_TIME 80
kono
parents:
diff changeset
1170
kono
parents:
diff changeset
1171 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1172 __asm__ ("clrt;subc %5,%1; subc %4,%0" \
kono
parents:
diff changeset
1173 : "=r" (sh), "=r" (sl) \
kono
parents:
diff changeset
1174 : "0" (ah), "1" (al), "r" (bh), "r" (bl) : "t")
kono
parents:
diff changeset
1175
kono
parents:
diff changeset
1176 #endif /* __sh__ */
kono
parents:
diff changeset
1177
kono
parents:
diff changeset
1178 #if defined (__sparc__) && !defined (__arch64__) && !defined (__sparcv9) \
kono
parents:
diff changeset
1179 && W_TYPE_SIZE == 32
kono
parents:
diff changeset
1180 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1181 __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0" \
kono
parents:
diff changeset
1182 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
1183 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
1184 : "%rJ" ((USItype) (ah)), \
kono
parents:
diff changeset
1185 "rI" ((USItype) (bh)), \
kono
parents:
diff changeset
1186 "%rJ" ((USItype) (al)), \
kono
parents:
diff changeset
1187 "rI" ((USItype) (bl)) \
kono
parents:
diff changeset
1188 __CLOBBER_CC)
kono
parents:
diff changeset
1189 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1190 __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0" \
kono
parents:
diff changeset
1191 : "=r" ((USItype) (sh)), \
kono
parents:
diff changeset
1192 "=&r" ((USItype) (sl)) \
kono
parents:
diff changeset
1193 : "rJ" ((USItype) (ah)), \
kono
parents:
diff changeset
1194 "rI" ((USItype) (bh)), \
kono
parents:
diff changeset
1195 "rJ" ((USItype) (al)), \
kono
parents:
diff changeset
1196 "rI" ((USItype) (bl)) \
kono
parents:
diff changeset
1197 __CLOBBER_CC)
kono
parents:
diff changeset
1198 #if defined (__sparc_v9__)
kono
parents:
diff changeset
1199 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1200 do { \
kono
parents:
diff changeset
1201 register USItype __g1 asm ("g1"); \
kono
parents:
diff changeset
1202 __asm__ ("umul\t%2,%3,%1\n\t" \
kono
parents:
diff changeset
1203 "srlx\t%1, 32, %0" \
kono
parents:
diff changeset
1204 : "=r" ((USItype) (w1)), \
kono
parents:
diff changeset
1205 "=r" (__g1) \
kono
parents:
diff changeset
1206 : "r" ((USItype) (u)), \
kono
parents:
diff changeset
1207 "r" ((USItype) (v))); \
kono
parents:
diff changeset
1208 (w0) = __g1; \
kono
parents:
diff changeset
1209 } while (0)
kono
parents:
diff changeset
1210 #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
kono
parents:
diff changeset
1211 __asm__ ("mov\t%2,%%y\n\t" \
kono
parents:
diff changeset
1212 "udiv\t%3,%4,%0\n\t" \
kono
parents:
diff changeset
1213 "umul\t%0,%4,%1\n\t" \
kono
parents:
diff changeset
1214 "sub\t%3,%1,%1" \
kono
parents:
diff changeset
1215 : "=&r" ((USItype) (__q)), \
kono
parents:
diff changeset
1216 "=&r" ((USItype) (__r)) \
kono
parents:
diff changeset
1217 : "r" ((USItype) (__n1)), \
kono
parents:
diff changeset
1218 "r" ((USItype) (__n0)), \
kono
parents:
diff changeset
1219 "r" ((USItype) (__d)))
kono
parents:
diff changeset
1220 #else
kono
parents:
diff changeset
1221 #if defined (__sparc_v8__)
kono
parents:
diff changeset
1222 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1223 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
kono
parents:
diff changeset
1224 : "=r" ((USItype) (w1)), \
kono
parents:
diff changeset
1225 "=r" ((USItype) (w0)) \
kono
parents:
diff changeset
1226 : "r" ((USItype) (u)), \
kono
parents:
diff changeset
1227 "r" ((USItype) (v)))
kono
parents:
diff changeset
1228 #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
kono
parents:
diff changeset
1229 __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
kono
parents:
diff changeset
1230 : "=&r" ((USItype) (__q)), \
kono
parents:
diff changeset
1231 "=&r" ((USItype) (__r)) \
kono
parents:
diff changeset
1232 : "r" ((USItype) (__n1)), \
kono
parents:
diff changeset
1233 "r" ((USItype) (__n0)), \
kono
parents:
diff changeset
1234 "r" ((USItype) (__d)))
kono
parents:
diff changeset
1235 #else
kono
parents:
diff changeset
1236 #if defined (__sparclite__)
kono
parents:
diff changeset
1237 /* This has hardware multiply but not divide. It also has two additional
kono
parents:
diff changeset
1238 instructions scan (ffs from high bit) and divscc. */
kono
parents:
diff changeset
1239 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1240 __asm__ ("umul %2,%3,%1;rd %%y,%0" \
kono
parents:
diff changeset
1241 : "=r" ((USItype) (w1)), \
kono
parents:
diff changeset
1242 "=r" ((USItype) (w0)) \
kono
parents:
diff changeset
1243 : "r" ((USItype) (u)), \
kono
parents:
diff changeset
1244 "r" ((USItype) (v)))
kono
parents:
diff changeset
1245 #define udiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
1246 __asm__ ("! Inlined udiv_qrnnd\n" \
kono
parents:
diff changeset
1247 " wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
kono
parents:
diff changeset
1248 " tst %%g0\n" \
kono
parents:
diff changeset
1249 " divscc %3,%4,%%g1\n" \
kono
parents:
diff changeset
1250 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1251 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1252 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1253 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1254 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1255 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1256 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1257 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1258 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1259 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1260 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1261 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1262 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1263 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1264 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1265 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1266 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1267 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1268 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1269 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1270 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1271 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1272 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1273 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1274 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1275 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1276 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1277 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1278 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1279 " divscc %%g1,%4,%%g1\n" \
kono
parents:
diff changeset
1280 " divscc %%g1,%4,%0\n" \
kono
parents:
diff changeset
1281 " rd %%y,%1\n" \
kono
parents:
diff changeset
1282 " bl,a 1f\n" \
kono
parents:
diff changeset
1283 " add %1,%4,%1\n" \
kono
parents:
diff changeset
1284 "1: ! End of inline udiv_qrnnd" \
kono
parents:
diff changeset
1285 : "=r" ((USItype) (q)), \
kono
parents:
diff changeset
1286 "=r" ((USItype) (r)) \
kono
parents:
diff changeset
1287 : "r" ((USItype) (n1)), \
kono
parents:
diff changeset
1288 "r" ((USItype) (n0)), \
kono
parents:
diff changeset
1289 "rI" ((USItype) (d)) \
kono
parents:
diff changeset
1290 : "g1" __AND_CLOBBER_CC)
kono
parents:
diff changeset
1291 #define UDIV_TIME 37
kono
parents:
diff changeset
1292 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
1293 do { \
kono
parents:
diff changeset
1294 __asm__ ("scan %1,1,%0" \
kono
parents:
diff changeset
1295 : "=r" ((USItype) (count)) \
kono
parents:
diff changeset
1296 : "r" ((USItype) (x))); \
kono
parents:
diff changeset
1297 } while (0)
kono
parents:
diff changeset
1298 /* Early sparclites return 63 for an argument of 0, but they warn that future
kono
parents:
diff changeset
1299 implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
kono
parents:
diff changeset
1300 undefined. */
kono
parents:
diff changeset
1301 #else
kono
parents:
diff changeset
1302 /* SPARC without integer multiplication and divide instructions.
kono
parents:
diff changeset
1303 (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
kono
parents:
diff changeset
1304 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1305 __asm__ ("! Inlined umul_ppmm\n" \
kono
parents:
diff changeset
1306 " wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n"\
kono
parents:
diff changeset
1307 " sra %3,31,%%o5 ! Don't move this insn\n" \
kono
parents:
diff changeset
1308 " and %2,%%o5,%%o5 ! Don't move this insn\n" \
kono
parents:
diff changeset
1309 " andcc %%g0,0,%%g1 ! Don't move this insn\n" \
kono
parents:
diff changeset
1310 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1311 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1312 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1313 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1314 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1315 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1316 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1317 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1318 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1319 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1320 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1321 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1322 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1323 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1324 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1325 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1326 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1327 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1328 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1329 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1330 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1331 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1332 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1333 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1334 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1335 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1336 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1337 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1338 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1339 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1340 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1341 " mulscc %%g1,%3,%%g1\n" \
kono
parents:
diff changeset
1342 " mulscc %%g1,0,%%g1\n" \
kono
parents:
diff changeset
1343 " add %%g1,%%o5,%0\n" \
kono
parents:
diff changeset
1344 " rd %%y,%1" \
kono
parents:
diff changeset
1345 : "=r" ((USItype) (w1)), \
kono
parents:
diff changeset
1346 "=r" ((USItype) (w0)) \
kono
parents:
diff changeset
1347 : "%rI" ((USItype) (u)), \
kono
parents:
diff changeset
1348 "r" ((USItype) (v)) \
kono
parents:
diff changeset
1349 : "g1", "o5" __AND_CLOBBER_CC)
kono
parents:
diff changeset
1350 #define UMUL_TIME 39 /* 39 instructions */
kono
parents:
diff changeset
1351 /* It's quite necessary to add this much assembler for the sparc.
kono
parents:
diff changeset
1352 The default udiv_qrnnd (in C) is more than 10 times slower! */
kono
parents:
diff changeset
1353 #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
kono
parents:
diff changeset
1354 __asm__ ("! Inlined udiv_qrnnd\n" \
kono
parents:
diff changeset
1355 " mov 32,%%g1\n" \
kono
parents:
diff changeset
1356 " subcc %1,%2,%%g0\n" \
kono
parents:
diff changeset
1357 "1: bcs 5f\n" \
kono
parents:
diff changeset
1358 " addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
kono
parents:
diff changeset
1359 " sub %1,%2,%1 ! this kills msb of n\n" \
kono
parents:
diff changeset
1360 " addx %1,%1,%1 ! so this can't give carry\n" \
kono
parents:
diff changeset
1361 " subcc %%g1,1,%%g1\n" \
kono
parents:
diff changeset
1362 "2: bne 1b\n" \
kono
parents:
diff changeset
1363 " subcc %1,%2,%%g0\n" \
kono
parents:
diff changeset
1364 " bcs 3f\n" \
kono
parents:
diff changeset
1365 " addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
kono
parents:
diff changeset
1366 " b 3f\n" \
kono
parents:
diff changeset
1367 " sub %1,%2,%1 ! this kills msb of n\n" \
kono
parents:
diff changeset
1368 "4: sub %1,%2,%1\n" \
kono
parents:
diff changeset
1369 "5: addxcc %1,%1,%1\n" \
kono
parents:
diff changeset
1370 " bcc 2b\n" \
kono
parents:
diff changeset
1371 " subcc %%g1,1,%%g1\n" \
kono
parents:
diff changeset
1372 "! Got carry from n. Subtract next step to cancel this carry.\n" \
kono
parents:
diff changeset
1373 " bne 4b\n" \
kono
parents:
diff changeset
1374 " addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n" \
kono
parents:
diff changeset
1375 " sub %1,%2,%1\n" \
kono
parents:
diff changeset
1376 "3: xnor %0,0,%0\n" \
kono
parents:
diff changeset
1377 " ! End of inline udiv_qrnnd" \
kono
parents:
diff changeset
1378 : "=&r" ((USItype) (__q)), \
kono
parents:
diff changeset
1379 "=&r" ((USItype) (__r)) \
kono
parents:
diff changeset
1380 : "r" ((USItype) (__d)), \
kono
parents:
diff changeset
1381 "1" ((USItype) (__n1)), \
kono
parents:
diff changeset
1382 "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
kono
parents:
diff changeset
1383 #define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
kono
parents:
diff changeset
1384 #endif /* __sparclite__ */
kono
parents:
diff changeset
1385 #endif /* __sparc_v8__ */
kono
parents:
diff changeset
1386 #endif /* __sparc_v9__ */
kono
parents:
diff changeset
1387 #endif /* sparc32 */
kono
parents:
diff changeset
1388
kono
parents:
diff changeset
1389 #if ((defined (__sparc__) && defined (__arch64__)) || defined (__sparcv9)) \
kono
parents:
diff changeset
1390 && W_TYPE_SIZE == 64
kono
parents:
diff changeset
1391 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1392 do { \
kono
parents:
diff changeset
1393 UDItype __carry = 0; \
kono
parents:
diff changeset
1394 __asm__ ("addcc\t%r5,%6,%1\n\t" \
kono
parents:
diff changeset
1395 "add\t%r3,%4,%0\n\t" \
kono
parents:
diff changeset
1396 "movcs\t%%xcc, 1, %2\n\t" \
kono
parents:
diff changeset
1397 "add\t%0, %2, %0" \
kono
parents:
diff changeset
1398 : "=r" ((UDItype)(sh)), \
kono
parents:
diff changeset
1399 "=&r" ((UDItype)(sl)), \
kono
parents:
diff changeset
1400 "+r" (__carry) \
kono
parents:
diff changeset
1401 : "%rJ" ((UDItype)(ah)), \
kono
parents:
diff changeset
1402 "rI" ((UDItype)(bh)), \
kono
parents:
diff changeset
1403 "%rJ" ((UDItype)(al)), \
kono
parents:
diff changeset
1404 "rI" ((UDItype)(bl)) \
kono
parents:
diff changeset
1405 __CLOBBER_CC); \
kono
parents:
diff changeset
1406 } while (0)
kono
parents:
diff changeset
1407
kono
parents:
diff changeset
1408 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1409 do { \
kono
parents:
diff changeset
1410 UDItype __carry = 0; \
kono
parents:
diff changeset
1411 __asm__ ("subcc\t%r5,%6,%1\n\t" \
kono
parents:
diff changeset
1412 "sub\t%r3,%4,%0\n\t" \
kono
parents:
diff changeset
1413 "movcs\t%%xcc, 1, %2\n\t" \
kono
parents:
diff changeset
1414 "sub\t%0, %2, %0" \
kono
parents:
diff changeset
1415 : "=r" ((UDItype)(sh)), \
kono
parents:
diff changeset
1416 "=&r" ((UDItype)(sl)), \
kono
parents:
diff changeset
1417 "+r" (__carry) \
kono
parents:
diff changeset
1418 : "%rJ" ((UDItype)(ah)), \
kono
parents:
diff changeset
1419 "rI" ((UDItype)(bh)), \
kono
parents:
diff changeset
1420 "%rJ" ((UDItype)(al)), \
kono
parents:
diff changeset
1421 "rI" ((UDItype)(bl)) \
kono
parents:
diff changeset
1422 __CLOBBER_CC); \
kono
parents:
diff changeset
1423 } while (0)
kono
parents:
diff changeset
1424
kono
parents:
diff changeset
1425 #define umul_ppmm(wh, wl, u, v) \
kono
parents:
diff changeset
1426 do { \
kono
parents:
diff changeset
1427 UDItype tmp1, tmp2, tmp3, tmp4; \
kono
parents:
diff changeset
1428 __asm__ __volatile__ ( \
kono
parents:
diff changeset
1429 "srl %7,0,%3\n\t" \
kono
parents:
diff changeset
1430 "mulx %3,%6,%1\n\t" \
kono
parents:
diff changeset
1431 "srlx %6,32,%2\n\t" \
kono
parents:
diff changeset
1432 "mulx %2,%3,%4\n\t" \
kono
parents:
diff changeset
1433 "sllx %4,32,%5\n\t" \
kono
parents:
diff changeset
1434 "srl %6,0,%3\n\t" \
kono
parents:
diff changeset
1435 "sub %1,%5,%5\n\t" \
kono
parents:
diff changeset
1436 "srlx %5,32,%5\n\t" \
kono
parents:
diff changeset
1437 "addcc %4,%5,%4\n\t" \
kono
parents:
diff changeset
1438 "srlx %7,32,%5\n\t" \
kono
parents:
diff changeset
1439 "mulx %3,%5,%3\n\t" \
kono
parents:
diff changeset
1440 "mulx %2,%5,%5\n\t" \
kono
parents:
diff changeset
1441 "sethi %%hi(0x80000000),%2\n\t" \
kono
parents:
diff changeset
1442 "addcc %4,%3,%4\n\t" \
kono
parents:
diff changeset
1443 "srlx %4,32,%4\n\t" \
kono
parents:
diff changeset
1444 "add %2,%2,%2\n\t" \
kono
parents:
diff changeset
1445 "movcc %%xcc,%%g0,%2\n\t" \
kono
parents:
diff changeset
1446 "addcc %5,%4,%5\n\t" \
kono
parents:
diff changeset
1447 "sllx %3,32,%3\n\t" \
kono
parents:
diff changeset
1448 "add %1,%3,%1\n\t" \
kono
parents:
diff changeset
1449 "add %5,%2,%0" \
kono
parents:
diff changeset
1450 : "=r" ((UDItype)(wh)), \
kono
parents:
diff changeset
1451 "=&r" ((UDItype)(wl)), \
kono
parents:
diff changeset
1452 "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
kono
parents:
diff changeset
1453 : "r" ((UDItype)(u)), \
kono
parents:
diff changeset
1454 "r" ((UDItype)(v)) \
kono
parents:
diff changeset
1455 __CLOBBER_CC); \
kono
parents:
diff changeset
1456 } while (0)
kono
parents:
diff changeset
1457 #define UMUL_TIME 96
kono
parents:
diff changeset
1458 #define UDIV_TIME 230
kono
parents:
diff changeset
1459 #endif /* sparc64 */
kono
parents:
diff changeset
1460
kono
parents:
diff changeset
1461 #if defined (__vax__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
1462 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1463 __asm__ ("addl2 %5,%1\n\tadwc %3,%0" \
kono
parents:
diff changeset
1464 : "=g" ((USItype) (sh)), \
kono
parents:
diff changeset
1465 "=&g" ((USItype) (sl)) \
kono
parents:
diff changeset
1466 : "%0" ((USItype) (ah)), \
kono
parents:
diff changeset
1467 "g" ((USItype) (bh)), \
kono
parents:
diff changeset
1468 "%1" ((USItype) (al)), \
kono
parents:
diff changeset
1469 "g" ((USItype) (bl)))
kono
parents:
diff changeset
1470 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1471 __asm__ ("subl2 %5,%1\n\tsbwc %3,%0" \
kono
parents:
diff changeset
1472 : "=g" ((USItype) (sh)), \
kono
parents:
diff changeset
1473 "=&g" ((USItype) (sl)) \
kono
parents:
diff changeset
1474 : "0" ((USItype) (ah)), \
kono
parents:
diff changeset
1475 "g" ((USItype) (bh)), \
kono
parents:
diff changeset
1476 "1" ((USItype) (al)), \
kono
parents:
diff changeset
1477 "g" ((USItype) (bl)))
kono
parents:
diff changeset
1478 #define umul_ppmm(xh, xl, m0, m1) \
kono
parents:
diff changeset
1479 do { \
kono
parents:
diff changeset
1480 union { \
kono
parents:
diff changeset
1481 UDItype __ll; \
kono
parents:
diff changeset
1482 struct {USItype __l, __h;} __i; \
kono
parents:
diff changeset
1483 } __xx; \
kono
parents:
diff changeset
1484 USItype __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
1485 __asm__ ("emul %1,%2,$0,%0" \
kono
parents:
diff changeset
1486 : "=r" (__xx.__ll) \
kono
parents:
diff changeset
1487 : "g" (__m0), \
kono
parents:
diff changeset
1488 "g" (__m1)); \
kono
parents:
diff changeset
1489 (xh) = __xx.__i.__h; \
kono
parents:
diff changeset
1490 (xl) = __xx.__i.__l; \
kono
parents:
diff changeset
1491 (xh) += ((((SItype) __m0 >> 31) & __m1) \
kono
parents:
diff changeset
1492 + (((SItype) __m1 >> 31) & __m0)); \
kono
parents:
diff changeset
1493 } while (0)
kono
parents:
diff changeset
1494 #define sdiv_qrnnd(q, r, n1, n0, d) \
kono
parents:
diff changeset
1495 do { \
kono
parents:
diff changeset
1496 union {DItype __ll; \
kono
parents:
diff changeset
1497 struct {SItype __l, __h;} __i; \
kono
parents:
diff changeset
1498 } __xx; \
kono
parents:
diff changeset
1499 __xx.__i.__h = n1; __xx.__i.__l = n0; \
kono
parents:
diff changeset
1500 __asm__ ("ediv %3,%2,%0,%1" \
kono
parents:
diff changeset
1501 : "=g" (q), "=g" (r) \
kono
parents:
diff changeset
1502 : "g" (__xx.__ll), "g" (d)); \
kono
parents:
diff changeset
1503 } while (0)
kono
parents:
diff changeset
1504 #endif /* __vax__ */
kono
parents:
diff changeset
1505
kono
parents:
diff changeset
1506 #ifdef _TMS320C6X
kono
parents:
diff changeset
1507 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1508 do \
kono
parents:
diff changeset
1509 { \
kono
parents:
diff changeset
1510 UDItype __ll; \
kono
parents:
diff changeset
1511 __asm__ ("addu .l1 %1, %2, %0" \
kono
parents:
diff changeset
1512 : "=a" (__ll) : "a" (al), "a" (bl)); \
kono
parents:
diff changeset
1513 (sl) = (USItype)__ll; \
kono
parents:
diff changeset
1514 (sh) = ((USItype)(__ll >> 32)) + (ah) + (bh); \
kono
parents:
diff changeset
1515 } \
kono
parents:
diff changeset
1516 while (0)
kono
parents:
diff changeset
1517
kono
parents:
diff changeset
1518 #ifdef _TMS320C6400_PLUS
kono
parents:
diff changeset
1519 #define __umulsidi3(u,v) ((UDItype)(USItype)u*(USItype)v)
kono
parents:
diff changeset
1520 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1521 do { \
kono
parents:
diff changeset
1522 UDItype __x = (UDItype) (USItype) (u) * (USItype) (v); \
kono
parents:
diff changeset
1523 (w1) = (USItype) (__x >> 32); \
kono
parents:
diff changeset
1524 (w0) = (USItype) (__x); \
kono
parents:
diff changeset
1525 } while (0)
kono
parents:
diff changeset
1526 #endif /* _TMS320C6400_PLUS */
kono
parents:
diff changeset
1527
kono
parents:
diff changeset
1528 #define count_leading_zeros(count, x) ((count) = __builtin_clz (x))
kono
parents:
diff changeset
1529 #ifdef _TMS320C6400
kono
parents:
diff changeset
1530 #define count_trailing_zeros(count, x) ((count) = __builtin_ctz (x))
kono
parents:
diff changeset
1531 #endif
kono
parents:
diff changeset
1532 #define UMUL_TIME 4
kono
parents:
diff changeset
1533 #define UDIV_TIME 40
kono
parents:
diff changeset
1534 #endif /* _TMS320C6X */
kono
parents:
diff changeset
1535
kono
parents:
diff changeset
1536 #if defined (__xtensa__) && W_TYPE_SIZE == 32
kono
parents:
diff changeset
1537 /* This code is not Xtensa-configuration-specific, so rely on the compiler
kono
parents:
diff changeset
1538 to expand builtin functions depending on what configuration features
kono
parents:
diff changeset
1539 are available. This avoids library calls when the operation can be
kono
parents:
diff changeset
1540 performed in-line. */
kono
parents:
diff changeset
1541 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1542 do { \
kono
parents:
diff changeset
1543 DWunion __w; \
kono
parents:
diff changeset
1544 __w.ll = __builtin_umulsidi3 (u, v); \
kono
parents:
diff changeset
1545 w1 = __w.s.high; \
kono
parents:
diff changeset
1546 w0 = __w.s.low; \
kono
parents:
diff changeset
1547 } while (0)
kono
parents:
diff changeset
1548 #define __umulsidi3(u, v) __builtin_umulsidi3 (u, v)
kono
parents:
diff changeset
1549 #define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
kono
parents:
diff changeset
1550 #define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X))
kono
parents:
diff changeset
1551 #endif /* __xtensa__ */
kono
parents:
diff changeset
1552
kono
parents:
diff changeset
1553 #if defined xstormy16
kono
parents:
diff changeset
1554 extern UHItype __stormy16_count_leading_zeros (UHItype);
kono
parents:
diff changeset
1555 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
1556 do \
kono
parents:
diff changeset
1557 { \
kono
parents:
diff changeset
1558 UHItype size; \
kono
parents:
diff changeset
1559 \
kono
parents:
diff changeset
1560 /* We assume that W_TYPE_SIZE is a multiple of 16... */ \
kono
parents:
diff changeset
1561 for ((count) = 0, size = W_TYPE_SIZE; size; size -= 16) \
kono
parents:
diff changeset
1562 { \
kono
parents:
diff changeset
1563 UHItype c; \
kono
parents:
diff changeset
1564 \
kono
parents:
diff changeset
1565 c = __clzhi2 ((x) >> (size - 16)); \
kono
parents:
diff changeset
1566 (count) += c; \
kono
parents:
diff changeset
1567 if (c != 16) \
kono
parents:
diff changeset
1568 break; \
kono
parents:
diff changeset
1569 } \
kono
parents:
diff changeset
1570 } \
kono
parents:
diff changeset
1571 while (0)
kono
parents:
diff changeset
1572 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
kono
parents:
diff changeset
1573 #endif
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 #if defined (__z8000__) && W_TYPE_SIZE == 16
kono
parents:
diff changeset
1576 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1577 __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
kono
parents:
diff changeset
1578 : "=r" ((unsigned int)(sh)), \
kono
parents:
diff changeset
1579 "=&r" ((unsigned int)(sl)) \
kono
parents:
diff changeset
1580 : "%0" ((unsigned int)(ah)), \
kono
parents:
diff changeset
1581 "r" ((unsigned int)(bh)), \
kono
parents:
diff changeset
1582 "%1" ((unsigned int)(al)), \
kono
parents:
diff changeset
1583 "rQR" ((unsigned int)(bl)))
kono
parents:
diff changeset
1584 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1585 __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
kono
parents:
diff changeset
1586 : "=r" ((unsigned int)(sh)), \
kono
parents:
diff changeset
1587 "=&r" ((unsigned int)(sl)) \
kono
parents:
diff changeset
1588 : "0" ((unsigned int)(ah)), \
kono
parents:
diff changeset
1589 "r" ((unsigned int)(bh)), \
kono
parents:
diff changeset
1590 "1" ((unsigned int)(al)), \
kono
parents:
diff changeset
1591 "rQR" ((unsigned int)(bl)))
kono
parents:
diff changeset
1592 #define umul_ppmm(xh, xl, m0, m1) \
kono
parents:
diff changeset
1593 do { \
kono
parents:
diff changeset
1594 union {long int __ll; \
kono
parents:
diff changeset
1595 struct {unsigned int __h, __l;} __i; \
kono
parents:
diff changeset
1596 } __xx; \
kono
parents:
diff changeset
1597 unsigned int __m0 = (m0), __m1 = (m1); \
kono
parents:
diff changeset
1598 __asm__ ("mult %S0,%H3" \
kono
parents:
diff changeset
1599 : "=r" (__xx.__i.__h), \
kono
parents:
diff changeset
1600 "=r" (__xx.__i.__l) \
kono
parents:
diff changeset
1601 : "%1" (__m0), \
kono
parents:
diff changeset
1602 "rQR" (__m1)); \
kono
parents:
diff changeset
1603 (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
kono
parents:
diff changeset
1604 (xh) += ((((signed int) __m0 >> 15) & __m1) \
kono
parents:
diff changeset
1605 + (((signed int) __m1 >> 15) & __m0)); \
kono
parents:
diff changeset
1606 } while (0)
kono
parents:
diff changeset
1607 #endif /* __z8000__ */
kono
parents:
diff changeset
1608
kono
parents:
diff changeset
1609 #endif /* __GNUC__ */
kono
parents:
diff changeset
1610
kono
parents:
diff changeset
1611 /* If this machine has no inline assembler, use C macros. */
kono
parents:
diff changeset
1612
kono
parents:
diff changeset
1613 #if !defined (add_ssaaaa)
kono
parents:
diff changeset
1614 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1615 do { \
kono
parents:
diff changeset
1616 UWtype __x; \
kono
parents:
diff changeset
1617 __x = (al) + (bl); \
kono
parents:
diff changeset
1618 (sh) = (ah) + (bh) + (__x < (al)); \
kono
parents:
diff changeset
1619 (sl) = __x; \
kono
parents:
diff changeset
1620 } while (0)
kono
parents:
diff changeset
1621 #endif
kono
parents:
diff changeset
1622
kono
parents:
diff changeset
1623 #if !defined (sub_ddmmss)
kono
parents:
diff changeset
1624 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
kono
parents:
diff changeset
1625 do { \
kono
parents:
diff changeset
1626 UWtype __x; \
kono
parents:
diff changeset
1627 __x = (al) - (bl); \
kono
parents:
diff changeset
1628 (sh) = (ah) - (bh) - (__x > (al)); \
kono
parents:
diff changeset
1629 (sl) = __x; \
kono
parents:
diff changeset
1630 } while (0)
kono
parents:
diff changeset
1631 #endif
kono
parents:
diff changeset
1632
kono
parents:
diff changeset
1633 /* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
kono
parents:
diff changeset
1634 smul_ppmm. */
kono
parents:
diff changeset
1635 #if !defined (umul_ppmm) && defined (smul_ppmm)
kono
parents:
diff changeset
1636 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1637 do { \
kono
parents:
diff changeset
1638 UWtype __w1; \
kono
parents:
diff changeset
1639 UWtype __xm0 = (u), __xm1 = (v); \
kono
parents:
diff changeset
1640 smul_ppmm (__w1, w0, __xm0, __xm1); \
kono
parents:
diff changeset
1641 (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \
kono
parents:
diff changeset
1642 + (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \
kono
parents:
diff changeset
1643 } while (0)
kono
parents:
diff changeset
1644 #endif
kono
parents:
diff changeset
1645
kono
parents:
diff changeset
1646 /* If we still don't have umul_ppmm, define it using plain C. */
kono
parents:
diff changeset
1647 #if !defined (umul_ppmm)
kono
parents:
diff changeset
1648 #define umul_ppmm(w1, w0, u, v) \
kono
parents:
diff changeset
1649 do { \
kono
parents:
diff changeset
1650 UWtype __x0, __x1, __x2, __x3; \
kono
parents:
diff changeset
1651 UHWtype __ul, __vl, __uh, __vh; \
kono
parents:
diff changeset
1652 \
kono
parents:
diff changeset
1653 __ul = __ll_lowpart (u); \
kono
parents:
diff changeset
1654 __uh = __ll_highpart (u); \
kono
parents:
diff changeset
1655 __vl = __ll_lowpart (v); \
kono
parents:
diff changeset
1656 __vh = __ll_highpart (v); \
kono
parents:
diff changeset
1657 \
kono
parents:
diff changeset
1658 __x0 = (UWtype) __ul * __vl; \
kono
parents:
diff changeset
1659 __x1 = (UWtype) __ul * __vh; \
kono
parents:
diff changeset
1660 __x2 = (UWtype) __uh * __vl; \
kono
parents:
diff changeset
1661 __x3 = (UWtype) __uh * __vh; \
kono
parents:
diff changeset
1662 \
kono
parents:
diff changeset
1663 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
kono
parents:
diff changeset
1664 __x1 += __x2; /* but this indeed can */ \
kono
parents:
diff changeset
1665 if (__x1 < __x2) /* did we get it? */ \
kono
parents:
diff changeset
1666 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
kono
parents:
diff changeset
1667 \
kono
parents:
diff changeset
1668 (w1) = __x3 + __ll_highpart (__x1); \
kono
parents:
diff changeset
1669 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
kono
parents:
diff changeset
1670 } while (0)
kono
parents:
diff changeset
1671 #endif
kono
parents:
diff changeset
1672
kono
parents:
diff changeset
1673 #if !defined (__umulsidi3)
kono
parents:
diff changeset
1674 #define __umulsidi3(u, v) \
kono
parents:
diff changeset
1675 ({DWunion __w; \
kono
parents:
diff changeset
1676 umul_ppmm (__w.s.high, __w.s.low, u, v); \
kono
parents:
diff changeset
1677 __w.ll; })
kono
parents:
diff changeset
1678 #endif
kono
parents:
diff changeset
1679
kono
parents:
diff changeset
1680 /* Define this unconditionally, so it can be used for debugging. */
kono
parents:
diff changeset
1681 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
kono
parents:
diff changeset
1682 do { \
kono
parents:
diff changeset
1683 UWtype __d1, __d0, __q1, __q0; \
kono
parents:
diff changeset
1684 UWtype __r1, __r0, __m; \
kono
parents:
diff changeset
1685 __d1 = __ll_highpart (d); \
kono
parents:
diff changeset
1686 __d0 = __ll_lowpart (d); \
kono
parents:
diff changeset
1687 \
kono
parents:
diff changeset
1688 __r1 = (n1) % __d1; \
kono
parents:
diff changeset
1689 __q1 = (n1) / __d1; \
kono
parents:
diff changeset
1690 __m = (UWtype) __q1 * __d0; \
kono
parents:
diff changeset
1691 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
kono
parents:
diff changeset
1692 if (__r1 < __m) \
kono
parents:
diff changeset
1693 { \
kono
parents:
diff changeset
1694 __q1--, __r1 += (d); \
kono
parents:
diff changeset
1695 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
kono
parents:
diff changeset
1696 if (__r1 < __m) \
kono
parents:
diff changeset
1697 __q1--, __r1 += (d); \
kono
parents:
diff changeset
1698 } \
kono
parents:
diff changeset
1699 __r1 -= __m; \
kono
parents:
diff changeset
1700 \
kono
parents:
diff changeset
1701 __r0 = __r1 % __d1; \
kono
parents:
diff changeset
1702 __q0 = __r1 / __d1; \
kono
parents:
diff changeset
1703 __m = (UWtype) __q0 * __d0; \
kono
parents:
diff changeset
1704 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
kono
parents:
diff changeset
1705 if (__r0 < __m) \
kono
parents:
diff changeset
1706 { \
kono
parents:
diff changeset
1707 __q0--, __r0 += (d); \
kono
parents:
diff changeset
1708 if (__r0 >= (d)) \
kono
parents:
diff changeset
1709 if (__r0 < __m) \
kono
parents:
diff changeset
1710 __q0--, __r0 += (d); \
kono
parents:
diff changeset
1711 } \
kono
parents:
diff changeset
1712 __r0 -= __m; \
kono
parents:
diff changeset
1713 \
kono
parents:
diff changeset
1714 (q) = (UWtype) __q1 * __ll_B | __q0; \
kono
parents:
diff changeset
1715 (r) = __r0; \
kono
parents:
diff changeset
1716 } while (0)
kono
parents:
diff changeset
1717
kono
parents:
diff changeset
1718 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
kono
parents:
diff changeset
1719 __udiv_w_sdiv (defined in libgcc or elsewhere). */
kono
parents:
diff changeset
1720 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
kono
parents:
diff changeset
1721 #define udiv_qrnnd(q, r, nh, nl, d) \
kono
parents:
diff changeset
1722 do { \
kono
parents:
diff changeset
1723 extern UWtype __udiv_w_sdiv (UWtype *, UWtype, UWtype, UWtype); \
kono
parents:
diff changeset
1724 UWtype __r; \
kono
parents:
diff changeset
1725 (q) = __udiv_w_sdiv (&__r, nh, nl, d); \
kono
parents:
diff changeset
1726 (r) = __r; \
kono
parents:
diff changeset
1727 } while (0)
kono
parents:
diff changeset
1728 #endif
kono
parents:
diff changeset
1729
kono
parents:
diff changeset
1730 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
kono
parents:
diff changeset
1731 #if !defined (udiv_qrnnd)
kono
parents:
diff changeset
1732 #define UDIV_NEEDS_NORMALIZATION 1
kono
parents:
diff changeset
1733 #define udiv_qrnnd __udiv_qrnnd_c
kono
parents:
diff changeset
1734 #endif
kono
parents:
diff changeset
1735
kono
parents:
diff changeset
1736 #if !defined (count_leading_zeros)
kono
parents:
diff changeset
1737 #define count_leading_zeros(count, x) \
kono
parents:
diff changeset
1738 do { \
kono
parents:
diff changeset
1739 UWtype __xr = (x); \
kono
parents:
diff changeset
1740 UWtype __a; \
kono
parents:
diff changeset
1741 \
kono
parents:
diff changeset
1742 if (W_TYPE_SIZE <= 32) \
kono
parents:
diff changeset
1743 { \
kono
parents:
diff changeset
1744 __a = __xr < ((UWtype)1<<2*__BITS4) \
kono
parents:
diff changeset
1745 ? (__xr < ((UWtype)1<<__BITS4) ? 0 : __BITS4) \
kono
parents:
diff changeset
1746 : (__xr < ((UWtype)1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
kono
parents:
diff changeset
1747 } \
kono
parents:
diff changeset
1748 else \
kono
parents:
diff changeset
1749 { \
kono
parents:
diff changeset
1750 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
kono
parents:
diff changeset
1751 if (((__xr >> __a) & 0xff) != 0) \
kono
parents:
diff changeset
1752 break; \
kono
parents:
diff changeset
1753 } \
kono
parents:
diff changeset
1754 \
kono
parents:
diff changeset
1755 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
kono
parents:
diff changeset
1756 } while (0)
kono
parents:
diff changeset
1757 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
kono
parents:
diff changeset
1758 #endif
kono
parents:
diff changeset
1759
kono
parents:
diff changeset
1760 #if !defined (count_trailing_zeros)
kono
parents:
diff changeset
1761 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
kono
parents:
diff changeset
1762 defined in asm, but if it is not, the C version above is good enough. */
kono
parents:
diff changeset
1763 #define count_trailing_zeros(count, x) \
kono
parents:
diff changeset
1764 do { \
kono
parents:
diff changeset
1765 UWtype __ctz_x = (x); \
kono
parents:
diff changeset
1766 UWtype __ctz_c; \
kono
parents:
diff changeset
1767 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
kono
parents:
diff changeset
1768 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
kono
parents:
diff changeset
1769 } while (0)
kono
parents:
diff changeset
1770 #endif
kono
parents:
diff changeset
1771
kono
parents:
diff changeset
1772 #ifndef UDIV_NEEDS_NORMALIZATION
kono
parents:
diff changeset
1773 #define UDIV_NEEDS_NORMALIZATION 0
kono
parents:
diff changeset
1774 #endif