OSDN Git Service

PR target/34210 PR target/35508 * config.host (avr-*-*): Add avr cpu_type and avr...
[pf3gnuchains/gcc-fork.git] / libgcc / config / libbid / bid64_logb.c
1 /* Copyright (C) 2007  Free Software Foundation, Inc.
2
3 This file is part of GCC.
4
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version.
9
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file.  (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
17 executable.)
18
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING.  If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 02110-1301, USA.  */
28
29 #include "bid_internal.h"
30
31 #define MAX_FORMAT_DIGITS     16
32 #define DECIMAL_EXPONENT_BIAS 398
33
34 #if DECIMAL_CALL_BY_REFERENCE
35
36 void
37 bid64_logb (int * pres, UINT64 * px
38             _EXC_FLAGS_PARAM _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
39   UINT64 x;
40 #else
41
42 int
43 bid64_logb (UINT64 x _EXC_FLAGS_PARAM _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
44 #endif
45   UINT64 sign_x, coefficient_x;
46   int_double dx;
47   int exponent_x, bin_expon_cx, digits;
48
49 #if DECIMAL_CALL_BY_REFERENCE
50   x = *px;
51 #endif
52   // unpack arguments, check for NaN or Infinity
53   if (!unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x)) {
54     // x is Inf. or NaN
55 #ifdef SET_STATUS_FLAGS
56       __set_status_flags (pfpsf, INVALID_EXCEPTION);
57 #endif
58       BID_RETURN (0x80000000);
59   }
60   // find number of digits in coefficient
61   if (coefficient_x >= 1000000000000000ull) {
62     digits = 16;
63   } else {
64     dx.d = (double)coefficient_x;   // exact conversion;
65     bin_expon_cx = (int)(dx.i >> 52) - 1023;
66     digits = estimate_decimal_digits[bin_expon_cx];
67     if (coefficient_x >= power10_table_128[digits].w[0])
68       digits++;
69   }
70   exponent_x = exponent_x - DECIMAL_EXPONENT_BIAS + digits - 1;
71
72   BID_RETURN (exponent_x);
73 }