]>
Commit | Line | Data |
---|---|---|
7acf4da6 DD |
1 | /* libgcc routines for MeP. |
2 | Copyright 2001, 2002, 2009 Free Software Foundation, Inc | |
3 | ||
4 | This file is free software; you can redistribute it and/or modify it | |
5 | under the terms of the GNU General Public License as published by the | |
6 | Free Software Foundation; either version 3 of the License, or (at your | |
7 | option) any later version. | |
8 | ||
9 | This file is distributed in the hope that it will be useful, but | |
10 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | General Public License for more details. | |
13 | ||
14 | Under Section 7 of GPL version 3, you are granted additional | |
15 | permissions described in the GCC Runtime Library Exception, version | |
16 | 3.1, as published by the Free Software Foundation. | |
17 | ||
18 | You should have received a copy of the GNU General Public License and | |
19 | a copy of the GCC Runtime Library Exception along with this program; | |
20 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
21 | <http://www.gnu.org/licenses/>. */ | |
22 | ||
23 | typedef int SItype __attribute__ ((mode (SI))); | |
24 | typedef unsigned int USItype __attribute__ ((mode (SI))); | |
25 | ||
26 | typedef int word_type __attribute__ ((mode (__word__))); | |
27 | ||
28 | USItype | |
29 | __mulsi3 (USItype a, USItype b) | |
30 | { | |
31 | USItype c = 0; | |
32 | ||
33 | while (a != 0) | |
34 | { | |
35 | if (a & 1) | |
36 | c += b; | |
37 | a >>= 1; | |
38 | b <<= 1; | |
39 | } | |
40 | ||
41 | return c; | |
42 | } | |
43 | ||
44 | ||
45 | ||
46 | USItype | |
47 | udivmodsi4(USItype num, USItype den, word_type modwanted) | |
48 | { | |
49 | USItype bit = 1; | |
50 | USItype res = 0; | |
51 | ||
52 | while (den < num && bit && !(den & (1L<<31))) | |
53 | { | |
54 | den <<=1; | |
55 | bit <<=1; | |
56 | } | |
57 | while (bit) | |
58 | { | |
59 | if (num >= den) | |
60 | { | |
61 | num -= den; | |
62 | res |= bit; | |
63 | } | |
64 | bit >>=1; | |
65 | den >>=1; | |
66 | } | |
67 | if (modwanted) return num; | |
68 | return res; | |
69 | } | |
70 | ||
71 | ||
72 | ||
73 | SItype | |
74 | __divsi3 (SItype a, SItype b) | |
75 | { | |
76 | word_type neg = 0; | |
77 | SItype res; | |
78 | ||
79 | if (a < 0) | |
80 | { | |
81 | a = -a; | |
82 | neg = !neg; | |
83 | } | |
84 | ||
85 | if (b < 0) | |
86 | { | |
87 | b = -b; | |
88 | neg = !neg; | |
89 | } | |
90 | ||
91 | res = udivmodsi4 (a, b, 0); | |
92 | ||
93 | if (neg) | |
94 | res = -res; | |
95 | ||
96 | return res; | |
97 | } | |
98 | ||
99 | ||
100 | ||
101 | SItype | |
102 | __modsi3 (SItype a, SItype b) | |
103 | { | |
104 | word_type neg = 0; | |
105 | SItype res; | |
106 | ||
107 | if (a < 0) | |
108 | { | |
109 | a = -a; | |
110 | neg = 1; | |
111 | } | |
112 | ||
113 | if (b < 0) | |
114 | b = -b; | |
115 | ||
116 | res = udivmodsi4 (a, b, 1); | |
117 | ||
118 | if (neg) | |
119 | res = -res; | |
120 | ||
121 | return res; | |
122 | } | |
123 | ||
124 | ||
125 | ||
126 | ||
127 | SItype | |
128 | __udivsi3 (SItype a, SItype b) | |
129 | { | |
130 | return udivmodsi4 (a, b, 0); | |
131 | } | |
132 | ||
133 | ||
134 | ||
135 | SItype | |
136 | __umodsi3 (SItype a, SItype b) | |
137 | { | |
138 | return udivmodsi4 (a, b, 1); | |
139 | } |