/* libgcc1 routines for 68000 w/o floating-point hardware.1Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.23This file is part of GNU CC.45GNU CC is free software; you can redistribute it and/or modify it6under the terms of the GNU General Public License as published by the7Free Software Foundation; either version 2, or (at your option) any8later version.910In addition to the permissions in the GNU General Public License, the11Free Software Foundation gives you unlimited permission to link the12compiled version of this file with other programs, and to distribute13those programs without any restriction coming from the use of this14file. (The General Public License restrictions do apply in other15respects; for example, they cover modification of the file, and16distribution when not linked into another program.)1718This file is distributed in the hope that it will be useful, but19WITHOUT ANY WARRANTY; without even the implied warranty of20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU21General Public License for more details.2223You should have received a copy of the GNU General Public License24along with this program; see the file COPYING. If not, write to25the Free Software Foundation, 59 Temple Place - Suite 330,26Boston, MA 02111-1307, USA. */2728/* As a special exception, if you link this library with files29compiled with GCC to produce an executable, this does not cause30the resulting executable to be covered by the GNU General Public License.31This exception does not however invalidate any other reasons why32the executable file might be covered by the GNU General Public License. */3334/* Use this one for any 680x0; assumes no floating point hardware.35The trailing " '" appearing on some lines is for ANSI preprocessors. Yuk.36Some of this code comes from MINIX, via the folks at ericsson.37D. V. Henkel-Wallace ([email protected]) Fete Bastille, 199238*/3940/* These are predefined by new versions of GNU cpp. */4142#ifndef __USER_LABEL_PREFIX__43#define __USER_LABEL_PREFIX__ _44#endif4546#ifndef __REGISTER_PREFIX__47#define __REGISTER_PREFIX__48#endif4950#ifndef __IMMEDIATE_PREFIX__51#define __IMMEDIATE_PREFIX__ #52#endif5354/* ANSI concatenation macros. */5556#define CONCAT1(a, b) CONCAT2(a, b)57#define CONCAT2(a, b) a ## b5859/* Use the right prefix for global labels. */6061#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)6263/* Use the right prefix for registers. */6465#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)6667/* Use the right prefix for immediate values. */6869#define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)7071#define d0 REG (d0)72#define d1 REG (d1)73#define d2 REG (d2)74#define d3 REG (d3)75#define d4 REG (d4)76#define d5 REG (d5)77#define d6 REG (d6)78#define d7 REG (d7)79#define a0 REG (a0)80#define a1 REG (a1)81#define a2 REG (a2)82#define a3 REG (a3)83#define a4 REG (a4)84#define a5 REG (a5)85#define a6 REG (a6)86#define fp REG (fp)87#define sp REG (sp)8889.text90.proc91.globl SYM (__udivsi3)92SYM (__udivsi3):93#if !(defined(__mcf5200__) || defined(__mcoldfire__))94movel d2, sp@-95movel sp@(12), d1 /* d1 = divisor */96movel sp@(8), d0 /* d0 = dividend */9798cmpl IMM (0x10000), d1 /* divisor >= 2 ^ 16 ? */99jcc L3 /* then try next algorithm */100movel d0, d2101clrw d2102swap d2103divu d1, d2 /* high quotient in lower word */104movew d2, d0 /* save high quotient */105swap d0106movew sp@(10), d2 /* get low dividend + high rest */107divu d1, d2 /* low quotient */108movew d2, d0109jra L6110111L3: movel d1, d2 /* use d2 as divisor backup */112L4: lsrl IMM (1), d1 /* shift divisor */113lsrl IMM (1), d0 /* shift dividend */114cmpl IMM (0x10000), d1 /* still divisor >= 2 ^ 16 ? */115jcc L4116divu d1, d0 /* now we have 16 bit divisor */117andl IMM (0xffff), d0 /* mask out divisor, ignore remainder */118119/* Multiply the 16 bit tentative quotient with the 32 bit divisor. Because of120the operand ranges, this might give a 33 bit product. If this product is121greater than the dividend, the tentative quotient was too large. */122movel d2, d1123mulu d0, d1 /* low part, 32 bits */124swap d2125mulu d0, d2 /* high part, at most 17 bits */126swap d2 /* align high part with low part */127tstw d2 /* high part 17 bits? */128jne L5 /* if 17 bits, quotient was too large */129addl d2, d1 /* add parts */130jcs L5 /* if sum is 33 bits, quotient was too large */131cmpl sp@(8), d1 /* compare the sum with the dividend */132jls L6 /* if sum > dividend, quotient was too large */133L5: subql IMM (1), d0 /* adjust quotient */134135L6: movel sp@+, d2136rts137138#else /* __mcf5200__ || __mcoldfire__ */139140/* Coldfire implementation of non-restoring division algorithm from141Hennessy & Patterson, Appendix A. */142link a6,IMM (-12)143moveml d2-d4,sp@144movel a6@(8),d0145movel a6@(12),d1146clrl d2 | clear p147moveq IMM (31),d4148L1: addl d0,d0 | shift reg pair (p,a) one bit left149addxl d2,d2150movl d2,d3 | subtract b from p, store in tmp.151subl d1,d3152jcs L2 | if no carry,153bset IMM (0),d0 | set the low order bit of a to 1,154movl d3,d2 | and store tmp in p.155L2: subql IMM (1),d4156jcc L1157moveml sp@,d2-d4 | restore data registers158unlk a6 | and return159rts160#endif /* __mcf5200__ || __mcoldfire__ */161162163164