OSDN Git Service

7bdc161215c2e68d58f72d8c1de348bcd12afdf8
[pf3gnuchains/gcc-fork.git] / gcc / config / arm / bpabi.c
1 /* Miscellaneous BPABI functions.
2
3    Copyright (C) 2003, 2004  Free Software Foundation, Inc.
4    Contributed by CodeSourcery, LLC.
5
6    This file is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any
9    later version.
10
11    In addition to the permissions in the GNU General Public License, the
12    Free Software Foundation gives you unlimited permission to link the
13    compiled version of this file into combinations with other programs,
14    and to distribute those combinations without any restriction coming
15    from the use of this file.  (The General Public License restrictions
16    do apply in other respects; for example, they cover modification of
17    the file, and distribution when not linked into a combine
18    executable.)
19
20    This file is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; see the file COPYING.  If not, write to
27    the Free Software Foundation, 59 Temple Place - Suite 330,
28    Boston, MA 02111-1307, USA.  */
29
30 extern double __aeabi_ul2d (unsigned long long);
31 extern float __aeabi_ul2f (unsigned long long);
32 extern long long __divdi3 (long long, long long);
33 extern unsigned long long __udivdi3 (unsigned long long, 
34                                      unsigned long long);
35 extern long long __gnu_ldivmod_helper (long long, long long, long long *);
36 extern unsigned long long __gnu_uldivmod_helper (unsigned long long, 
37                                                  unsigned long long, 
38                                                  unsigned long long *);
39
40 /* These functions are based on __floatdidf and __floatdisf, but
41    convert unsigned DImode values instead of signed DImode
42    values.  */
43
44 #define WORD_SIZE (sizeof (int) * 8)
45 #define HIGH_HALFWORD_COEFF (((unsigned long long) 1) << (WORD_SIZE / 2))
46 #define HIGH_WORD_COEFF (((unsigned long long) 1) << WORD_SIZE)
47
48 double
49 __aeabi_ul2d (unsigned long long u)
50 {
51   double d = (unsigned) (u >> WORD_SIZE);
52   d *= HIGH_HALFWORD_COEFF;
53   d *= HIGH_HALFWORD_COEFF;
54   d += (unsigned) (u & (HIGH_WORD_COEFF - 1));
55
56   return d;
57 }
58
59 float
60 __aeabi_ul2f (unsigned long long u)
61 {
62   /* Do the calculation in DFmode so that we don't lose any of the
63      precision of the high word while multiplying it.  */
64   double f = (unsigned) (u >> WORD_SIZE);
65   f *= HIGH_HALFWORD_COEFF;
66   f *= HIGH_HALFWORD_COEFF;
67   f += (unsigned) (u & (HIGH_WORD_COEFF - 1));
68
69   return (float) f;
70 }
71
72 long long
73 __gnu_ldivmod_helper (long long a, 
74                       long long b, 
75                       long long *remainder)
76 {
77   long long quotient;
78
79   quotient = __divdi3 (a, b);
80   *remainder = a - b * quotient;
81   return quotient;
82 }
83
84 unsigned long long
85 __gnu_uldivmod_helper (unsigned long long a, 
86                        unsigned long long b,
87                        unsigned long long *remainder)
88 {
89   unsigned long long quotient;
90
91   quotient = __udivdi3 (a, b);
92   *remainder = a - b * quotient;
93   return quotient;
94 }