* real.c: Avoid parse error if FLOAT_WORDS_BIG_ENDIAN is
[official-gcc.git] / gcc / config / d30v / libgcc1.asm
blobed359fc552ec8d0fa1deb99f24db8bd00d5d540a
1 /* Assembly support functions for libgcc.
3 * Copyright (C) 1997 Free Software Foundation, Inc.
4 * Contributed by Cygnus Support
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.
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.)
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.
33 #ifdef L_udivsi3
35 /* For division, we use the following algorithm:
37 * unsigned
38 * __divsi3 (unsigned a, unsigned b)
39 * {
40 * unsigned al = a;
41 * unsigned ah = 0;
42 * unsigned tmpf;
43 * int i;
45 * for (i = 32; i > 0; i--)
46 * {
47 * ah = (ah << 1) | (al >> 31);
48 * tmpf = (ah >= b) ? 1 : 0;
49 * ah -= ((tmpf) ? b : 0);
50 * al = (al << 1) | tmpf;
51 * }
53 * return al; // for __udivsi3
54 * return ah; // for __umodsi3
55 * }
58 .file "_udivsi3"
59 .text
60 .globl __umodsi3
61 .globl __udivsi3
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
70 __umodsi3:
71 bra.s .Lmerge || orfg f1,f1,1 ; indicate this is __umodsi3
72 .Lumod:
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
79 __udivsi3:
80 andfg f1,f1,0 || nop ; indicate this is __udivsi3
82 .Lmerge:
83 ; r2 = al
84 ; r3 = b
85 ; r4 = ah
86 ; r5 = loop counter
87 ; f0 = tmpf
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
91 .Lloop:
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
97 .Ludiv:
98 .size __udivsi3,.Ludiv-__udivsi3
99 .stabs "",36,0,0,.Ludiv-__udivsi3
101 #endif /* L_udivsi3 */
104 #ifdef L_divsi3
106 /* For division, we use the following algorithm:
108 * unsigned
109 * __divsi3 (unsigned a, unsigned b)
111 * unsigned al = __builtin_abs (a);
112 * unsigned b2 = __builtin_abs (b);
113 * unsigned ah = 0;
114 * unsigned tmpf;
115 * int i;
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;
125 * if (a < 0)
126 * ah = -ah, al = -al;
128 * if (b < 0)
129 * al = -al;
131 * return al; // for __divsi3
132 * return ah; // for __modsi3
136 .file "_divsi3"
137 .text
138 .globl __modsi3
139 .globl __divsi3
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
148 __modsi3:
149 bra.s .Lmerge || orfg f1,f1,1 ; indicate this is __modsi3
150 .Lmod:
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
157 __divsi3:
158 andfg f1,f1,0 || nop ; indicate this is __divsi3
160 .Lmerge:
161 ; r2 = al
162 ; r3 = b2
163 ; r4 = ah
164 ; r5 = loop counter
165 ; r6 = a
166 ; r7 = b
167 ; f0 = tmpf
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
173 .Lloop:
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
183 .Ldiv:
184 .size __divsi3,.Ldiv-__divsi3
185 .stabs "",36,0,0,.Ldiv-__divsi3
187 #endif /* L_divsi3 */