1 /* Assembly support functions for libgcc.
3 * Copyright
(C
) 1997 Free Software Foundation
, Inc.
4 * Contributed by Cygnus Support
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
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
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.
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.
35 /* For division
, we use the following
algorithm:
38 * __divsi3
(unsigned a
, unsigned b
)
45 * for (i = 32; i > 0; i--)
47 * ah = (ah << 1) | (al >> 31);
48 * tmpf = (ah >= b) ? 1 : 0;
49 * ah -= ((tmpf) ? b : 0);
50 * al = (al << 1) | tmpf;
53 * return
al; // for __udivsi3
54 * return
ah; // for __umodsi3
62 .
type __umodsi3
,@function
63 .
type __udivsi3
,@function
64 .stabs
"libgcc1.asm",100,0,0,__umodsi3
65 .stabs
"int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0
66 .stabs
"__umodsi3:F(0,1)",36,0,1,__umodsi3
67 .stabs
"a:P(0,1)",64,0,1,2
68 .stabs
"b:P(0,1)",64,0,1,3
71 bra.s .Lmerge || orfg f1
,f1
,1 ; indicate this is __umodsi3
73 .
size __umodsi3
,.Lumod
-__umodsi3
74 .stabs
"",36,0,0,.Lumod
-__umodsi3
76 .stabs
"__udivsi3:F(0,1)",36,0,1,__udivsi3
77 .stabs
"a:P(0,1)",64,0,1,2
78 .stabs
"b:P(0,1)",64,0,1,3
80 andfg f1
,f1
,0 ||
nop ; indicate this is __udivsi3
88 ; f1 = 1 if this is mod, 0 if this is div
89 or r4
,r0
,0 ||
sub r5
,r0
,-32 ; ah = 0, loop = 32
92 src r4
,r2
,-1 ||
sub r5
,r5
,1 ; ah = (ah << 1) | (al >> 31); decrement loop count
93 cmpuge f0
,r4
,r3 || sra r2
,r2
,-1 ; f0 = (ah >= b); al <<= 1
94 sub/tx r4
,r4
,r3 ||
or/tx r2
,r2
,1 ; ah -= (tmpf) ? b : 0; al |= tmpf
95 bratnz.s r5
,.Lloop ||
nop ; loop back if not done
96 jmp link ||
or/xt r2
,r0
,r4
; if mod, update register, then return to user
98 .
size __udivsi3
,.Ludiv
-__udivsi3
99 .stabs
"",36,0,0,.Ludiv
-__udivsi3
101 #endif
/* L_udivsi3
*/
106 /* For division
, we use the following
algorithm:
109 * __divsi3
(unsigned a
, unsigned b
)
111 * unsigned al = __builtin_abs (a);
112 * unsigned b2 = __builtin_abs (b);
117 * for (i = 32; i > 0; i--)
119 * ah = (ah << 1) | (al >> 31);
120 * tmpf = (ah >= b2) ? 1 : 0;
121 * ah -= ((tmpf) ? b2 : 0);
122 * al = (al << 1) | tmpf;
126 * ah = -ah, al = -al;
131 * return
al; // for __divsi3
132 * return
ah; // for __modsi3
140 .
type __modsi3
,@function
141 .
type __divsi3
,@function
142 .stabs
"libgcc1.asm",100,0,0,__modsi3
143 .stabs
"int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0
144 .stabs
"__modsi3:F(0,1)",36,0,1,__modsi3
145 .stabs
"a:P(0,1)",64,0,1,2
146 .stabs
"b:P(0,1)",64,0,1,3
149 bra.s .Lmerge || orfg f1
,f1
,1 ; indicate this is __modsi3
151 .
size __modsi3
,.Lmod
-__modsi3
152 .stabs
"",36,0,0,.Lmod
-__modsi3
154 .stabs
"__divsi3:F(0,1)",36,0,1,__divsi3
155 .stabs
"a:P(0,1)",64,0,1,2
156 .stabs
"b:P(0,1)",64,0,1,3
158 andfg f1
,f1
,0 ||
nop ; indicate this is __divsi3
168 ; f1 = 1 if this is mod, 0 if this is div
169 or r6
,r0
,r2 ||
or r7
,r0
,r3
; copy original inputs
170 abs r2
,r2 || abs r3
,r3
; make both postive
171 or r4
,r0
,0 ||
sub r5
,r0
,-32 ; ah = 0, loop = 32
174 src r4
,r2
,-1 ||
sub r5
,r5
,1 ; ah = (ah << 1) | (al >> 31); decrement loop count
175 cmpuge f0
,r4
,r3 || sra r2
,r2
,-1 ; f0 = (ah >= b); al <<= 1
176 sub/tx r4
,r4
,r3 ||
or/tx r2
,r2
,1 ; ah -= (tmpf) ? b : 0; al |= tmpf
177 bratnz.s r5
,.Lloop ||
nop ; loop back if not done
178 cmplt f0
,r6
,0 ||
nop ; f0 = (a < 0)
180 sub/tx r2
,r0
,r2 ||
sub/tx r4
,r0
,r4
; negate both al, ah if (a < 0)
181 cmplt f0
,r7
,0 -> sub/tx r2
,r0
,r2
; negate al if (b < 0)
182 jmp link ||
or/xt r2
,r0
,r4
; update result if mod; return to user
184 .
size __divsi3
,.Ldiv
-__divsi3
185 .stabs
"",36,0,0,.Ldiv
-__divsi3
187 #endif
/* L_divsi3
*/