1 /* 128-bit floating point to 64-bit fixed point unsigned integer.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <quad_float.h>
22 /* unsigned long long _q_qtoull(const long double *a);
23 Convert 'a' to unsigned long long by truncation.
27 NaN: raise VXCVI, return 0
28 SNaN: raise VXSNAN, VXCVI, and return 0
29 Negative numbers (other than -0, but including -Inf): raise VXCVI, return 0
30 >= 2^32: raise VXCVI, return 0xffffffffffffffff
34 __q_qtoull(const unsigned long long a
[2])
38 unsigned long long a0
, a1
;
40 /* Deal with non-special cases. */
42 ax
= (a0
>> 48) - 16383;
44 /* If we had a '>>' operator that behaved properly with respect to
45 large shifts, we wouldn't need the '& -(ax >> 31)' term, which
46 clears 'result' if ax is negative. */
47 return ((a0
<< 15 | a1
>> 64-15 | 0x8000000000000000ULL
) >> 63-ax
48 & -(unsigned long long)(ax
>> 31));
50 /* 'result' is 1 if a is negative, 0 otherwise. */
52 /* Check for -0, otherwise raise VXCVI. */
53 if (a0
!= 0x8000000000000000ULL
|| a
[1] != 0)
55 /* Check for SNaN, if so raise VXSNAN. */
56 if ((a0
>> 32 & 0x7fff8000) == 0x7fff0000
57 && (a1
| a0
& 0x00007fffffffffffULL
) != 0)
58 set_fpscr_bit(FPSCR_VXSNAN
);
59 /* Treat all NaNs as large negative numbers. */
60 result
|= cntlzw(~(a0
>> 32) & 0x7fff0000) >> 5;
62 set_fpscr_bit(FPSCR_VXCVI
);