| 1 |
/* longlong.h -- definitions for mixed size 32/64 bit arithmetic. |
| 2 |
Note: This is the Libgcrypt version |
| 3 |
|
| 4 |
|
| 5 |
Copyright (C) 1991, 1992, 1993, 1994, 1996, 1998, |
| 6 |
2000, 2001, 2002, 2003, 2004, 2011 Free Software Foundation, Inc. |
| 7 |
|
| 8 |
This file is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU Lesser General Public License as published by |
| 10 |
the Free Software Foundation; either version 2.1 of the License, or (at your |
| 11 |
option) any later version. |
| 12 |
|
| 13 |
This file is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 16 |
License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU Library General Public License |
| 19 |
along with this file; see the file COPYING.LIB. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
SPDX-License-Identifier: LGPL-2.1-or-later |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "const-time.h" |
| 24 |
|
| 25 |
/* On 32-bit, use 64-bit 'unsigned long long' for UDWtype, if available. */ |
| 26 |
#if !defined (UDWtype) && SIZEOF_UNSIGNED_LONG_LONG * 8 == W_TYPE_SIZE * 2 |
| 27 |
# define UDWtype unsigned long long |
| 28 |
#endif |
| 29 |
|
| 30 |
/* On 64-bit, use 128-bit 'unsigned __int128' for UDWtype, if available. */ |
| 31 |
#if !defined (UDWtype) && SIZEOF_UNSIGNED___INT128 * 8 == W_TYPE_SIZE * 2 |
| 32 |
# define UDWtype unsigned __int128 |
| 33 |
#endif |
| 34 |
|
| 35 |
/* You have to define the following before including this file: |
| 36 |
|
| 37 |
UWtype -- An unsigned type, default type for operations (typically a "word"). |
| 38 |
UHWtype -- An unsigned type, at least half the size of UWtype. |
| 39 |
UDWtype -- An unsigned type, at least twice as large a UWtype. |
| 40 |
W_TYPE_SIZE -- size in bits of UWtype. |
| 41 |
|
| 42 |
SItype, USItype -- Signed and unsigned 32 bit types. |
| 43 |
DItype, UDItype -- Signed and unsigned 64 bit types. |
| 44 |
|
| 45 |
On a 32 bit machine UWtype should typically be USItype. |
| 46 |
On a 64 bit machine, UWtype should typically be UDItype. |
| 47 |
*/ |
| 48 |
|
| 49 |
#define __BITS4 (W_TYPE_SIZE / 4) |
| 50 |
#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2)) |
| 51 |
#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1)) |
| 52 |
#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2)) |
| 53 |
|
| 54 |
/* This is used to make sure no undesirable sharing between different libraries |
| 55 |
that use this file takes place. */ |
| 56 |
#ifndef __MPN |
| 57 |
# define __MPN(x) __##x |
| 58 |
#endif |
| 59 |
|
| 60 |
/* Define auxiliary asm macros. |
| 61 |
|
| 62 |
1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two |
| 63 |
UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype |
| 64 |
word product in HIGH_PROD and LOW_PROD. |
| 65 |
|
| 66 |
2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a |
| 67 |
UDWtype product. This is just a variant of umul_ppmm. |
| 68 |
|
| 69 |
3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator, |
| 70 |
denominator) divides a UDWtype, composed by the UWtype integers |
| 71 |
HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient |
| 72 |
in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less |
| 73 |
than DENOMINATOR for correct operation. If, in addition, the most |
| 74 |
significant bit of DENOMINATOR must be 1, then the pre-processor symbol |
| 75 |
UDIV_NEEDS_NORMALIZATION is defined to 1. |
| 76 |
|
| 77 |
4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator, |
| 78 |
denominator). Like udiv_qrnnd but the numbers are signed. The quotient |
| 79 |
is rounded towards 0. |
| 80 |
|
| 81 |
5) count_leading_zeros(count, x) counts the number of zero-bits from the |
| 82 |
msb to the first non-zero bit in the UWtype X. This is the number of |
| 83 |
steps X needs to be shifted left to set the msb. Undefined for X == 0, |
| 84 |
unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value. |
| 85 |
|
| 86 |
6) count_trailing_zeros(count, x) like count_leading_zeros, but counts |
| 87 |
from the least significant end. |
| 88 |
|
| 89 |
7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1, |
| 90 |
high_addend_2, low_addend_2) adds two UWtype integers, composed by |
| 91 |
HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2 |
| 92 |
respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow |
| 93 |
(i.e. carry out) is not stored anywhere, and is lost. |
| 94 |
|
| 95 |
8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend, |
| 96 |
high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers, |
| 97 |
composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and |
| 98 |
LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE |
| 99 |
and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere, |
| 100 |
and is lost. |
| 101 |
|
| 102 |
If any of these macros are left undefined for a particular CPU, |
| 103 |
C macros are used. */ |
| 104 |
|
| 105 |
/* The CPUs come in alphabetical order below. |
| 106 |
|
| 107 |
Please add support for more CPUs here, or improve the current support |
| 108 |
for the CPUs below! */ |
| 109 |
|
| 110 |
#ifdef __riscos__ |
| 111 |
#pragma continue_after_hash_error |
| 112 |
#else /* !__riscos__ */ |
| 113 |
#if defined (__GNUC__) && !defined (NO_ASM) |
| 114 |
|
| 115 |
/* We sometimes need to clobber "cc" with gcc2, but that would not be |
| 116 |
understood by gcc1. Use cpp to avoid major code duplication. */ |
| 117 |
#if __GNUC__ < 2 |
| 118 |
# define __CLOBBER_CC |
| 119 |
# define __AND_CLOBBER_CC |
| 120 |
#else /* __GNUC__ >= 2 */ |
| 121 |
# define __CLOBBER_CC : "cc" |
| 122 |
# define __AND_CLOBBER_CC , "cc" |
| 123 |
#endif /* __GNUC__ < 2 */ |
| 124 |
|
| 125 |
/*************************************** |
| 126 |
**** Begin CPU Specific Versions **** |
| 127 |
***************************************/ |
| 128 |
|
| 129 |
/*************************************** |
| 130 |
************** A29K ***************** |
| 131 |
***************************************/ |
| 132 |
#if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32 |
| 133 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 134 |
__asm__ ("add %1,%4,%5\n" \ |
| 135 |
"addc %0,%2,%3" \ |
| 136 |
: "=r" ((USItype)(sh)), \ |
| 137 |
"=&r" ((USItype)(sl)) \ |
| 138 |
: "%r" ((USItype)(ah)), \ |
| 139 |
"rI" ((USItype)(bh)), \ |
| 140 |
"%r" ((USItype)(al)), \ |
| 141 |
"rI" ((USItype)(bl))) |
| 142 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 143 |
__asm__ ("sub %1,%4,%5\n" \ |
| 144 |
"subc %0,%2,%3" \ |
| 145 |
: "=r" ((USItype)(sh)), \ |
| 146 |
"=&r" ((USItype)(sl)) \ |
| 147 |
: "r" ((USItype)(ah)), \ |
| 148 |
"rI" ((USItype)(bh)), \ |
| 149 |
"r" ((USItype)(al)), \ |
| 150 |
"rI" ((USItype)(bl))) |
| 151 |
# define umul_ppmm(xh, xl, m0, m1) \ |
| 152 |
do { \ |
| 153 |
USItype __m0 = (m0), __m1 = (m1); \ |
| 154 |
__asm__ ("multiplu %0,%1,%2" \ |
| 155 |
: "=r" ((USItype)(xl)) \ |
| 156 |
: "r" (__m0), \ |
| 157 |
"r" (__m1)); \ |
| 158 |
__asm__ ("multmu %0,%1,%2" \ |
| 159 |
: "=r" ((USItype)(xh)) \ |
| 160 |
: "r" (__m0), \ |
| 161 |
"r" (__m1)); \ |
| 162 |
} while (0) |
| 163 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 164 |
__asm__ ("dividu %0,%3,%4" \ |
| 165 |
: "=r" ((USItype)(q)), \ |
| 166 |
"=q" ((USItype)(r)) \ |
| 167 |
: "1" ((USItype)(n1)), \ |
| 168 |
"r" ((USItype)(n0)), \ |
| 169 |
"r" ((USItype)(d))) |
| 170 |
# define count_leading_zeros(count, x) \ |
| 171 |
__asm__ ("clz %0,%1" \ |
| 172 |
: "=r" ((USItype)(count)) \ |
| 173 |
: "r" ((USItype)(x))) |
| 174 |
# define COUNT_LEADING_ZEROS_0 32 |
| 175 |
#endif /* __a29k__ */ |
| 176 |
|
| 177 |
|
| 178 |
#if defined (__alpha) && W_TYPE_SIZE == 64 |
| 179 |
# define umul_ppmm(ph, pl, m0, m1) \ |
| 180 |
do { \ |
| 181 |
UDItype __m0 = (m0), __m1 = (m1); \ |
| 182 |
__asm__ ("umulh %r1,%2,%0" \ |
| 183 |
: "=r" ((UDItype)(ph)) \ |
| 184 |
: "%rJ" (__m0), \ |
| 185 |
"rI" (__m1)); \ |
| 186 |
(pl) = __m0 * __m1; \ |
| 187 |
} while (0) |
| 188 |
# define UMUL_TIME 46 |
| 189 |
# ifndef LONGLONG_STANDALONE |
| 190 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 191 |
do { UDItype __r; \ |
| 192 |
(q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \ |
| 193 |
(r) = __r; \ |
| 194 |
} while (0) |
| 195 |
extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype); |
| 196 |
# define UDIV_TIME 220 |
| 197 |
# endif /* !LONGLONG_STANDALONE */ |
| 198 |
#endif /* __alpha */ |
| 199 |
|
| 200 |
/*************************************** |
| 201 |
************** ARM ****************** |
| 202 |
***************************************/ |
| 203 |
#if defined (__arm__) && W_TYPE_SIZE == 32 && \ |
| 204 |
(!defined (__thumb__) || defined (__thumb2__)) |
| 205 |
/* The __ARM_ARCH define is provided by gcc 4.8. Construct it otherwise. */ |
| 206 |
# ifndef __ARM_ARCH |
| 207 |
# ifdef __ARM_ARCH_2__ |
| 208 |
# define __ARM_ARCH 2 |
| 209 |
# elif defined (__ARM_ARCH_3__) || defined (__ARM_ARCH_3M__) |
| 210 |
# define __ARM_ARCH 3 |
| 211 |
# elif defined (__ARM_ARCH_4__) || defined (__ARM_ARCH_4T__) |
| 212 |
# define __ARM_ARCH 4 |
| 213 |
# elif defined (__ARM_ARCH_5__) || defined (__ARM_ARCH_5E__) \ |
| 214 |
|| defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5TE__) \ |
| 215 |
|| defined(__ARM_ARCH_5TEJ__) |
| 216 |
# define __ARM_ARCH 5 |
| 217 |
# elif defined (__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ |
| 218 |
|| defined (__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \ |
| 219 |
|| defined (__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) |
| 220 |
# define __ARM_ARCH 6 |
| 221 |
# elif defined (__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ |
| 222 |
|| defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ |
| 223 |
|| defined(__ARM_ARCH_7EM__) |
| 224 |
# define __ARM_ARCH 7 |
| 225 |
# else |
| 226 |
/* could not detect? */ |
| 227 |
# endif |
| 228 |
# endif /* !__ARM_ARCH */ |
| 229 |
|
| 230 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 231 |
__asm__ ("adds %1, %4, %5\n" \ |
| 232 |
"adc %0, %2, %3" \ |
| 233 |
: "=r" ((sh)), \ |
| 234 |
"=&r" ((sl)) \ |
| 235 |
: "%r" ((USItype)(ah)), \ |
| 236 |
"rI" ((USItype)(bh)), \ |
| 237 |
"%r" ((USItype)(al)), \ |
| 238 |
"rI" ((USItype)(bl)) __CLOBBER_CC) |
| 239 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 240 |
__asm__ ("subs %1, %4, %5\n" \ |
| 241 |
"sbc %0, %2, %3" \ |
| 242 |
: "=r" ((sh)), \ |
| 243 |
"=&r" ((sl)) \ |
| 244 |
: "r" ((USItype)(ah)), \ |
| 245 |
"rI" ((USItype)(bh)), \ |
| 246 |
"r" ((USItype)(al)), \ |
| 247 |
"rI" ((USItype)(bl)) __CLOBBER_CC) |
| 248 |
# if (defined __ARM_ARCH && __ARM_ARCH <= 3) |
| 249 |
# define umul_ppmm(xh, xl, a, b) \ |
| 250 |
__asm__ ("@ Inlined umul_ppmm\n" \ |
| 251 |
"mov %|r0, %2, lsr #16 @ AAAA\n" \ |
| 252 |
"mov %|r2, %3, lsr #16 @ BBBB\n" \ |
| 253 |
"bic %|r1, %2, %|r0, lsl #16 @ aaaa\n" \ |
| 254 |
"bic %0, %3, %|r2, lsl #16 @ bbbb\n" \ |
| 255 |
"mul %1, %|r1, %|r2 @ aaaa * BBBB\n" \ |
| 256 |
"mul %|r2, %|r0, %|r2 @ AAAA * BBBB\n" \ |
| 257 |
"mul %|r1, %0, %|r1 @ aaaa * bbbb\n" \ |
| 258 |
"mul %0, %|r0, %0 @ AAAA * bbbb\n" \ |
| 259 |
"adds %|r0, %1, %0 @ central sum\n" \ |
| 260 |
"addcs %|r2, %|r2, #65536\n" \ |
| 261 |
"adds %1, %|r1, %|r0, lsl #16\n" \ |
| 262 |
"adc %0, %|r2, %|r0, lsr #16" \ |
| 263 |
: "=&r" ((xh)), \ |
| 264 |
"=r" ((xl)) \ |
| 265 |
: "r" ((USItype)(a)), \ |
| 266 |
"r" ((USItype)(b)) \ |
| 267 |
: "r0", "r1", "r2" __AND_CLOBBER_CC) |
| 268 |
# else /* __ARM_ARCH >= 4 */ |
| 269 |
# define umul_ppmm(xh, xl, a, b) \ |
| 270 |
__asm__ ("@ Inlined umul_ppmm\n" \ |
| 271 |
"umull %1, %0, %2, %3" \ |
| 272 |
: "=&r" ((xh)), \ |
| 273 |
"=r" ((xl)) \ |
| 274 |
: "r" ((USItype)(a)), \ |
| 275 |
"r" ((USItype)(b))) |
| 276 |
# endif /* __ARM_ARCH >= 4 */ |
| 277 |
# define UMUL_TIME 20 |
| 278 |
# define UDIV_TIME 100 |
| 279 |
# if (defined __ARM_ARCH && __ARM_ARCH >= 5) |
| 280 |
# define count_leading_zeros(count, x) \ |
| 281 |
__asm__ ("clz %0, %1" \ |
| 282 |
: "=r" ((count)) \ |
| 283 |
: "r" ((USItype)(x))) |
| 284 |
# endif /* __ARM_ARCH >= 5 */ |
| 285 |
#endif /* __arm__ */ |
| 286 |
|
| 287 |
/*************************************** |
| 288 |
********** ARM64 / Aarch64 ********** |
| 289 |
***************************************/ |
| 290 |
#if defined(__aarch64__) && W_TYPE_SIZE == 64 |
| 291 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 292 |
__asm__ ("adds %1, %4, %5\n" \ |
| 293 |
"adc %0, %2, %3\n" \ |
| 294 |
: "=r" ((sh)), \ |
| 295 |
"=&r" ((sl)) \ |
| 296 |
: "r" ((UDItype)(ah)), \ |
| 297 |
"r" ((UDItype)(bh)), \ |
| 298 |
"r" ((UDItype)(al)), \ |
| 299 |
"r" ((UDItype)(bl)) __CLOBBER_CC) |
| 300 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 301 |
__asm__ ("subs %1, %4, %5\n" \ |
| 302 |
"sbc %0, %2, %3\n" \ |
| 303 |
: "=r" ((sh)), \ |
| 304 |
"=&r" ((sl)) \ |
| 305 |
: "r" ((UDItype)(ah)), \ |
| 306 |
"r" ((UDItype)(bh)), \ |
| 307 |
"r" ((UDItype)(al)), \ |
| 308 |
"r" ((UDItype)(bl)) __CLOBBER_CC) |
| 309 |
# define umul_ppmm(ph, pl, m0, m1) \ |
| 310 |
do { \ |
| 311 |
UDItype __m0 = (m0), __m1 = (m1), __ph; \ |
| 312 |
(pl) = __m0 * __m1; \ |
| 313 |
__asm__ ("umulh %0,%1,%2" \ |
| 314 |
: "=r" (__ph) \ |
| 315 |
: "r" (__m0), \ |
| 316 |
"r" (__m1)); \ |
| 317 |
(ph) = __ph; \ |
| 318 |
} while (0) |
| 319 |
# define count_leading_zeros(count, x) \ |
| 320 |
do { \ |
| 321 |
UDItype __co; \ |
| 322 |
__asm__ ("clz %0, %1\n" \ |
| 323 |
: "=r" (__co) \ |
| 324 |
: "r" ((UDItype)(x))); \ |
| 325 |
(count) = __co; \ |
| 326 |
} while (0) |
| 327 |
#endif /* __aarch64__ */ |
| 328 |
|
| 329 |
/*************************************** |
| 330 |
************** CLIPPER ************** |
| 331 |
***************************************/ |
| 332 |
#if defined (__clipper__) && W_TYPE_SIZE == 32 |
| 333 |
# define umul_ppmm(w1, w0, u, v) \ |
| 334 |
({union {UDItype __ll; \ |
| 335 |
struct {USItype __l, __h;} __i; \ |
| 336 |
} __xx; \ |
| 337 |
__asm__ ("mulwux %2,%0" \ |
| 338 |
: "=r" (__xx.__ll) \ |
| 339 |
: "%0" ((USItype)(u)), \ |
| 340 |
"r" ((USItype)(v))); \ |
| 341 |
(w1) = __xx.__i.__h; (w0) = __xx.__i.__l;}) |
| 342 |
# define smul_ppmm(w1, w0, u, v) \ |
| 343 |
({union {DItype __ll; \ |
| 344 |
struct {SItype __l, __h;} __i; \ |
| 345 |
} __xx; \ |
| 346 |
__asm__ ("mulwx %2,%0" \ |
| 347 |
: "=r" (__xx.__ll) \ |
| 348 |
: "%0" ((SItype)(u)), \ |
| 349 |
"r" ((SItype)(v))); \ |
| 350 |
(w1) = __xx.__i.__h; (w0) = __xx.__i.__l;}) |
| 351 |
# define __umulsidi3(u, v) \ |
| 352 |
({UDItype __w; \ |
| 353 |
__asm__ ("mulwux %2,%0" \ |
| 354 |
: "=r" (__w) \ |
| 355 |
: "%0" ((USItype)(u)), \ |
| 356 |
"r" ((USItype)(v))); \ |
| 357 |
__w; }) |
| 358 |
#endif /* __clipper__ */ |
| 359 |
|
| 360 |
|
| 361 |
/*************************************** |
| 362 |
************** GMICRO *************** |
| 363 |
***************************************/ |
| 364 |
#if defined (__gmicro__) && W_TYPE_SIZE == 32 |
| 365 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 366 |
__asm__ ("add.w %5,%1\n" \ |
| 367 |
"addx %3,%0" \ |
| 368 |
: "=g" ((USItype)(sh)), \ |
| 369 |
"=&g" ((USItype)(sl)) \ |
| 370 |
: "%0" ((USItype)(ah)), \ |
| 371 |
"g" ((USItype)(bh)), \ |
| 372 |
"%1" ((USItype)(al)), \ |
| 373 |
"g" ((USItype)(bl))) |
| 374 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 375 |
__asm__ ("sub.w %5,%1\n" \ |
| 376 |
"subx %3,%0" \ |
| 377 |
: "=g" ((USItype)(sh)), \ |
| 378 |
"=&g" ((USItype)(sl)) \ |
| 379 |
: "0" ((USItype)(ah)), \ |
| 380 |
"g" ((USItype)(bh)), \ |
| 381 |
"1" ((USItype)(al)), \ |
| 382 |
"g" ((USItype)(bl))) |
| 383 |
# define umul_ppmm(ph, pl, m0, m1) \ |
| 384 |
__asm__ ("mulx %3,%0,%1" \ |
| 385 |
: "=g" ((USItype)(ph)), \ |
| 386 |
"=r" ((USItype)(pl)) \ |
| 387 |
: "%0" ((USItype)(m0)), \ |
| 388 |
"g" ((USItype)(m1))) |
| 389 |
# define udiv_qrnnd(q, r, nh, nl, d) \ |
| 390 |
__asm__ ("divx %4,%0,%1" \ |
| 391 |
: "=g" ((USItype)(q)), \ |
| 392 |
"=r" ((USItype)(r)) \ |
| 393 |
: "1" ((USItype)(nh)), \ |
| 394 |
"0" ((USItype)(nl)), \ |
| 395 |
"g" ((USItype)(d))) |
| 396 |
# define count_leading_zeros(count, x) \ |
| 397 |
__asm__ ("bsch/1 %1,%0" \ |
| 398 |
: "=g" (count) \ |
| 399 |
: "g" ((USItype)(x)), \ |
| 400 |
"0" ((USItype)0)) |
| 401 |
#endif |
| 402 |
|
| 403 |
|
| 404 |
/*************************************** |
| 405 |
************** HPPA ***************** |
| 406 |
***************************************/ |
| 407 |
#if defined (__hppa) && W_TYPE_SIZE == 32 |
| 408 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 409 |
__asm__ ("add %4,%5,%1\n\t" \ |
| 410 |
"addc %2,%3,%0" \ |
| 411 |
: "=r" ((USItype)(sh)), \ |
| 412 |
"=&r" ((USItype)(sl)) \ |
| 413 |
: "%rM" ((USItype)(ah)), \ |
| 414 |
"rM" ((USItype)(bh)), \ |
| 415 |
"%rM" ((USItype)(al)), \ |
| 416 |
"rM" ((USItype)(bl)) __CLOBBER_CC) |
| 417 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 418 |
__asm__ ("sub %4,%5,%1\n\t" \ |
| 419 |
"subb %2,%3,%0" \ |
| 420 |
: "=r" ((USItype)(sh)), \ |
| 421 |
"=&r" ((USItype)(sl)) \ |
| 422 |
: "rM" ((USItype)(ah)), \ |
| 423 |
"rM" ((USItype)(bh)), \ |
| 424 |
"rM" ((USItype)(al)), \ |
| 425 |
"rM" ((USItype)(bl)) __CLOBBER_CC) |
| 426 |
# if defined (_PA_RISC1_1) |
| 427 |
# define umul_ppmm(wh, wl, u, v) \ |
| 428 |
do { \ |
| 429 |
union {UDItype __ll; \ |
| 430 |
struct {USItype __h, __l;} __i; \ |
| 431 |
} __xx; \ |
| 432 |
__asm__ (" xmpyu %1,%2,%0" \ |
| 433 |
: "=*f" (__xx.__ll) \ |
| 434 |
: "*f" ((USItype)(u)), \ |
| 435 |
"*f" ((USItype)(v))); \ |
| 436 |
(wh) = __xx.__i.__h; \ |
| 437 |
(wl) = __xx.__i.__l; \ |
| 438 |
} while (0) |
| 439 |
# define UMUL_TIME 8 |
| 440 |
# define UDIV_TIME 60 |
| 441 |
# else |
| 442 |
# define UMUL_TIME 40 |
| 443 |
# define UDIV_TIME 80 |
| 444 |
# endif |
| 445 |
# if !defined(LONGLONG_STANDALONE) && !defined(ASM_DISABLED) |
| 446 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 447 |
do { USItype __r; \ |
| 448 |
(q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \ |
| 449 |
(r) = __r; \ |
| 450 |
} while (0) |
| 451 |
extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype); |
| 452 |
# endif /* !LONGLONG_STANDALONE && !ASM_DISABLED */ |
| 453 |
# define count_leading_zeros(count, x) \ |
| 454 |
do { \ |
| 455 |
USItype __tmp; \ |
| 456 |
__asm__ ( \ |
| 457 |
" ldi 1,%0 \n" \ |
| 458 |
" extru,= %1,15,16,%%r0 ; Bits 31..16 zero? \n" \ |
| 459 |
" extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n" \ |
| 460 |
" ldo 16(%0),%0 ; Yes. Perform add. \n" \ |
| 461 |
" extru,= %1,23,8,%%r0 ; Bits 15..8 zero? \n" \ |
| 462 |
" extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n" \ |
| 463 |
" ldo 8(%0),%0 ; Yes. Perform add. \n" \ |
| 464 |
" extru,= %1,27,4,%%r0 ; Bits 7..4 zero? \n" \ |
| 465 |
" extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n" \ |
| 466 |
" ldo 4(%0),%0 ; Yes. Perform add. \n" \ |
| 467 |
" extru,= %1,29,2,%%r0 ; Bits 3..2 zero? \n" \ |
| 468 |
" extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n" \ |
| 469 |
" ldo 2(%0),%0 ; Yes. Perform add. \n" \ |
| 470 |
" extru %1,30,1,%1 ; Extract bit 1. \n" \ |
| 471 |
" sub %0,%1,%0 ; Subtract it. " \ |
| 472 |
: "=r" (count), "=r" (__tmp) : "1" (x)); \ |
| 473 |
} while (0) |
| 474 |
#endif /* hppa */ |
| 475 |
|
| 476 |
|
| 477 |
/*************************************** |
| 478 |
************** I370 ***************** |
| 479 |
***************************************/ |
| 480 |
#if (defined (__i370__) || defined (__mvs__)) && W_TYPE_SIZE == 32 |
| 481 |
# define umul_ppmm(xh, xl, m0, m1) \ |
| 482 |
do { \ |
| 483 |
union {UDItype __ll; \ |
| 484 |
struct {USItype __h, __l;} __i; \ |
| 485 |
} __xx; \ |
| 486 |
USItype __m0 = (m0), __m1 = (m1); \ |
| 487 |
__asm__ ("mr %0,%3" \ |
| 488 |
: "=r" (__xx.__i.__h), \ |
| 489 |
"=r" (__xx.__i.__l) \ |
| 490 |
: "%1" (__m0), \ |
| 491 |
"r" (__m1)); \ |
| 492 |
(xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \ |
| 493 |
(xh) += ((((SItype) __m0 >> 31) & __m1) \ |
| 494 |
+ (((SItype) __m1 >> 31) & __m0)); \ |
| 495 |
} while (0) |
| 496 |
# define smul_ppmm(xh, xl, m0, m1) \ |
| 497 |
do { \ |
| 498 |
union {DItype __ll; \ |
| 499 |
struct {USItype __h, __l;} __i; \ |
| 500 |
} __xx; \ |
| 501 |
__asm__ ("mr %0,%3" \ |
| 502 |
: "=r" (__xx.__i.__h), \ |
| 503 |
"=r" (__xx.__i.__l) \ |
| 504 |
: "%1" (m0), \ |
| 505 |
"r" (m1)); \ |
| 506 |
(xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \ |
| 507 |
} while (0) |
| 508 |
# define sdiv_qrnnd(q, r, n1, n0, d) \ |
| 509 |
do { \ |
| 510 |
union {DItype __ll; \ |
| 511 |
struct {USItype __h, __l;} __i; \ |
| 512 |
} __xx; \ |
| 513 |
__xx.__i.__h = (n1); __xx.__i.__l = (n0); \ |
| 514 |
__asm__ ("dr %0,%2" \ |
| 515 |
: "=r" (__xx.__ll) \ |
| 516 |
: "0" (__xx.__ll), "r" (d)); \ |
| 517 |
(q) = __xx.__i.__l; (r) = __xx.__i.__h; \ |
| 518 |
} while (0) |
| 519 |
#endif |
| 520 |
|
| 521 |
|
| 522 |
/*************************************** |
| 523 |
************** I386 ***************** |
| 524 |
***************************************/ |
| 525 |
#if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32 |
| 526 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 527 |
__asm__ ("addl %5,%1\n" \ |
| 528 |
"adcl %3,%0" \ |
| 529 |
: "=r" ((sh)), \ |
| 530 |
"=&r" ((sl)) \ |
| 531 |
: "%0" ((USItype)(ah)), \ |
| 532 |
"g" ((USItype)(bh)), \ |
| 533 |
"%1" ((USItype)(al)), \ |
| 534 |
"g" ((USItype)(bl)) \ |
| 535 |
__CLOBBER_CC) |
| 536 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 537 |
__asm__ ("subl %5,%1\n" \ |
| 538 |
"sbbl %3,%0" \ |
| 539 |
: "=r" ((sh)), \ |
| 540 |
"=&r" ((sl)) \ |
| 541 |
: "0" ((USItype)(ah)), \ |
| 542 |
"g" ((USItype)(bh)), \ |
| 543 |
"1" ((USItype)(al)), \ |
| 544 |
"g" ((USItype)(bl)) \ |
| 545 |
__CLOBBER_CC) |
| 546 |
# define umul_ppmm(w1, w0, u, v) \ |
| 547 |
__asm__ ("mull %3" \ |
| 548 |
: "=a" ((w0)), \ |
| 549 |
"=d" ((w1)) \ |
| 550 |
: "%0" ((USItype)(u)), \ |
| 551 |
"rm" ((USItype)(v)) \ |
| 552 |
__CLOBBER_CC) |
| 553 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 554 |
__asm__ ("divl %4" \ |
| 555 |
: "=a" ((q)), \ |
| 556 |
"=d" ((r)) \ |
| 557 |
: "0" ((USItype)(n0)), \ |
| 558 |
"1" ((USItype)(n1)), \ |
| 559 |
"rm" ((USItype)(d)) \ |
| 560 |
__CLOBBER_CC) |
| 561 |
# define count_leading_zeros(count, x) \ |
| 562 |
do { \ |
| 563 |
USItype __cbtmp; \ |
| 564 |
__asm__ ("bsrl %1,%0" \ |
| 565 |
: "=r" (__cbtmp) : "rm" ((USItype)(x)) \ |
| 566 |
__CLOBBER_CC); \ |
| 567 |
(count) = __cbtmp ^ 31; \ |
| 568 |
} while (0) |
| 569 |
# define count_trailing_zeros(count, x) \ |
| 570 |
__asm__ ("rep;bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)) __CLOBBER_CC) |
| 571 |
# ifndef UMUL_TIME |
| 572 |
# define UMUL_TIME 40 |
| 573 |
# endif |
| 574 |
# ifndef UDIV_TIME |
| 575 |
# define UDIV_TIME 40 |
| 576 |
# endif |
| 577 |
#endif /* 80x86 */ |
| 578 |
|
| 579 |
/*************************************** |
| 580 |
*********** AMD64 / x86-64 ************ |
| 581 |
***************************************/ |
| 582 |
#if defined(__x86_64) && W_TYPE_SIZE == 64 |
| 583 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 584 |
__asm__ ("addq %5,%1\n" \ |
| 585 |
"adcq %3,%0" \ |
| 586 |
: "=r" ((sh)), \ |
| 587 |
"=&r" ((sl)) \ |
| 588 |
: "0" ((UDItype)(ah)), \ |
| 589 |
"g" ((UDItype)(bh)), \ |
| 590 |
"1" ((UDItype)(al)), \ |
| 591 |
"g" ((UDItype)(bl)) \ |
| 592 |
__CLOBBER_CC) |
| 593 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 594 |
__asm__ ("subq %5,%1\n" \ |
| 595 |
"sbbq %3,%0" \ |
| 596 |
: "=r" ((sh)), \ |
| 597 |
"=&r" ((sl)) \ |
| 598 |
: "0" ((UDItype)(ah)), \ |
| 599 |
"g" ((UDItype)(bh)), \ |
| 600 |
"1" ((UDItype)(al)), \ |
| 601 |
"g" ((UDItype)(bl)) \ |
| 602 |
__CLOBBER_CC) |
| 603 |
# define umul_ppmm(w1, w0, u, v) \ |
| 604 |
__asm__ ("mulq %3" \ |
| 605 |
: "=a" ((w0)), \ |
| 606 |
"=d" ((w1)) \ |
| 607 |
: "0" ((UDItype)(u)), \ |
| 608 |
"rm" ((UDItype)(v)) \ |
| 609 |
__CLOBBER_CC) |
| 610 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 611 |
__asm__ ("divq %4" \ |
| 612 |
: "=a" ((q)), \ |
| 613 |
"=d" ((r)) \ |
| 614 |
: "0" ((UDItype)(n0)), \ |
| 615 |
"1" ((UDItype)(n1)), \ |
| 616 |
"rm" ((UDItype)(d)) \ |
| 617 |
__CLOBBER_CC) |
| 618 |
# define count_leading_zeros(count, x) \ |
| 619 |
do { \ |
| 620 |
UDItype __cbtmp; \ |
| 621 |
__asm__ ("bsrq %1,%0" \ |
| 622 |
: "=r" (__cbtmp) : "rm" ((UDItype)(x)) \ |
| 623 |
__CLOBBER_CC); \ |
| 624 |
(count) = __cbtmp ^ 63; \ |
| 625 |
} while (0) |
| 626 |
# define count_trailing_zeros(count, x) \ |
| 627 |
do { \ |
| 628 |
UDItype __cbtmp; \ |
| 629 |
__asm__ ("rep;bsfq %1,%0" \ |
| 630 |
: "=r" (__cbtmp) : "rm" ((UDItype)(x)) \ |
| 631 |
__CLOBBER_CC); \ |
| 632 |
(count) = __cbtmp; \ |
| 633 |
} while (0) |
| 634 |
# ifndef UMUL_TIME |
| 635 |
# define UMUL_TIME 40 |
| 636 |
# endif |
| 637 |
# ifndef UDIV_TIME |
| 638 |
# define UDIV_TIME 40 |
| 639 |
# endif |
| 640 |
#endif /* __x86_64 */ |
| 641 |
|
| 642 |
|
| 643 |
/*************************************** |
| 644 |
************** I860 ***************** |
| 645 |
***************************************/ |
| 646 |
#if defined (__i860__) && W_TYPE_SIZE == 32 |
| 647 |
# define rshift_rhlc(r,h,l,c) \ |
| 648 |
__asm__ ("shr %3,r0,r0\n" \ |
| 649 |
"shrd %1,%2,%0" \ |
| 650 |
"=r" (r) : "r" (h), "r" (l), "rn" (c)) |
| 651 |
#endif /* i860 */ |
| 652 |
|
| 653 |
/*************************************** |
| 654 |
************** I960 ***************** |
| 655 |
***************************************/ |
| 656 |
#if defined (__i960__) && W_TYPE_SIZE == 32 |
| 657 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 658 |
__asm__ ("cmpo 1,0\n" \ |
| 659 |
"addc %5,%4,%1\n" \ |
| 660 |
"addc %3,%2,%0" \ |
| 661 |
: "=r" ((USItype)(sh)), \ |
| 662 |
"=&r" ((USItype)(sl)) \ |
| 663 |
: "%dI" ((USItype)(ah)), \ |
| 664 |
"dI" ((USItype)(bh)), \ |
| 665 |
"%dI" ((USItype)(al)), \ |
| 666 |
"dI" ((USItype)(bl))) |
| 667 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 668 |
__asm__ ("cmpo 0,0\n" \ |
| 669 |
"subc %5,%4,%1\n" \ |
| 670 |
"subc %3,%2,%0" \ |
| 671 |
: "=r" ((USItype)(sh)), \ |
| 672 |
"=&r" ((USItype)(sl)) \ |
| 673 |
: "dI" ((USItype)(ah)), \ |
| 674 |
"dI" ((USItype)(bh)), \ |
| 675 |
"dI" ((USItype)(al)), \ |
| 676 |
"dI" ((USItype)(bl))) |
| 677 |
# define umul_ppmm(w1, w0, u, v) \ |
| 678 |
({union {UDItype __ll; \ |
| 679 |
struct {USItype __l, __h;} __i; \ |
| 680 |
} __xx; \ |
| 681 |
__asm__ ("emul %2,%1,%0" \ |
| 682 |
: "=d" (__xx.__ll) \ |
| 683 |
: "%dI" ((USItype)(u)), \ |
| 684 |
"dI" ((USItype)(v))); \ |
| 685 |
(w1) = __xx.__i.__h; (w0) = __xx.__i.__l;}) |
| 686 |
# define __umulsidi3(u, v) \ |
| 687 |
({UDItype __w; \ |
| 688 |
__asm__ ("emul %2,%1,%0" \ |
| 689 |
: "=d" (__w) \ |
| 690 |
: "%dI" ((USItype)(u)), \ |
| 691 |
"dI" ((USItype)(v))); \ |
| 692 |
__w; }) |
| 693 |
# define udiv_qrnnd(q, r, nh, nl, d) \ |
| 694 |
do { \ |
| 695 |
union {UDItype __ll; \ |
| 696 |
struct {USItype __l, __h;} __i; \ |
| 697 |
} __nn; \ |
| 698 |
__nn.__i.__h = (nh); __nn.__i.__l = (nl); \ |
| 699 |
__asm__ ("ediv %d,%n,%0" \ |
| 700 |
: "=d" (__rq.__ll) \ |
| 701 |
: "dI" (__nn.__ll), \ |
| 702 |
"dI" ((USItype)(d))); \ |
| 703 |
(r) = __rq.__i.__l; (q) = __rq.__i.__h; \ |
| 704 |
} while (0) |
| 705 |
# define count_leading_zeros(count, x) \ |
| 706 |
do { \ |
| 707 |
USItype __cbtmp; \ |
| 708 |
__asm__ ("scanbit %1,%0" \ |
| 709 |
: "=r" (__cbtmp) \ |
| 710 |
: "r" ((USItype)(x))); \ |
| 711 |
(count) = __cbtmp ^ 31; \ |
| 712 |
} while (0) |
| 713 |
# define COUNT_LEADING_ZEROS_0 (-32) /* sic */ |
| 714 |
# if defined (__i960mx) /* what is the proper symbol to test??? */ |
| 715 |
# define rshift_rhlc(r,h,l,c) \ |
| 716 |
do { \ |
| 717 |
union {UDItype __ll; \ |
| 718 |
struct {USItype __l, __h;} __i; \ |
| 719 |
} __nn; \ |
| 720 |
__nn.__i.__h = (h); __nn.__i.__l = (l); \ |
| 721 |
__asm__ ("shre %2,%1,%0" \ |
| 722 |
: "=d" (r) : "dI" (__nn.__ll), "dI" (c)); \ |
| 723 |
} |
| 724 |
# endif /* i960mx */ |
| 725 |
#endif /* i960 */ |
| 726 |
|
| 727 |
|
| 728 |
/*************************************** |
| 729 |
************** 68000 **************** |
| 730 |
***************************************/ |
| 731 |
#if (defined (__mc68000__) || defined (__mc68020__) \ |
| 732 |
|| defined (__NeXT__) || defined(mc68020)) && W_TYPE_SIZE == 32 |
| 733 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 734 |
__asm__ ("add%.l %5,%1\n" \ |
| 735 |
"addx%.l %3,%0" \ |
| 736 |
: "=d" ((USItype)(sh)), \ |
| 737 |
"=&d" ((USItype)(sl)) \ |
| 738 |
: "%0" ((USItype)(ah)), \ |
| 739 |
"d" ((USItype)(bh)), \ |
| 740 |
"%1" ((USItype)(al)), \ |
| 741 |
"g" ((USItype)(bl))) |
| 742 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 743 |
__asm__ ("sub%.l %5,%1\n" \ |
| 744 |
"subx%.l %3,%0" \ |
| 745 |
: "=d" ((USItype)(sh)), \ |
| 746 |
"=&d" ((USItype)(sl)) \ |
| 747 |
: "0" ((USItype)(ah)), \ |
| 748 |
"d" ((USItype)(bh)), \ |
| 749 |
"1" ((USItype)(al)), \ |
| 750 |
"g" ((USItype)(bl))) |
| 751 |
# if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) |
| 752 |
# define umul_ppmm(w1, w0, u, v) \ |
| 753 |
__asm__ ("mulu%.l %3,%1:%0" \ |
| 754 |
: "=d" ((USItype)(w0)), \ |
| 755 |
"=d" ((USItype)(w1)) \ |
| 756 |
: "%0" ((USItype)(u)), \ |
| 757 |
"dmi" ((USItype)(v))) |
| 758 |
# define UMUL_TIME 45 |
| 759 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 760 |
__asm__ ("divu%.l %4,%1:%0" \ |
| 761 |
: "=d" ((USItype)(q)), \ |
| 762 |
"=d" ((USItype)(r)) \ |
| 763 |
: "0" ((USItype)(n0)), \ |
| 764 |
"1" ((USItype)(n1)), \ |
| 765 |
"dmi" ((USItype)(d))) |
| 766 |
# define UDIV_TIME 90 |
| 767 |
# define sdiv_qrnnd(q, r, n1, n0, d) \ |
| 768 |
__asm__ ("divs%.l %4,%1:%0" \ |
| 769 |
: "=d" ((USItype)(q)), \ |
| 770 |
"=d" ((USItype)(r)) \ |
| 771 |
: "0" ((USItype)(n0)), \ |
| 772 |
"1" ((USItype)(n1)), \ |
| 773 |
"dmi" ((USItype)(d))) |
| 774 |
# define count_leading_zeros(count, x) \ |
| 775 |
__asm__ ("bfffo %1{%b2:%b2},%0" \ |
| 776 |
: "=d" ((USItype)(count)) \ |
| 777 |
: "od" ((USItype)(x)), "n" (0)) |
| 778 |
# define COUNT_LEADING_ZEROS_0 32 |
| 779 |
# else /* not mc68020 */ |
| 780 |
# define umul_ppmm(xh, xl, a, b) \ |
| 781 |
do { USItype __umul_tmp1, __umul_tmp2; \ |
| 782 |
__asm__ ("| Inlined umul_ppmm \n" \ |
| 783 |
" move%.l %5,%3 \n" \ |
| 784 |
" move%.l %2,%0 \n" \ |
| 785 |
" move%.w %3,%1 \n" \ |
| 786 |
" swap %3 \n" \ |
| 787 |
" swap %0 \n" \ |
| 788 |
" mulu %2,%1 \n" \ |
| 789 |
" mulu %3,%0 \n" \ |
| 790 |
" mulu %2,%3 \n" \ |
| 791 |
" swap %2 \n" \ |
| 792 |
" mulu %5,%2 \n" \ |
| 793 |
" add%.l %3,%2 \n" \ |
| 794 |
" jcc 1f \n" \ |
| 795 |
" add%.l %#0x10000,%0 \n" \ |
| 796 |
"1: move%.l %2,%3 \n" \ |
| 797 |
" clr%.w %2 \n" \ |
| 798 |
" swap %2 \n" \ |
| 799 |
" swap %3 \n" \ |
| 800 |
" clr%.w %3 \n" \ |
| 801 |
" add%.l %3,%1 \n" \ |
| 802 |
" addx%.l %2,%0 \n" \ |
| 803 |
" | End inlined umul_ppmm" \ |
| 804 |
: "=&d" ((USItype)(xh)), "=&d" ((USItype)(xl)), \ |
| 805 |
"=d" (__umul_tmp1), "=&d" (__umul_tmp2) \ |
| 806 |
: "%2" ((USItype)(a)), "d" ((USItype)(b))); \ |
| 807 |
} while (0) |
| 808 |
# define UMUL_TIME 100 |
| 809 |
# define UDIV_TIME 400 |
| 810 |
# endif /* not mc68020 */ |
| 811 |
#endif /* mc68000 */ |
| 812 |
|
| 813 |
|
| 814 |
/*************************************** |
| 815 |
************** 88000 **************** |
| 816 |
***************************************/ |
| 817 |
#if defined (__m88000__) && W_TYPE_SIZE == 32 |
| 818 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 819 |
__asm__ ("addu.co %1,%r4,%r5\n" \ |
| 820 |
"addu.ci %0,%r2,%r3" \ |
| 821 |
: "=r" ((USItype)(sh)), \ |
| 822 |
"=&r" ((USItype)(sl)) \ |
| 823 |
: "%rJ" ((USItype)(ah)), \ |
| 824 |
"rJ" ((USItype)(bh)), \ |
| 825 |
"%rJ" ((USItype)(al)), \ |
| 826 |
"rJ" ((USItype)(bl))) |
| 827 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 828 |
__asm__ ("subu.co %1,%r4,%r5\n" \ |
| 829 |
"subu.ci %0,%r2,%r3" \ |
| 830 |
: "=r" ((USItype)(sh)), \ |
| 831 |
"=&r" ((USItype)(sl)) \ |
| 832 |
: "rJ" ((USItype)(ah)), \ |
| 833 |
"rJ" ((USItype)(bh)), \ |
| 834 |
"rJ" ((USItype)(al)), \ |
| 835 |
"rJ" ((USItype)(bl))) |
| 836 |
# define count_leading_zeros(count, x) \ |
| 837 |
do { \ |
| 838 |
USItype __cbtmp; \ |
| 839 |
__asm__ ("ff1 %0,%1" \ |
| 840 |
: "=r" (__cbtmp) \ |
| 841 |
: "r" ((USItype)(x))); \ |
| 842 |
(count) = __cbtmp ^ 31; \ |
| 843 |
} while (0) |
| 844 |
# define COUNT_LEADING_ZEROS_0 63 /* sic */ |
| 845 |
# if defined (__m88110__) |
| 846 |
# define umul_ppmm(wh, wl, u, v) \ |
| 847 |
do { \ |
| 848 |
union {UDItype __ll; \ |
| 849 |
struct {USItype __h, __l;} __i; \ |
| 850 |
} __x; \ |
| 851 |
__asm__ ("mulu.d %0,%1,%2" : "=r" (__x.__ll) : "r" (u), "r" (v)); \ |
| 852 |
(wh) = __x.__i.__h; \ |
| 853 |
(wl) = __x.__i.__l; \ |
| 854 |
} while (0) |
| 855 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 856 |
({union {UDItype __ll; \ |
| 857 |
struct {USItype __h, __l;} __i; \ |
| 858 |
} __x, __q; \ |
| 859 |
__x.__i.__h = (n1); __x.__i.__l = (n0); \ |
| 860 |
__asm__ ("divu.d %0,%1,%2" \ |
| 861 |
: "=r" (__q.__ll) : "r" (__x.__ll), "r" (d)); \ |
| 862 |
(r) = (n0) - __q.__l * (d); (q) = __q.__l; }) |
| 863 |
# define UMUL_TIME 5 |
| 864 |
# define UDIV_TIME 25 |
| 865 |
# else |
| 866 |
# define UMUL_TIME 17 |
| 867 |
# define UDIV_TIME 150 |
| 868 |
# endif /* __m88110__ */ |
| 869 |
#endif /* __m88000__ */ |
| 870 |
|
| 871 |
/*************************************** |
| 872 |
************** MIPS ***************** |
| 873 |
***************************************/ |
| 874 |
#if defined (__mips__) && W_TYPE_SIZE == 32 |
| 875 |
# if defined (__clang__) || (__GNUC__ >= 5) || (__GNUC__ == 4 && \ |
| 876 |
__GNUC_MINOR__ >= 4) |
| 877 |
# define umul_ppmm(w1, w0, u, v) \ |
| 878 |
do { \ |
| 879 |
UDItype __r; \ |
| 880 |
__r = (UDItype)(u) * (v); \ |
| 881 |
(w1) = __r >> 32; \ |
| 882 |
(w0) = (USItype) __r; \ |
| 883 |
} while (0) |
| 884 |
# elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7 |
| 885 |
# define umul_ppmm(w1, w0, u, v) \ |
| 886 |
__asm__ ("multu %2,%3" \ |
| 887 |
: "=l" ((USItype)(w0)), \ |
| 888 |
"=h" ((USItype)(w1)) \ |
| 889 |
: "d" ((USItype)(u)), \ |
| 890 |
"d" ((USItype)(v))) |
| 891 |
# else |
| 892 |
# define umul_ppmm(w1, w0, u, v) \ |
| 893 |
__asm__ ("multu %2,%3 \n" \ |
| 894 |
"mflo %0 \n" \ |
| 895 |
"mfhi %1" \ |
| 896 |
: "=d" ((USItype)(w0)), \ |
| 897 |
"=d" ((USItype)(w1)) \ |
| 898 |
: "d" ((USItype)(u)), \ |
| 899 |
"d" ((USItype)(v))) |
| 900 |
# endif |
| 901 |
# define UMUL_TIME 10 |
| 902 |
# define UDIV_TIME 100 |
| 903 |
#endif /* __mips__ */ |
| 904 |
|
| 905 |
/*************************************** |
| 906 |
************** MIPS/64 ************** |
| 907 |
***************************************/ |
| 908 |
#if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64 |
| 909 |
# if defined (__clang__) || (__GNUC__ >= 5) || (__GNUC__ == 4 && \ |
| 910 |
__GNUC_MINOR__ >= 4) |
| 911 |
typedef unsigned int UTItype __attribute__ ((mode (TI))); |
| 912 |
# define umul_ppmm(w1, w0, u, v) \ |
| 913 |
do { \ |
| 914 |
UTItype __r; \ |
| 915 |
__r = (UTItype)(u) * (v); \ |
| 916 |
(w1) = __r >> 64; \ |
| 917 |
(w0) = (UDItype) __r; \ |
| 918 |
} while (0) |
| 919 |
# elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7 |
| 920 |
# define umul_ppmm(w1, w0, u, v) \ |
| 921 |
__asm__ ("dmultu %2,%3" \ |
| 922 |
: "=l" ((UDItype)(w0)), \ |
| 923 |
"=h" ((UDItype)(w1)) \ |
| 924 |
: "d" ((UDItype)(u)), \ |
| 925 |
"d" ((UDItype)(v))) |
| 926 |
# else |
| 927 |
# define umul_ppmm(w1, w0, u, v) \ |
| 928 |
__asm__ ("dmultu %2,%3 \n" \ |
| 929 |
"mflo %0 \n" \ |
| 930 |
"mfhi %1" \ |
| 931 |
: "=d" ((UDItype)(w0)), \ |
| 932 |
"=d" ((UDItype)(w1)) \ |
| 933 |
: "d" ((UDItype)(u)), \ |
| 934 |
"d" ((UDItype)(v))) |
| 935 |
# endif |
| 936 |
# define UMUL_TIME 20 |
| 937 |
# define UDIV_TIME 140 |
| 938 |
#endif /* __mips__ */ |
| 939 |
|
| 940 |
|
| 941 |
/*************************************** |
| 942 |
************** 32000 **************** |
| 943 |
***************************************/ |
| 944 |
#if defined (__ns32000__) && W_TYPE_SIZE == 32 |
| 945 |
# define umul_ppmm(w1, w0, u, v) \ |
| 946 |
({union {UDItype __ll; \ |
| 947 |
struct {USItype __l, __h;} __i; \ |
| 948 |
} __xx; \ |
| 949 |
__asm__ ("meid %2,%0" \ |
| 950 |
: "=g" (__xx.__ll) \ |
| 951 |
: "%0" ((USItype)(u)), \ |
| 952 |
"g" ((USItype)(v))); \ |
| 953 |
(w1) = __xx.__i.__h; (w0) = __xx.__i.__l;}) |
| 954 |
# define __umulsidi3(u, v) \ |
| 955 |
({UDItype __w; \ |
| 956 |
__asm__ ("meid %2,%0" \ |
| 957 |
: "=g" (__w) \ |
| 958 |
: "%0" ((USItype)(u)), \ |
| 959 |
"g" ((USItype)(v))); \ |
| 960 |
__w; }) |
| 961 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 962 |
({union {UDItype __ll; \ |
| 963 |
struct {USItype __l, __h;} __i; \ |
| 964 |
} __xx; \ |
| 965 |
__xx.__i.__h = (n1); __xx.__i.__l = (n0); \ |
| 966 |
__asm__ ("deid %2,%0" \ |
| 967 |
: "=g" (__xx.__ll) \ |
| 968 |
: "0" (__xx.__ll), \ |
| 969 |
"g" ((USItype)(d))); \ |
| 970 |
(r) = __xx.__i.__l; (q) = __xx.__i.__h; }) |
| 971 |
# define count_trailing_zeros(count,x) \ |
| 972 |
do { |
| 973 |
__asm__ ("ffsd %2,%0" \ |
| 974 |
: "=r" ((USItype) (count)) \ |
| 975 |
: "0" ((USItype) 0), \ |
| 976 |
"r" ((USItype) (x))); \ |
| 977 |
} while (0) |
| 978 |
#endif /* __ns32000__ */ |
| 979 |
|
| 980 |
|
| 981 |
/*************************************** |
| 982 |
************** PPC ****************** |
| 983 |
***************************************/ |
| 984 |
/* Powerpc 32 bit support taken from GCC longlong.h. */ |
| 985 |
#if (defined (_ARCH_PPC) || defined (__powerpc__)) && W_TYPE_SIZE == 32 |
| 986 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 987 |
do { \ |
| 988 |
if (__builtin_constant_p (bh) && (bh) == 0) \ |
| 989 |
__asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2" \ |
| 990 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl) \ |
| 991 |
__CLOBBER_CC); \ |
| 992 |
else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ |
| 993 |
__asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2" \ |
| 994 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl) \ |
| 995 |
__CLOBBER_CC); \ |
| 996 |
else \ |
| 997 |
__asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3" \ |
| 998 |
: "=r" (sh), "=&r" (sl) \ |
| 999 |
: "%r" (ah), "r" (bh), "%r" (al), "rI" (bl) \ |
| 1000 |
__CLOBBER_CC); \ |
| 1001 |
} while (0) |
| 1002 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1003 |
do { \ |
| 1004 |
if (__builtin_constant_p (ah) && (ah) == 0) \ |
| 1005 |
__asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2" \ |
| 1006 |
: "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl) \ |
| 1007 |
__CLOBBER_CC); \ |
| 1008 |
else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \ |
| 1009 |
__asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2" \ |
| 1010 |
: "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl) \ |
| 1011 |
__CLOBBER_CC); \ |
| 1012 |
else if (__builtin_constant_p (bh) && (bh) == 0) \ |
| 1013 |
__asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2" \ |
| 1014 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl) \ |
| 1015 |
__CLOBBER_CC); \ |
| 1016 |
else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ |
| 1017 |
__asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2" \ |
| 1018 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl) \ |
| 1019 |
__CLOBBER_CC); \ |
| 1020 |
else \ |
| 1021 |
__asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2" \ |
| 1022 |
: "=r" (sh), "=&r" (sl) \ |
| 1023 |
: "r" (ah), "r" (bh), "rI" (al), "r" (bl) \ |
| 1024 |
__CLOBBER_CC); \ |
| 1025 |
} while (0) |
| 1026 |
# define count_leading_zeros(count, x) \ |
| 1027 |
__asm__ ("cntlzw %0,%1" : "=r" (count) : "r" (x)) |
| 1028 |
# define COUNT_LEADING_ZEROS_0 32 |
| 1029 |
# define umul_ppmm(ph, pl, m0, m1) \ |
| 1030 |
do { \ |
| 1031 |
USItype __m0 = (m0), __m1 = (m1); \ |
| 1032 |
__asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ |
| 1033 |
(pl) = __m0 * __m1; \ |
| 1034 |
} while (0) |
| 1035 |
# define UMUL_TIME 15 |
| 1036 |
# define smul_ppmm(ph, pl, m0, m1) \ |
| 1037 |
do { \ |
| 1038 |
SItype __m0 = (m0), __m1 = (m1); \ |
| 1039 |
__asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ |
| 1040 |
(pl) = __m0 * __m1; \ |
| 1041 |
} while (0) |
| 1042 |
# define SMUL_TIME 14 |
| 1043 |
# define UDIV_TIME 120 |
| 1044 |
#endif /* 32-bit POWER architecture variants. */ |
| 1045 |
|
| 1046 |
/* Powerpc 64 bit support taken from GCC longlong.h. */ |
| 1047 |
/* We should test _IBMR2 here when we add assembly support for the system |
| 1048 |
vendor compilers. */ |
| 1049 |
#if (defined (_ARCH_PPC64) || defined (__powerpc64__)) && W_TYPE_SIZE == 64 |
| 1050 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1051 |
do { \ |
| 1052 |
if (__builtin_constant_p (bh) && (bh) == 0) \ |
| 1053 |
__asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2" \ |
| 1054 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl) \ |
| 1055 |
__CLOBBER_CC); \ |
| 1056 |
else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \ |
| 1057 |
__asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2" \ |
| 1058 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl) \ |
| 1059 |
__CLOBBER_CC); \ |
| 1060 |
else \ |
| 1061 |
__asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3" \ |
| 1062 |
: "=r" (sh), "=&r" (sl) \ |
| 1063 |
: "%r" (ah), "r" (bh), "%r" (al), "rI" (bl) \ |
| 1064 |
__CLOBBER_CC); \ |
| 1065 |
} while (0) |
| 1066 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1067 |
do { \ |
| 1068 |
if (__builtin_constant_p (ah) && (ah) == 0) \ |
| 1069 |
__asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2" \ |
| 1070 |
: "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl) \ |
| 1071 |
__CLOBBER_CC); \ |
| 1072 |
else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \ |
| 1073 |
__asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2" \ |
| 1074 |
: "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl) \ |
| 1075 |
__CLOBBER_CC); \ |
| 1076 |
else if (__builtin_constant_p (bh) && (bh) == 0) \ |
| 1077 |
__asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2" \ |
| 1078 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl) \ |
| 1079 |
__CLOBBER_CC); \ |
| 1080 |
else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \ |
| 1081 |
__asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2" \ |
| 1082 |
: "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl) \ |
| 1083 |
__CLOBBER_CC); \ |
| 1084 |
else \ |
| 1085 |
__asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2" \ |
| 1086 |
: "=r" (sh), "=&r" (sl) \ |
| 1087 |
: "r" (ah), "r" (bh), "rI" (al), "r" (bl) \ |
| 1088 |
__CLOBBER_CC); \ |
| 1089 |
} while (0) |
| 1090 |
# define count_leading_zeros(count, x) \ |
| 1091 |
__asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x)) |
| 1092 |
# define COUNT_LEADING_ZEROS_0 64 |
| 1093 |
# define umul_ppmm(ph, pl, m0, m1) \ |
| 1094 |
do { \ |
| 1095 |
UDItype __m0 = (m0), __m1 = (m1); \ |
| 1096 |
__asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ |
| 1097 |
(pl) = __m0 * __m1; \ |
| 1098 |
} while (0) |
| 1099 |
# define UMUL_TIME 15 |
| 1100 |
# define smul_ppmm(ph, pl, m0, m1) \ |
| 1101 |
do { \ |
| 1102 |
DItype __m0 = (m0), __m1 = (m1); \ |
| 1103 |
__asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ |
| 1104 |
(pl) = __m0 * __m1; \ |
| 1105 |
} while (0) |
| 1106 |
# define SMUL_TIME 14 /* ??? */ |
| 1107 |
# define UDIV_TIME 120 /* ??? */ |
| 1108 |
#endif /* 64-bit PowerPC. */ |
| 1109 |
|
| 1110 |
/*************************************** |
| 1111 |
************** PYR ****************** |
| 1112 |
***************************************/ |
| 1113 |
#if defined (__pyr__) && W_TYPE_SIZE == 32 |
| 1114 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1115 |
__asm__ ("addw %5,%1 \n" \ |
| 1116 |
"addwc %3,%0" \ |
| 1117 |
: "=r" ((USItype)(sh)), \ |
| 1118 |
"=&r" ((USItype)(sl)) \ |
| 1119 |
: "%0" ((USItype)(ah)), \ |
| 1120 |
"g" ((USItype)(bh)), \ |
| 1121 |
"%1" ((USItype)(al)), \ |
| 1122 |
"g" ((USItype)(bl))) |
| 1123 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1124 |
__asm__ ("subw %5,%1 \n" \ |
| 1125 |
"subwb %3,%0" \ |
| 1126 |
: "=r" ((USItype)(sh)), \ |
| 1127 |
"=&r" ((USItype)(sl)) \ |
| 1128 |
: "0" ((USItype)(ah)), \ |
| 1129 |
"g" ((USItype)(bh)), \ |
| 1130 |
"1" ((USItype)(al)), \ |
| 1131 |
"g" ((USItype)(bl))) |
| 1132 |
/* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */ |
| 1133 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1134 |
({union {UDItype __ll; \ |
| 1135 |
struct {USItype __h, __l;} __i; \ |
| 1136 |
} __xx; \ |
| 1137 |
__asm__ ("movw %1,%R0 \n" \ |
| 1138 |
"uemul %2,%0" \ |
| 1139 |
: "=&r" (__xx.__ll) \ |
| 1140 |
: "g" ((USItype) (u)), \ |
| 1141 |
"g" ((USItype)(v))); \ |
| 1142 |
(w1) = __xx.__i.__h; (w0) = __xx.__i.__l;}) |
| 1143 |
#endif /* __pyr__ */ |
| 1144 |
|
| 1145 |
|
| 1146 |
/*************************************** |
| 1147 |
************** RT/ROMP ************** |
| 1148 |
***************************************/ |
| 1149 |
#if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32 |
| 1150 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1151 |
__asm__ ("a %1,%5 \n" \ |
| 1152 |
"ae %0,%3" \ |
| 1153 |
: "=r" ((USItype)(sh)), \ |
| 1154 |
"=&r" ((USItype)(sl)) \ |
| 1155 |
: "%0" ((USItype)(ah)), \ |
| 1156 |
"r" ((USItype)(bh)), \ |
| 1157 |
"%1" ((USItype)(al)), \ |
| 1158 |
"r" ((USItype)(bl))) |
| 1159 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1160 |
__asm__ ("s %1,%5\n" \ |
| 1161 |
"se %0,%3" \ |
| 1162 |
: "=r" ((USItype)(sh)), \ |
| 1163 |
"=&r" ((USItype)(sl)) \ |
| 1164 |
: "0" ((USItype)(ah)), \ |
| 1165 |
"r" ((USItype)(bh)), \ |
| 1166 |
"1" ((USItype)(al)), \ |
| 1167 |
"r" ((USItype)(bl))) |
| 1168 |
# define umul_ppmm(ph, pl, m0, m1) \ |
| 1169 |
do { \ |
| 1170 |
USItype __m0 = (m0), __m1 = (m1); \ |
| 1171 |
__asm__ ( \ |
| 1172 |
"s r2,r2 \n" \ |
| 1173 |
"mts r10,%2 \n" \ |
| 1174 |
"m r2,%3 \n" \ |
| 1175 |
"m r2,%3 \n" \ |
| 1176 |
"m r2,%3 \n" \ |
| 1177 |
"m r2,%3 \n" \ |
| 1178 |
"m r2,%3 \n" \ |
| 1179 |
"m r2,%3 \n" \ |
| 1180 |
"m r2,%3 \n" \ |
| 1181 |
"m r2,%3 \n" \ |
| 1182 |
"m r2,%3 \n" \ |
| 1183 |
"m r2,%3 \n" \ |
| 1184 |
"m r2,%3 \n" \ |
| 1185 |
"m r2,%3 \n" \ |
| 1186 |
"m r2,%3 \n" \ |
| 1187 |
"m r2,%3 \n" \ |
| 1188 |
"m r2,%3 \n" \ |
| 1189 |
"m r2,%3 \n" \ |
| 1190 |
"cas %0,r2,r0 \n" \ |
| 1191 |
"mfs r10,%1" \ |
| 1192 |
: "=r" ((USItype)(ph)), \ |
| 1193 |
"=r" ((USItype)(pl)) \ |
| 1194 |
: "%r" (__m0), \ |
| 1195 |
"r" (__m1) \ |
| 1196 |
: "r2"); \ |
| 1197 |
(ph) += ((((SItype) __m0 >> 31) & __m1) \ |
| 1198 |
+ (((SItype) __m1 >> 31) & __m0)); \ |
| 1199 |
} while (0) |
| 1200 |
# define UMUL_TIME 20 |
| 1201 |
# define UDIV_TIME 200 |
| 1202 |
# define count_leading_zeros(count, x) \ |
| 1203 |
do { \ |
| 1204 |
if ((x) >= 0x10000) \ |
| 1205 |
__asm__ ("clz %0,%1" \ |
| 1206 |
: "=r" ((USItype)(count)) \ |
| 1207 |
: "r" ((USItype)(x) >> 16)); \ |
| 1208 |
else \ |
| 1209 |
{ \ |
| 1210 |
__asm__ ("clz %0,%1" \ |
| 1211 |
: "=r" ((USItype)(count)) \ |
| 1212 |
: "r" ((USItype)(x))); \ |
| 1213 |
(count) += 16; \ |
| 1214 |
} \ |
| 1215 |
} while (0) |
| 1216 |
#endif /* RT/ROMP */ |
| 1217 |
|
| 1218 |
|
| 1219 |
/*************************************** |
| 1220 |
************** SH2 ****************** |
| 1221 |
***************************************/ |
| 1222 |
#if (defined (__sh2__) || defined(__sh3__) || defined(__SH4__) ) \ |
| 1223 |
&& W_TYPE_SIZE == 32 |
| 1224 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1225 |
__asm__ ( \ |
| 1226 |
"dmulu.l %2,%3\n" \ |
| 1227 |
"sts macl,%1\n" \ |
| 1228 |
"sts mach,%0" \ |
| 1229 |
: "=r" ((USItype)(w1)), \ |
| 1230 |
"=r" ((USItype)(w0)) \ |
| 1231 |
: "r" ((USItype)(u)), \ |
| 1232 |
"r" ((USItype)(v)) \ |
| 1233 |
: "macl", "mach") |
| 1234 |
# define UMUL_TIME 5 |
| 1235 |
#endif |
| 1236 |
|
| 1237 |
/*************************************** |
| 1238 |
************** SPARC **************** |
| 1239 |
***************************************/ |
| 1240 |
#if defined (__sparc__) && W_TYPE_SIZE == 32 |
| 1241 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1242 |
__asm__ ("addcc %r4,%5,%1\n" \ |
| 1243 |
"addx %r2,%3,%0" \ |
| 1244 |
: "=r" ((USItype)(sh)), \ |
| 1245 |
"=&r" ((USItype)(sl)) \ |
| 1246 |
: "%rJ" ((USItype)(ah)), \ |
| 1247 |
"rI" ((USItype)(bh)), \ |
| 1248 |
"%rJ" ((USItype)(al)), \ |
| 1249 |
"rI" ((USItype)(bl)) \ |
| 1250 |
__CLOBBER_CC) |
| 1251 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1252 |
__asm__ ("subcc %r4,%5,%1\n" \ |
| 1253 |
"subx %r2,%3,%0" \ |
| 1254 |
: "=r" ((USItype)(sh)), \ |
| 1255 |
"=&r" ((USItype)(sl)) \ |
| 1256 |
: "rJ" ((USItype)(ah)), \ |
| 1257 |
"rI" ((USItype)(bh)), \ |
| 1258 |
"rJ" ((USItype)(al)), \ |
| 1259 |
"rI" ((USItype)(bl)) \ |
| 1260 |
__CLOBBER_CC) |
| 1261 |
# if defined (__sparc_v8__) || defined(__sparcv8) |
| 1262 |
/* Don't match immediate range because, 1) it is not often useful, |
| 1263 |
2) the 'I' flag thinks of the range as a 13 bit signed interval, |
| 1264 |
while we want to match a 13 bit interval, sign extended to 32 bits, |
| 1265 |
but INTERPRETED AS UNSIGNED. */ |
| 1266 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1267 |
__asm__ ("umul %2,%3,%1;rd %%y,%0" \ |
| 1268 |
: "=r" ((USItype)(w1)), \ |
| 1269 |
"=r" ((USItype)(w0)) \ |
| 1270 |
: "r" ((USItype)(u)), \ |
| 1271 |
"r" ((USItype)(v))) |
| 1272 |
# define UMUL_TIME 5 |
| 1273 |
# ifndef SUPERSPARC /* SuperSPARC's udiv only handles 53 bit dividends */ |
| 1274 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 1275 |
do { \ |
| 1276 |
USItype __q; \ |
| 1277 |
__asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \ |
| 1278 |
: "=r" ((USItype)(__q)) \ |
| 1279 |
: "r" ((USItype)(n1)), \ |
| 1280 |
"r" ((USItype)(n0)), \ |
| 1281 |
"r" ((USItype)(d))); \ |
| 1282 |
(r) = (n0) - __q * (d); \ |
| 1283 |
(q) = __q; \ |
| 1284 |
} while (0) |
| 1285 |
# define UDIV_TIME 25 |
| 1286 |
# endif /*!SUPERSPARC */ |
| 1287 |
# else /* ! __sparc_v8__ */ |
| 1288 |
# if defined (__sparclite__) |
| 1289 |
/* This has hardware multiply but not divide. It also has two additional |
| 1290 |
instructions scan (ffs from high bit) and divscc. */ |
| 1291 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1292 |
__asm__ ("umul %2,%3,%1;rd %%y,%0" \ |
| 1293 |
: "=r" ((USItype)(w1)), \ |
| 1294 |
"=r" ((USItype)(w0)) \ |
| 1295 |
: "r" ((USItype)(u)), \ |
| 1296 |
"r" ((USItype)(v))) |
| 1297 |
# define UMUL_TIME 5 |
| 1298 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 1299 |
__asm__ ("! Inlined udiv_qrnnd \n" \ |
| 1300 |
" wr %%g0,%2,%%y ! Not a delayed write for sparclite \n" \ |
| 1301 |
" tst %%g0 \n" \ |
| 1302 |
" divscc %3,%4,%%g1 \n" \ |
| 1303 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1304 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1305 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1306 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1307 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1308 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1309 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1310 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1311 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1312 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1313 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1314 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1315 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1316 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1317 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1318 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1319 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1320 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1321 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1322 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1323 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1324 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1325 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1326 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1327 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1328 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1329 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1330 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1331 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1332 |
" divscc %%g1,%4,%%g1 \n" \ |
| 1333 |
" divscc %%g1,%4,%0 \n" \ |
| 1334 |
" rd %%y,%1 \n" \ |
| 1335 |
" bl,a 1f \n" \ |
| 1336 |
" add %1,%4,%1 \n" \ |
| 1337 |
"1: ! End of inline udiv_qrnnd" \ |
| 1338 |
: "=r" ((USItype)(q)), \ |
| 1339 |
"=r" ((USItype)(r)) \ |
| 1340 |
: "r" ((USItype)(n1)), \ |
| 1341 |
"r" ((USItype)(n0)), \ |
| 1342 |
"rI" ((USItype)(d)) \ |
| 1343 |
: "%g1" __AND_CLOBBER_CC) |
| 1344 |
# define UDIV_TIME 37 |
| 1345 |
# define count_leading_zeros(count, x) \ |
| 1346 |
__asm__ ("scan %1,0,%0" \ |
| 1347 |
: "=r" ((USItype)(x)) \ |
| 1348 |
: "r" ((USItype)(count))) |
| 1349 |
/* Early sparclites return 63 for an argument of 0, but they warn that future |
| 1350 |
implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0 |
| 1351 |
undefined. */ |
| 1352 |
# endif /* !__sparclite__ */ |
| 1353 |
# endif /* !__sparc_v8__ */ |
| 1354 |
/* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */ |
| 1355 |
# ifndef umul_ppmm |
| 1356 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1357 |
__asm__ ("! Inlined umul_ppmm \n" \ |
| 1358 |
" wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr \n" \ |
| 1359 |
" sra %3,31,%%g2 ! Don't move this insn \n" \ |
| 1360 |
" and %2,%%g2,%%g2 ! Don't move this insn \n" \ |
| 1361 |
" andcc %%g0,0,%%g1 ! Don't move this insn \n" \ |
| 1362 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1363 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1364 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1365 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1366 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1367 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1368 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1369 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1370 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1371 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1372 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1373 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1374 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1375 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1376 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1377 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1378 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1379 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1380 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1381 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1382 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1383 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1384 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1385 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1386 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1387 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1388 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1389 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1390 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1391 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1392 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1393 |
" mulscc %%g1,%3,%%g1 \n" \ |
| 1394 |
" mulscc %%g1,0,%%g1 \n" \ |
| 1395 |
" add %%g1,%%g2,%0 \n" \ |
| 1396 |
" rd %%y,%1" \ |
| 1397 |
: "=r" ((USItype)(w1)), \ |
| 1398 |
"=r" ((USItype)(w0)) \ |
| 1399 |
: "%rI" ((USItype)(u)), \ |
| 1400 |
"r" ((USItype)(v)) \ |
| 1401 |
: "%g1", "%g2" __AND_CLOBBER_CC) |
| 1402 |
# define UMUL_TIME 39 /* 39 instructions */ |
| 1403 |
# endif /* umul_ppmm */ |
| 1404 |
# ifndef udiv_qrnnd |
| 1405 |
# ifndef LONGLONG_STANDALONE |
| 1406 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 1407 |
do { USItype __r; \ |
| 1408 |
(q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \ |
| 1409 |
(r) = __r; \ |
| 1410 |
} while (0) |
| 1411 |
extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype); |
| 1412 |
# define UDIV_TIME 140 |
| 1413 |
# endif /* LONGLONG_STANDALONE */ |
| 1414 |
# endif /* udiv_qrnnd */ |
| 1415 |
#endif /* __sparc__ */ |
| 1416 |
|
| 1417 |
|
| 1418 |
/*************************************** |
| 1419 |
************** VAX ****************** |
| 1420 |
***************************************/ |
| 1421 |
#if defined (__vax__) && W_TYPE_SIZE == 32 |
| 1422 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1423 |
__asm__ ("addl2 %5,%1\n" \ |
| 1424 |
"adwc %3,%0" \ |
| 1425 |
: "=g" ((USItype)(sh)), \ |
| 1426 |
"=&g" ((USItype)(sl)) \ |
| 1427 |
: "%0" ((USItype)(ah)), \ |
| 1428 |
"g" ((USItype)(bh)), \ |
| 1429 |
"%1" ((USItype)(al)), \ |
| 1430 |
"g" ((USItype)(bl))) |
| 1431 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1432 |
__asm__ ("subl2 %5,%1\n" \ |
| 1433 |
"sbwc %3,%0" \ |
| 1434 |
: "=g" ((USItype)(sh)), \ |
| 1435 |
"=&g" ((USItype)(sl)) \ |
| 1436 |
: "0" ((USItype)(ah)), \ |
| 1437 |
"g" ((USItype)(bh)), \ |
| 1438 |
"1" ((USItype)(al)), \ |
| 1439 |
"g" ((USItype)(bl))) |
| 1440 |
# define umul_ppmm(xh, xl, m0, m1) \ |
| 1441 |
do { \ |
| 1442 |
union {UDItype __ll; \ |
| 1443 |
struct {USItype __l, __h;} __i; \ |
| 1444 |
} __xx; \ |
| 1445 |
USItype __m0 = (m0), __m1 = (m1); \ |
| 1446 |
__asm__ ("emul %1,%2,$0,%0" \ |
| 1447 |
: "=g" (__xx.__ll) \ |
| 1448 |
: "g" (__m0), \ |
| 1449 |
"g" (__m1)); \ |
| 1450 |
(xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \ |
| 1451 |
(xh) += ((((SItype) __m0 >> 31) & __m1) \ |
| 1452 |
+ (((SItype) __m1 >> 31) & __m0)); \ |
| 1453 |
} while (0) |
| 1454 |
# define sdiv_qrnnd(q, r, n1, n0, d) \ |
| 1455 |
do { \ |
| 1456 |
union {DItype __ll; \ |
| 1457 |
struct {SItype __l, __h;} __i; \ |
| 1458 |
} __xx; \ |
| 1459 |
__xx.__i.__h = (n1); __xx.__i.__l = (n0); \ |
| 1460 |
__asm__ ("ediv %3,%2,%0,%1" \ |
| 1461 |
: "=g" (q), "=g" (r) \ |
| 1462 |
: "g" (__xx.__ll), "g" (d)); \ |
| 1463 |
} while (0) |
| 1464 |
#endif /* __vax__ */ |
| 1465 |
|
| 1466 |
|
| 1467 |
/*************************************** |
| 1468 |
************** Z8000 **************** |
| 1469 |
***************************************/ |
| 1470 |
#if defined (__z8000__) && W_TYPE_SIZE == 16 |
| 1471 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1472 |
__asm__ ("add %H1,%H5\n\tadc %H0,%H3" \ |
| 1473 |
: "=r" ((unsigned int)(sh)), \ |
| 1474 |
"=&r" ((unsigned int)(sl)) \ |
| 1475 |
: "%0" ((unsigned int)(ah)), \ |
| 1476 |
"r" ((unsigned int)(bh)), \ |
| 1477 |
"%1" ((unsigned int)(al)), \ |
| 1478 |
"rQR" ((unsigned int)(bl))) |
| 1479 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1480 |
__asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \ |
| 1481 |
: "=r" ((unsigned int)(sh)), \ |
| 1482 |
"=&r" ((unsigned int)(sl)) \ |
| 1483 |
: "0" ((unsigned int)(ah)), \ |
| 1484 |
"r" ((unsigned int)(bh)), \ |
| 1485 |
"1" ((unsigned int)(al)), \ |
| 1486 |
"rQR" ((unsigned int)(bl))) |
| 1487 |
# define umul_ppmm(xh, xl, m0, m1) \ |
| 1488 |
do { \ |
| 1489 |
union {long int __ll; \ |
| 1490 |
struct {unsigned int __h, __l;} __i; \ |
| 1491 |
} __xx; \ |
| 1492 |
unsigned int __m0 = (m0), __m1 = (m1); \ |
| 1493 |
__asm__ ("mult %S0,%H3" \ |
| 1494 |
: "=r" (__xx.__i.__h), \ |
| 1495 |
"=r" (__xx.__i.__l) \ |
| 1496 |
: "%1" (__m0), \ |
| 1497 |
"rQR" (__m1)); \ |
| 1498 |
(xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \ |
| 1499 |
(xh) += ((((signed int) __m0 >> 15) & __m1) \ |
| 1500 |
+ (((signed int) __m1 >> 15) & __m0)); \ |
| 1501 |
} while (0) |
| 1502 |
#endif /* __z8000__ */ |
| 1503 |
|
| 1504 |
|
| 1505 |
/*************************************** |
| 1506 |
*********** s390x/zSeries ************ |
| 1507 |
***************************************/ |
| 1508 |
#if defined (__s390x__) && !defined (__MVS__) && W_TYPE_SIZE == 64 && __GNUC__ >= 4 |
| 1509 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1510 |
__asm__ ("algr %1,%5\n" \ |
| 1511 |
"alcgr %0,%3\n" \ |
| 1512 |
: "=r" ((sh)), \ |
| 1513 |
"=&r" ((sl)) \ |
| 1514 |
: "0" ((UDItype)(ah)), \ |
| 1515 |
"r" ((UDItype)(bh)), \ |
| 1516 |
"1" ((UDItype)(al)), \ |
| 1517 |
"r" ((UDItype)(bl)) \ |
| 1518 |
__CLOBBER_CC) |
| 1519 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1520 |
__asm__ ("slgr %1,%5\n" \ |
| 1521 |
"slbgr %0,%3\n" \ |
| 1522 |
: "=r" ((sh)), \ |
| 1523 |
"=&r" ((sl)) \ |
| 1524 |
: "0" ((UDItype)(ah)), \ |
| 1525 |
"r" ((UDItype)(bh)), \ |
| 1526 |
"1" ((UDItype)(al)), \ |
| 1527 |
"r" ((UDItype)(bl)) \ |
| 1528 |
__CLOBBER_CC) |
| 1529 |
typedef unsigned int UTItype __attribute__ ((mode (TI))); |
| 1530 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1531 |
do { \ |
| 1532 |
UTItype ___r; \ |
| 1533 |
__asm__ ("mlgr %0,%2" \ |
| 1534 |
: "=r" (___r) \ |
| 1535 |
: "0" ((UDItype)(u)), \ |
| 1536 |
"r" ((UDItype)(v))); \ |
| 1537 |
(w1) = ___r >> 64; \ |
| 1538 |
(w0) = (UDItype) ___r; \ |
| 1539 |
} while (0) |
| 1540 |
# define udiv_qrnnd(q, r, n1, n0, d) \ |
| 1541 |
do { \ |
| 1542 |
UTItype ___r = ((UTItype)n1 << 64) | n0; \ |
| 1543 |
__asm__ ("dlgr %0,%2" \ |
| 1544 |
: "=r" (___r) \ |
| 1545 |
: "0" (___r), \ |
| 1546 |
"r" ((UDItype)(d))); \ |
| 1547 |
(r) = ___r >> 64; \ |
| 1548 |
(q) = (UDItype) ___r; \ |
| 1549 |
} while (0) |
| 1550 |
#endif /* __s390x__ */ |
| 1551 |
|
| 1552 |
|
| 1553 |
/*************************************** |
| 1554 |
***** End CPU Specific Versions ***** |
| 1555 |
***************************************/ |
| 1556 |
|
| 1557 |
#endif /* __GNUC__ */ |
| 1558 |
#endif /* !__riscos__ */ |
| 1559 |
|
| 1560 |
|
| 1561 |
/*************************************** |
| 1562 |
*********** Generic Versions ******** |
| 1563 |
***************************************/ |
| 1564 |
#if !defined (umul_ppmm) && defined (__umulsidi3) |
| 1565 |
# define umul_ppmm(ph, pl, m0, m1) \ |
| 1566 |
{ \ |
| 1567 |
UDWtype __ll = __umulsidi3 (m0, m1); \ |
| 1568 |
ph = (UWtype) (__ll >> W_TYPE_SIZE); \ |
| 1569 |
pl = (UWtype) __ll; \ |
| 1570 |
} |
| 1571 |
#endif |
| 1572 |
|
| 1573 |
#if !defined (__umulsidi3) |
| 1574 |
# define __umulsidi3(u, v) \ |
| 1575 |
({UWtype __hi, __lo; \ |
| 1576 |
umul_ppmm (__hi, __lo, u, v); \ |
| 1577 |
((UDWtype) __hi << W_TYPE_SIZE) | __lo; }) |
| 1578 |
#endif |
| 1579 |
|
| 1580 |
/* If this machine has no inline assembler, use C macros. */ |
| 1581 |
|
| 1582 |
#if !defined (add_ssaaaa) && defined (UDWtype) |
| 1583 |
/* Use double word type when available. */ |
| 1584 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1585 |
do { \ |
| 1586 |
UDWtype __audw = (ah); \ |
| 1587 |
UWtype __auwh, __auwl; \ |
| 1588 |
UDWtype __budw = (bh); \ |
| 1589 |
__audw <<= W_TYPE_SIZE; \ |
| 1590 |
__audw |= (al); \ |
| 1591 |
__budw <<= W_TYPE_SIZE; \ |
| 1592 |
__budw |= (bl); \ |
| 1593 |
__audw += __budw; \ |
| 1594 |
__auwh = (UWtype)(__audw >> W_TYPE_SIZE); \ |
| 1595 |
__auwl = (UWtype)(__audw); \ |
| 1596 |
CT_DEOPTIMIZE_VAR(__auwh); \ |
| 1597 |
(sh) = __auwh; \ |
| 1598 |
(sl) = __auwl; \ |
| 1599 |
} while (0) |
| 1600 |
#elif !defined (add_ssaaaa) |
| 1601 |
# define add_ssaaaa(sh, sl, ah, al, bh, bl) \ |
| 1602 |
do { \ |
| 1603 |
UWtype __xl, __xh; \ |
| 1604 |
__xl = (al) + (bl); \ |
| 1605 |
__xh = __xl < (al); \ |
| 1606 |
__xh = (ah) + (bh) + __xh; \ |
| 1607 |
CT_DEOPTIMIZE_VAR(__xh); \ |
| 1608 |
(sh) = __xh; \ |
| 1609 |
(sl) = __xl; \ |
| 1610 |
} while (0) |
| 1611 |
#endif |
| 1612 |
|
| 1613 |
#if !defined (sub_ddmmss) && defined (UDWtype) |
| 1614 |
/* Use double word type when available. */ |
| 1615 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1616 |
do { \ |
| 1617 |
UDWtype __audw = (ah); \ |
| 1618 |
UWtype __auwh, __auwl; \ |
| 1619 |
UDWtype __budw = (bh); \ |
| 1620 |
__audw <<= W_TYPE_SIZE; \ |
| 1621 |
__audw |= (al); \ |
| 1622 |
__budw <<= W_TYPE_SIZE; \ |
| 1623 |
__budw |= (bl); \ |
| 1624 |
__audw -= __budw; \ |
| 1625 |
__auwh = (UWtype)(__audw >> W_TYPE_SIZE); \ |
| 1626 |
__auwl = (UWtype)(__audw); \ |
| 1627 |
CT_DEOPTIMIZE_VAR(__auwh); \ |
| 1628 |
(sh) = __auwh; \ |
| 1629 |
(sl) = __auwl; \ |
| 1630 |
} while (0) |
| 1631 |
#elif !defined (sub_ddmmss) |
| 1632 |
# define sub_ddmmss(sh, sl, ah, al, bh, bl) \ |
| 1633 |
do { \ |
| 1634 |
UWtype __xl, __xh; \ |
| 1635 |
__xl = (al) - (bl); \ |
| 1636 |
__xh = (__xl > (al)); \ |
| 1637 |
__xh = (ah) - (bh) - __xh; \ |
| 1638 |
CT_DEOPTIMIZE_VAR(__xh); \ |
| 1639 |
(sh) = __xh; \ |
| 1640 |
(sl) = __xl; \ |
| 1641 |
} while (0) |
| 1642 |
#endif |
| 1643 |
|
| 1644 |
#if !defined (umul_ppmm) && defined (UDWtype) |
| 1645 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1646 |
do { \ |
| 1647 |
UDWtype __x = (u); \ |
| 1648 |
__x *= (v); \ |
| 1649 |
(w1) = (UWtype)(__x >> W_TYPE_SIZE); \ |
| 1650 |
(w0) = (UWtype)(__x); \ |
| 1651 |
} while (0) |
| 1652 |
#elif !defined (umul_ppmm) |
| 1653 |
# define umul_ppmm(w1, w0, u, v) \ |
| 1654 |
do { \ |
| 1655 |
UWtype __x0, __x1, __x2, __x3; \ |
| 1656 |
UHWtype __ul, __vl, __uh, __vh; \ |
| 1657 |
UWtype __u = (u), __v = (v); \ |
| 1658 |
\ |
| 1659 |
__ul = __ll_lowpart (__u); \ |
| 1660 |
__uh = __ll_highpart (__u); \ |
| 1661 |
__vl = __ll_lowpart (__v); \ |
| 1662 |
__vh = __ll_highpart (__v); \ |
| 1663 |
\ |
| 1664 |
__x0 = (UWtype) __ul * __vl; \ |
| 1665 |
__x1 = (UWtype) __ul * __vh; \ |
| 1666 |
__x2 = (UWtype) __uh * __vl; \ |
| 1667 |
__x3 = (UWtype) __uh * __vh; \ |
| 1668 |
\ |
| 1669 |
__x1 += __ll_highpart (__x0);/* this can't give carry */ \ |
| 1670 |
/* but this indeed can, and if so, add it in the proper pos: */ \ |
| 1671 |
add_ssaaaa(__x2, __x1, 0, __x1, 0, __x2); \ |
| 1672 |
__x3 += __x2 << (W_TYPE_SIZE / 2); \ |
| 1673 |
(w1) = __x3 + __ll_highpart (__x1); \ |
| 1674 |
(w0) = (__ll_lowpart (__x1) << W_TYPE_SIZE/2) + __ll_lowpart (__x0);\ |
| 1675 |
} while (0) |
| 1676 |
#endif |
| 1677 |
|
| 1678 |
#if !defined (smul_ppmm) |
| 1679 |
# define smul_ppmm(w1, w0, u, v) \ |
| 1680 |
do { \ |
| 1681 |
UWtype __w1; \ |
| 1682 |
UWtype __m0 = (u), __m1 = (v); \ |
| 1683 |
umul_ppmm (__w1, w0, __m0, __m1); \ |
| 1684 |
(w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \ |
| 1685 |
- (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \ |
| 1686 |
} while (0) |
| 1687 |
#endif |
| 1688 |
|
| 1689 |
/* Define this unconditionally, so it can be used for debugging. */ |
| 1690 |
#define __udiv_qrnnd_c(q, r, n1, n0, d) \ |
| 1691 |
do { \ |
| 1692 |
UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \ |
| 1693 |
__d1 = __ll_highpart (d); \ |
| 1694 |
__d0 = __ll_lowpart (d); \ |
| 1695 |
\ |
| 1696 |
__r1 = (n1) % __d1; \ |
| 1697 |
__q1 = (n1) / __d1; \ |
| 1698 |
__m = (UWtype) __q1 * __d0; \ |
| 1699 |
__r1 = __r1 * __ll_B | __ll_highpart (n0); \ |
| 1700 |
if (__r1 < __m) \ |
| 1701 |
{ \ |
| 1702 |
__q1--, __r1 += (d); \ |
| 1703 |
if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\ |
| 1704 |
if (__r1 < __m) \ |
| 1705 |
__q1--, __r1 += (d); \ |
| 1706 |
} \ |
| 1707 |
__r1 -= __m; \ |
| 1708 |
\ |
| 1709 |
__r0 = __r1 % __d1; \ |
| 1710 |
__q0 = __r1 / __d1; \ |
| 1711 |
__m = (UWtype) __q0 * __d0; \ |
| 1712 |
__r0 = __r0 * __ll_B | __ll_lowpart (n0); \ |
| 1713 |
if (__r0 < __m) \ |
| 1714 |
{ \ |
| 1715 |
__q0--, __r0 += (d); \ |
| 1716 |
if (__r0 >= (d)) \ |
| 1717 |
if (__r0 < __m) \ |
| 1718 |
__q0--, __r0 += (d); \ |
| 1719 |
} \ |
| 1720 |
__r0 -= __m; \ |
| 1721 |
\ |
| 1722 |
(q) = (UWtype) __q1 * __ll_B | __q0; \ |
| 1723 |
(r) = __r0; \ |
| 1724 |
} while (0) |
| 1725 |
|
| 1726 |
/* Use double word type if available. */ |
| 1727 |
#if !defined (udiv_qrnnd) && defined (UDWtype) |
| 1728 |
# define udiv_qrnnd(q, r, nh, nl, d) \ |
| 1729 |
do { \ |
| 1730 |
UWtype __d = (d); \ |
| 1731 |
UDWtype __nudw = (nh); \ |
| 1732 |
__nudw <<= W_TYPE_SIZE; \ |
| 1733 |
__nudw |= (nl); \ |
| 1734 |
(q) = (UWtype)(__nudw / __d); \ |
| 1735 |
(r) = (UWtype)(__nudw % __d); \ |
| 1736 |
} while (0) |
| 1737 |
#endif |
| 1738 |
|
| 1739 |
/* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through |
| 1740 |
__udiv_w_sdiv (defined in libgcc or elsewhere). */ |
| 1741 |
#if !defined (udiv_qrnnd) && defined (sdiv_qrnnd) |
| 1742 |
# define udiv_qrnnd(q, r, nh, nl, d) \ |
| 1743 |
do { \ |
| 1744 |
UWtype __r; \ |
| 1745 |
(q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \ |
| 1746 |
(r) = __r; \ |
| 1747 |
} while (0) |
| 1748 |
#endif |
| 1749 |
|
| 1750 |
/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */ |
| 1751 |
#if !defined (udiv_qrnnd) |
| 1752 |
# define UDIV_NEEDS_NORMALIZATION 1 |
| 1753 |
# define udiv_qrnnd __udiv_qrnnd_c |
| 1754 |
#endif |
| 1755 |
|
| 1756 |
#if !defined (count_leading_zeros) |
| 1757 |
# if defined (HAVE_BUILTIN_CLZL) && SIZEOF_UNSIGNED_LONG * 8 == W_TYPE_SIZE |
| 1758 |
# define count_leading_zeros(count, x) (count = __builtin_clzl(x)) |
| 1759 |
# undef COUNT_LEADING_ZEROS_0 /* Input X=0 is undefined for the builtin. */ |
| 1760 |
# elif defined (HAVE_BUILTIN_CLZ) && SIZEOF_UNSIGNED_INT * 8 == W_TYPE_SIZE |
| 1761 |
# define count_leading_zeros(count, x) (count = __builtin_clz(x)) |
| 1762 |
# undef COUNT_LEADING_ZEROS_0 /* Input X=0 is undefined for the builtin. */ |
| 1763 |
# endif |
| 1764 |
#endif |
| 1765 |
|
| 1766 |
#if !defined (count_trailing_zeros) |
| 1767 |
# if defined (HAVE_BUILTIN_CTZL) && SIZEOF_UNSIGNED_LONG * 8 == W_TYPE_SIZE |
| 1768 |
# define count_trailing_zeros(count, x) (count = __builtin_ctzl(x)) |
| 1769 |
# undef COUNT_LEADING_ZEROS_0 /* Input X=0 is undefined for the builtin. */ |
| 1770 |
# elif defined (HAVE_BUILTIN_CTZ) && SIZEOF_UNSIGNED_INT * 8 == W_TYPE_SIZE |
| 1771 |
# define count_trailing_zeros(count, x) (count = __builtin_ctz(x)) |
| 1772 |
# undef COUNT_LEADING_ZEROS_0 /* Input X=0 is undefined for the builtin. */ |
| 1773 |
# endif |
| 1774 |
#endif |
| 1775 |
|
| 1776 |
#if !defined (count_leading_zeros) |
| 1777 |
extern |
| 1778 |
# ifdef __STDC__ |
| 1779 |
const |
| 1780 |
# endif |
| 1781 |
unsigned char _gcry_clz_tab[]; |
| 1782 |
# define MPI_INTERNAL_NEED_CLZ_TAB 1 |
| 1783 |
# define count_leading_zeros(count, x) \ |
| 1784 |
do { \ |
| 1785 |
UWtype __xr = (x); \ |
| 1786 |
UWtype __a; \ |
| 1787 |
\ |
| 1788 |
if (W_TYPE_SIZE <= 32) \ |
| 1789 |
{ \ |
| 1790 |
__a = __xr < ((UWtype) 1 << 2*__BITS4) \ |
| 1791 |
? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \ |
| 1792 |
: (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4);\ |
| 1793 |
} \ |
| 1794 |
else \ |
| 1795 |
{ \ |
| 1796 |
for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \ |
| 1797 |
if (((__xr >> __a) & 0xff) != 0) \ |
| 1798 |
break; \ |
| 1799 |
} \ |
| 1800 |
\ |
| 1801 |
(count) = W_TYPE_SIZE - (_gcry_clz_tab[__xr >> __a] + __a); \ |
| 1802 |
} while (0) |
| 1803 |
/* This version gives a well-defined value for zero. */ |
| 1804 |
# define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE |
| 1805 |
#endif /* !count_leading_zeros */ |
| 1806 |
|
| 1807 |
#if !defined (count_trailing_zeros) |
| 1808 |
/* Define count_trailing_zeros using count_leading_zeros. The latter might be |
| 1809 |
defined in asm, but if it is not, the C version above is good enough. */ |
| 1810 |
# define count_trailing_zeros(count, x) \ |
| 1811 |
do { \ |
| 1812 |
UWtype __ctz_x = (x); \ |
| 1813 |
UWtype __ctz_c; \ |
| 1814 |
count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \ |
| 1815 |
(count) = W_TYPE_SIZE - 1 - __ctz_c; \ |
| 1816 |
} while (0) |
| 1817 |
#endif /* !count_trailing_zeros */ |
| 1818 |
|
| 1819 |
#ifndef UDIV_NEEDS_NORMALIZATION |
| 1820 |
# define UDIV_NEEDS_NORMALIZATION 0 |
| 1821 |
#endif |
| 1822 |
|
| 1823 |
/*************************************** |
| 1824 |
****** longlong.h ends here ********* |
| 1825 |
***************************************/ |