2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / config / mips / _tilib.c
blob25e326c86da5335dde619ad78510a09ac545f174
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>
5 This file is part of GCC.
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.
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.
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. */
23 #include "tconfig.h"
24 #include "coretypes.h"
25 #include "tm.h"
27 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
29 typedef int TItype __attribute__ ((mode (TI)));
30 typedef int DItype __attribute__ ((mode (DI)));
31 typedef int SItype __attribute__ ((mode (SI)));
33 typedef unsigned int UDItype __attribute__ ((mode (DI)));
35 typedef union
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;
47 TItype __negti2 (TItype);
48 TItype __ashlti3 (TItype, int);
49 #if 0
50 TItype __ashrti3 (TItype, int);
51 #endif
52 TItype __lshrti3 (TItype, int);
54 TItype
55 __negti2 (TItype u)
57 TIunion w;
58 TIunion uu;
60 uu.ll = u;
62 w.s.low = -uu.s.low;
63 w.s.high = -uu.s.high - ((UDItype) w.s.low > 0);
65 return w.ll;
68 TItype
69 __ashlti3 (TItype u, int b)
71 TIunion w;
72 int bm;
73 TIunion uu;
75 if (b == 0)
76 return u;
78 uu.ll = u;
80 bm = (sizeof (DItype) * BITS_PER_UNIT) - b;
81 if (bm <= 0)
83 w.s.low = 0;
84 w.s.high = (UDItype) uu.s.low << -bm;
86 else
88 UDItype carries = (UDItype) uu.s.low >> bm;
90 w.s.low = (UDItype) uu.s.low << b;
91 w.s.high = ((UDItype) uu.s.high << b) | carries;
94 return w.ll;
97 #if 0
98 TItype
99 __ashrti3 (TItype u, int b)
101 TIunion w;
102 int bm;
103 TIunion uu;
105 if (b == 0)
106 return u;
108 uu.ll = u;
110 bm = (sizeof (DItype) * BITS_PER_UNIT) - b;
111 if (bm <= 0)
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;
117 else
119 UDItype carries = (UDItype) uu.s.high << bm;
121 w.s.high = uu.s.high >> b;
122 w.s.low = ((UDItype) uu.s.low >> b) | carries;
125 return w.ll;
127 #endif
129 TItype
130 __lshrti3 (TItype u, int b)
132 TIunion w;
133 int bm;
134 TIunion uu;
136 if (b == 0)
137 return u;
139 uu.ll = u;
141 bm = (sizeof (DItype) * BITS_PER_UNIT) - b;
142 if (bm <= 0)
144 w.s.high = 0;
145 w.s.low = (UDItype) uu.s.high >> -bm;
147 else
149 UDItype carries = (UDItype) uu.s.high << bm;
151 w.s.high = (UDItype) uu.s.high >> b;
152 w.s.low = ((UDItype) uu.s.low >> b) | carries;
155 return w.ll;
158 #endif /* N32 or N64 */