]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/alpha/ldiv.S
update from main archive 961105
[thirdparty/glibc.git] / sysdeps / alpha / ldiv.S
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 Contributed by Richard Henderson (rth@tamu.edu)
3
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA. */
20
21
22 #include <sysdep.h>
23
24 #ifdef __linux__
25 # include <asm/gentrap.h>
26 # include <asm/pal.h>
27 #else
28 # include <machine/pal.h>
29 #endif
30
31 .set noat
32
33 .align 4
34 .globl ldiv
35 .ent ldiv
36 ldiv:
37 .frame sp, 0, ra
38 #ifdef PROF
39 ldgp gp, 0(pv)
40 lda AT, _mcount
41 jsr AT, (AT), _mcount
42 .prologue 1
43 #else
44 .prologue 0
45 #endif
46
47 #define dividend t0
48 #define divisor t1
49 #define mask t2
50 #define quotient t3
51 #define modulus t4
52 #define tmp1 t5
53 #define tmp2 t6
54 #define compare t7
55
56 /* find correct sign for input to unsigned divide loop. */
57 mov a1, dividend # e0 :
58 mov a2, divisor # .. e1 :
59 negq a1, tmp1 # e0 :
60 negq a2, tmp2 # .. e1 :
61 cmovlt a1, tmp1, dividend # e0 :
62 cmovlt a2, tmp2, divisor # .. e1 :
63 beq a2, $divbyzero # e1 :
64 unop # :
65
66 /* shift divisor left. */
67 1: cmpult divisor, modulus, compare # e0 :
68 blt divisor, 2f # .. e1 :
69 addq divisor, divisor, divisor # e0 :
70 addq mask, mask, mask # .. e1 :
71 bne compare, 1b # e1 :
72 unop # :
73
74 /* start to go right again. */
75 2: addq quotient, mask, tmp2 # e1 :
76 srl mask, 1, mask # .. e0 :
77 cmpule divisor, modulus, compare # e0 :
78 subq modulus, divisor, tmp1 # .. e1 :
79 cmovne compare, tmp2, quotient # e1 :
80 srl divisor, 1, divisor # .. e0 :
81 cmovne compare, tmp1, modulus # e0 :
82 bne mask, 2b # .. e1 :
83
84 /* find correct sign for result. */
85 xor a1, a2, compare # e0 :
86 negq quotient, tmp1 # .. e1 :
87 negq modulus, tmp2 # e0 :
88 cmovlt compare, tmp1, quotient # .. e1 :
89 cmovlt a1, tmp2, modulus # e1 :
90
91 /* and store it away in the structure. */
92 9: stq quotient, 0(a0) # .. e0 :
93 mov a0, v0 # e1 :
94 stq modulus, 8(a0) # .. e0 :
95 ret # e1 :
96
97 $divbyzero:
98 mov a0, v0
99 lda a0, GEN_INTDIV
100 call_pal PAL_gentrap
101
102 /* if trap returns, return zero. */
103 stq zero, 0(v0)
104 stq zero, 8(v0)
105 ret
106
107 .end ldiv
108
109 weak_alias(ldiv, lldiv)