udiv.S revision 1.1 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.1 christos #if defined(LIBC_SCCS) && !defined(lint)
34 1.1 christos /* .asciz "@(#)udiv.s 8.1 (Berkeley) 6/4/93" */
35 1.1 christos .asciz "$NetBSD: udiv.S,v 1.1 2005/12/20 19:28:50 christos Exp $"
36 1.1 christos #endif /* LIBC_SCCS and not lint */
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 #include "DEFS.h"
45 1.1 christos
46 1.1 christos #define DIVIDEND 4(%ap)
47 1.1 christos #define DIVISOR 8(%ap)
48 1.1 christos
49 1.1 christos #ifdef __ELF__
50 1.1 christos ASENTRY(__udiv,0)
51 1.1 christos #else
52 1.1 christos ASENTRY(udiv,0)
53 1.1 christos #endif
54 1.1 christos movl DIVISOR,%r2
55 1.1 christos jlss Leasy # big divisor: settle by comparison
56 1.1 christos movl DIVIDEND,%r0
57 1.1 christos jlss Lhard # big dividend: extended division
58 1.1 christos divl2 %r2,%r0 # small divisor and dividend: signed division
59 1.1 christos ret
60 1.1 christos Lhard:
61 1.1 christos clrl %r1
62 1.1 christos ediv %r2,%r0,%r0,%r1
63 1.1 christos ret
64 1.1 christos Leasy:
65 1.1 christos cmpl DIVIDEND,%r2
66 1.1 christos jgequ Lone # if dividend is as big or bigger, return 1
67 1.1 christos clrl %r0 # else return 0
68 1.1 christos ret
69 1.1 christos Lone:
70 1.1 christos movl $1,%r0
71 1.1 christos ret
72 1.1 christos
73 1.1 christos #ifdef __ELF__
74 1.1 christos ASENTRY(__audiv,0)
75 1.1 christos #else
76 1.1 christos ASENTRY(audiv,0)
77 1.1 christos #endif
78 1.1 christos movl DIVIDEND,%r3
79 1.1 christos movl DIVISOR,%r2
80 1.1 christos jlss La_easy # big divisor: settle by comparison
81 1.1 christos movl (%r3),%r0
82 1.1 christos jlss La_hard # big dividend: extended division
83 1.1 christos divl2 %r2,%r0 # small divisor and dividend: signed division
84 1.1 christos movl %r0,(%r3) # leave the value of the assignment in %r0
85 1.1 christos ret
86 1.1 christos La_hard:
87 1.1 christos clrl %r1
88 1.1 christos ediv %r2,%r0,%r0,%r1
89 1.1 christos movl %r0,(%r3)
90 1.1 christos ret
91 1.1 christos La_easy:
92 1.1 christos cmpl (%r3),%r2
93 1.1 christos jgequ La_one # if dividend is as big or bigger, return 1
94 1.1 christos clrl %r0 # else return 0
95 1.1 christos clrl (%r3)
96 1.1 christos ret
97 1.1 christos La_one:
98 1.1 christos movl $1,%r0
99 1.1 christos movl %r0,(%r3)
100 1.1 christos ret
101