1 ; libgcc routines for ARC cpu.
3 /* Copyright (C) 1995, 1997,2004, 2009 Free Software Foundation, Inc.
5 This file is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any
10 This file is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
33 /* This the simple version.
43 mov r2,0 ; Accumulate result here.
45 sub.f 0,r0,0 ; while (a)
48 and.f 0,r0,1 ; if (a & 1)
49 add.nz r2,r2,r1 ; r += b
69 /* This the simple version.
79 mov r2,0 ; Top part of b.
80 mov r3,0 ; Accumulate result here.
83 sub.f 0,r0,0 ; while (a)
86 and.f 0,r0,1 ; if (a & 1)
90 add.f r4,r4,r1 ; r += b
109 #endif /* L_umulsidi3 */
111 #ifdef L_divmod_tools
113 ; Utilities used by all routines.
118 ; inputs: r0 = numerator, r1 = denominator
119 ; outputs: positive r0/r1,
120 ; r6.bit1 = sign of numerator, r6.bit0 = sign of result
124 mov r6,0 ; keep sign in r6
125 sub.f 0,r0,0 ; is numerator -ve?
126 sub.lt r0,0,r0 ; negate numerator
127 mov.lt r6,3 ; sign is -ve
128 sub.f 0,r1,0 ; is denominator -ve?
129 sub.lt r1,0,r1 ; negate denominator
130 xor.lt r6,r6,1 ; toggle sign
135 udivmodsi4(int modwanted, unsigned long num, unsigned long den)
137 unsigned long bit = 1;
138 unsigned long res = 0;
140 while (den < num && bit && !(den & (1L<<31)))
155 if (modwanted) return num;
160 ; inputs: r0 = numerator, r1 = denominator
161 ; outputs: r0 = quotient, r1 = remainder, r2/r3 trashed
163 .global ___udivmodsi4
168 sub.f 0,r1,r0 ; while (den < num
171 sub.f 0,r2,0 ; && bit
174 lsl.f 0,r1 ; && !(den & (1<<31))
177 lsl r1,r1 ; den <<= 1
179 lsl r2,r2 ; bit <<= 1
181 sub.f 0,r2,0 ; while (bit)
184 sub.f 0,r0,r1 ; if (num >= den)
187 sub r0,r0,r1 ; num -= den
188 or r3,r3,r2 ; res |= bit
190 lsr r2,r2 ; bit >>= 1
192 lsr r1,r1 ; den >>= 1
213 #endif /* L_udivsi3 */
227 sub.nz r0,0,r0 ; cannot go in delay slot, has limm value
231 #endif /* L_divsi3 */
247 #endif /* L_umodsi3 */
266 #endif /* L_modsi3 */