udiv.S revision 1.3 1 1.1 christos /*-
2 1.1 christos * Copyright (c) 1991, 1993
3 1.1 christos * The Regents of the University of California. All rights reserved.
4 1.1 christos *
5 1.1 christos * This code is derived from software contributed to Berkeley by
6 1.1 christos * Donn Seeley at UUNET Technologies, Inc.
7 1.1 christos *
8 1.1 christos * Redistribution and use in source and binary forms, with or without
9 1.1 christos * modification, are permitted provided that the following conditions
10 1.1 christos * are met:
11 1.1 christos * 1. Redistributions of source code must retain the above copyright
12 1.1 christos * notice, this list of conditions and the following disclaimer.
13 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer in the
15 1.1 christos * documentation and/or other materials provided with the distribution.
16 1.1 christos * 3. Neither the name of the University nor the names of its contributors
17 1.1 christos * may be used to endorse or promote products derived from this software
18 1.1 christos * without specific prior written permission.
19 1.1 christos *
20 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1 christos * SUCH DAMAGE.
31 1.1 christos */
32 1.1 christos
33 1.3 matt #include <machine/asm.h>
34 1.3 matt
35 1.1 christos /* .asciz "@(#)udiv.s 8.1 (Berkeley) 6/4/93" */
36 1.3 matt RCSID("$NetBSD: udiv.S,v 1.3 2011/01/25 04:45:28 matt Exp $")
37 1.1 christos
38 1.1 christos /*
39 1.1 christos * Unsigned division, PCC flavor.
40 1.1 christos * udiv() takes an ordinary dividend/divisor pair;
41 1.1 christos * audiv() takes a pointer to a dividend and an ordinary divisor.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #define DIVIDEND 4(%ap)
45 1.1 christos #define DIVISOR 8(%ap)
46 1.1 christos
47 1.1 christos ASENTRY(__udiv,0)
48 1.1 christos movl DIVISOR,%r2
49 1.1 christos jlss Leasy # big divisor: settle by comparison
50 1.1 christos movl DIVIDEND,%r0
51 1.1 christos jlss Lhard # big dividend: extended division
52 1.1 christos divl2 %r2,%r0 # small divisor and dividend: signed division
53 1.1 christos ret
54 1.1 christos Lhard:
55 1.1 christos clrl %r1
56 1.1 christos ediv %r2,%r0,%r0,%r1
57 1.1 christos ret
58 1.1 christos Leasy:
59 1.1 christos cmpl DIVIDEND,%r2
60 1.1 christos jgequ Lone # if dividend is as big or bigger, return 1
61 1.1 christos clrl %r0 # else return 0
62 1.1 christos ret
63 1.1 christos Lone:
64 1.1 christos movl $1,%r0
65 1.1 christos ret
66 1.3 matt END(__udiv)
67 1.1 christos
68 1.1 christos ASENTRY(__audiv,0)
69 1.1 christos movl DIVIDEND,%r3
70 1.1 christos movl DIVISOR,%r2
71 1.1 christos jlss La_easy # big divisor: settle by comparison
72 1.1 christos movl (%r3),%r0
73 1.1 christos jlss La_hard # big dividend: extended division
74 1.1 christos divl2 %r2,%r0 # small divisor and dividend: signed division
75 1.1 christos movl %r0,(%r3) # leave the value of the assignment in %r0
76 1.1 christos ret
77 1.1 christos La_hard:
78 1.1 christos clrl %r1
79 1.1 christos ediv %r2,%r0,%r0,%r1
80 1.1 christos movl %r0,(%r3)
81 1.1 christos ret
82 1.1 christos La_easy:
83 1.1 christos cmpl (%r3),%r2
84 1.1 christos jgequ La_one # if dividend is as big or bigger, return 1
85 1.1 christos clrl %r0 # else return 0
86 1.1 christos clrl (%r3)
87 1.1 christos ret
88 1.1 christos La_one:
89 1.1 christos movl $1,%r0
90 1.1 christos movl %r0,(%r3)
91 1.1 christos ret
92 1.3 matt END(__audiv)
93