OSDN Git Service

* c-decl.c, config/m32r/m32r.c, expr.c, optabs.c: Don't check
[pf3gnuchains/gcc-fork.git] / gcc / config / mips / _tilib.c
1 /* A few TImode functions needed for TFmode emulated arithmetic.
2    Copyright 2002, 2003 Free Software Foundation, Inc.
3    Contributed by Alexandre Oliva <aoliva@redhat.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #include "tconfig.h"
24 #include "coretypes.h"
25 #include "tm.h"
26
27 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
28
29 typedef int TItype __attribute__ ((mode (TI)));
30 typedef int DItype __attribute__ ((mode (DI)));
31 typedef int SItype __attribute__ ((mode (SI)));
32
33 typedef unsigned int UDItype __attribute__ ((mode (DI)));
34
35 typedef union
36 {
37   struct TIstruct {
38 #if LIBGCC2_WORDS_BIG_ENDIAN
39     DItype high, low;
40 #else
41     DItype low, high;
42 #endif
43   } s;
44   TItype ll;
45 } TIunion;
46
47 TItype __negti2 (TItype);
48 TItype __ashlti3 (TItype, int);
49 #if 0
50 TItype __ashrti3 (TItype, int);
51 #endif
52 TItype __lshrti3 (TItype, int);
53
54 TItype
55 __negti2 (TItype u)
56 {
57   TIunion w;
58   TIunion uu;
59
60   uu.ll = u;
61
62   w.s.low = -uu.s.low;
63   w.s.high = -uu.s.high - ((UDItype) w.s.low > 0);
64
65   return w.ll;
66 }
67
68 TItype
69 __ashlti3 (TItype u, int b)
70 {
71   TIunion w;
72   int bm;
73   TIunion uu;
74
75   if (b == 0)
76     return u;
77
78   uu.ll = u;
79
80   bm = (sizeof (DItype) * BITS_PER_UNIT) - b;
81   if (bm <= 0)
82     {
83       w.s.low = 0;
84       w.s.high = (UDItype) uu.s.low << -bm;
85     }
86   else
87     {
88       UDItype carries = (UDItype) uu.s.low >> bm;
89
90       w.s.low = (UDItype) uu.s.low << b;
91       w.s.high = ((UDItype) uu.s.high << b) | carries;
92     }
93
94   return w.ll;
95 }
96
97 #if 0
98 TItype
99 __ashrti3 (TItype u, int b)
100 {
101   TIunion w;
102   int bm;
103   TIunion uu;
104
105   if (b == 0)
106     return u;
107
108   uu.ll = u;
109
110   bm = (sizeof (DItype) * BITS_PER_UNIT) - b;
111   if (bm <= 0)
112     {
113       /* w.s.high = 1..1 or 0..0 */
114       w.s.high = uu.s.high >> (sizeof (DItype) * BITS_PER_UNIT - 1);
115       w.s.low = uu.s.high >> -bm;
116     }
117   else
118     {
119       UDItype carries = (UDItype) uu.s.high << bm;
120
121       w.s.high = uu.s.high >> b;
122       w.s.low = ((UDItype) uu.s.low >> b) | carries;
123     }
124
125   return w.ll;
126 }
127 #endif
128
129 TItype
130 __lshrti3 (TItype u, int b)
131 {
132   TIunion w;
133   int bm;
134   TIunion uu;
135
136   if (b == 0)
137     return u;
138
139   uu.ll = u;
140
141   bm = (sizeof (DItype) * BITS_PER_UNIT) - b;
142   if (bm <= 0)
143     {
144       w.s.high = 0;
145       w.s.low = (UDItype) uu.s.high >> -bm;
146     }
147   else
148     {
149       UDItype carries = (UDItype) uu.s.high << bm;
150
151       w.s.high = (UDItype) uu.s.high >> b;
152       w.s.low = ((UDItype) uu.s.low >> b) | carries;
153     }
154
155   return w.ll;
156 }
157
158 #endif /* N32 or N64 */