Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / i386 / gnu / fpemul / reg_norm.s
1 /*
2  *  reg_norm.s
3  *
4  * Normalize the value in a FPU_REG.
5  *
6  * Call from C as:
7  *   void normalize(FPU_REG *n)
8  *
9  *   void normalize_nuo(FPU_REG *n)
10  *
11  *
12  * Copyright (C) 1992,1993,1994
13  *                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
14  *                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au
15  * All rights reserved.
16  *
17  * This copyright notice covers the redistribution and use of the
18  * FPU emulator developed by W. Metzenthen. It covers only its use
19  * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
20  * use is not permitted under this copyright.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the above copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must include information specifying
28  *    that source code for the emulator is freely available and include
29  *    either:
30  *      a) an offer to provide the source code for a nominal distribution
31  *         fee, or
32  *      b) list at least two alternative methods whereby the source
33  *         can be obtained, e.g. a publically accessible bulletin board
34  *         and an anonymous ftp site from which the software can be
35  *         downloaded.
36  * 3. All advertising materials specifically mentioning features or use of
37  *    this emulator must acknowledge that it was developed by W. Metzenthen.
38  * 4. The name of W. Metzenthen may not be used to endorse or promote
39  *    products derived from this software without specific prior written
40  *    permission.
41  *
42  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
43  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
44  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
45  * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
46  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
47  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
48  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
49  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
50  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
51  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52  *
53  *
54  * The purpose of this copyright, based upon the Berkeley copyright, is to
55  * ensure that the covered software remains freely available to everyone.
56  *
57  * The software (with necessary differences) is also available, but under
58  * the terms of the GNU copyleft, for the Linux operating system and for
59  * the djgpp ms-dos extender.
60  *
61  * W. Metzenthen   June 1994.
62  *
63  *
64  * $FreeBSD: src/sys/gnu/i386/fpemul/reg_norm.s,v 1.8 1999/08/28 00:42:57 peter Exp $
65  * $DragonFly: src/sys/i386/gnu/fpemul/Attic/reg_norm.s,v 1.2 2003/06/17 04:28:34 dillon Exp $
66  *
67  */
68
69
70 #include <gnu/i386/fpemul/fpu_asm.h>
71
72
73 .text
74
75 ENTRY(normalize)
76         pushl   %ebp
77         movl    %esp,%ebp
78         pushl   %ebx
79
80         movl    PARAM1,%ebx
81
82         movl    SIGH(%ebx),%edx
83         movl    SIGL(%ebx),%eax
84
85         orl     %edx,%edx       /* ms bits */
86         js      L_done          /* Already normalized */
87         jnz     L_shift_1       /* Shift left 1 - 31 bits */
88
89         orl     %eax,%eax
90         jz      L_zero          /* The contents are zero */
91
92 /* L_shift_32: */
93         movl    %eax,%edx
94         xorl    %eax,%eax
95         subl    $32,EXP(%ebx)   /* This can cause an underflow */
96
97 /* We need to shift left by 1 - 31 bits */
98 L_shift_1:
99         bsrl    %edx,%ecx       /* get the required shift in %ecx */
100         subl    $31,%ecx
101         negl    %ecx
102         shld    %cl,%eax,%edx
103         shl     %cl,%eax
104         subl    %ecx,EXP(%ebx)  /* This can cause an underflow */
105
106         movl    %edx,SIGH(%ebx)
107         movl    %eax,SIGL(%ebx)
108
109 L_done:
110         cmpl    EXP_OVER,EXP(%ebx)
111         jge     L_overflow
112
113         cmpl    EXP_UNDER,EXP(%ebx)
114         jle     L_underflow
115
116 L_exit:
117         popl    %ebx
118         leave
119         ret
120
121
122 L_zero:
123         movl    EXP_UNDER,EXP(%ebx)
124         movb    TW_Zero,TAG(%ebx)
125         jmp     L_exit
126
127 L_underflow:
128         push    %ebx
129         call    _arith_underflow
130         pop     %ebx
131         jmp     L_exit
132
133 L_overflow:
134         push    %ebx
135         call    _arith_overflow
136         pop     %ebx
137         jmp     L_exit
138
139
140
141 /* Normalise without reporting underflow or overflow */
142 ENTRY(normalize_nuo)
143         pushl   %ebp
144         movl    %esp,%ebp
145         pushl   %ebx
146
147         movl    PARAM1,%ebx
148
149         movl    SIGH(%ebx),%edx
150         movl    SIGL(%ebx),%eax
151
152         orl     %edx,%edx       /* ms bits */
153         js      L_exit          /* Already normalized */
154         jnz     L_nuo_shift_1   /* Shift left 1 - 31 bits */
155
156         orl     %eax,%eax
157         jz      L_zero          /* The contents are zero */
158
159 /* L_nuo_shift_32: */
160         movl    %eax,%edx
161         xorl    %eax,%eax
162         subl    $32,EXP(%ebx)   /* This can cause an underflow */
163
164 /* We need to shift left by 1 - 31 bits */
165 L_nuo_shift_1:
166         bsrl    %edx,%ecx       /* get the required shift in %ecx */
167         subl    $31,%ecx
168         negl    %ecx
169         shld    %cl,%eax,%edx
170         shl     %cl,%eax
171         subl    %ecx,EXP(%ebx)  /* This can cause an underflow */
172
173         movl    %edx,SIGH(%ebx)
174         movl    %eax,SIGL(%ebx)
175         jmp     L_exit
176
177