Initial import from FreeBSD RELENG_4:
[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  *
66  */
67
68
69 #include <gnu/i386/fpemul/fpu_asm.h>
70
71
72 .text
73
74 ENTRY(normalize)
75         pushl   %ebp
76         movl    %esp,%ebp
77         pushl   %ebx
78
79         movl    PARAM1,%ebx
80
81         movl    SIGH(%ebx),%edx
82         movl    SIGL(%ebx),%eax
83
84         orl     %edx,%edx       /* ms bits */
85         js      L_done          /* Already normalized */
86         jnz     L_shift_1       /* Shift left 1 - 31 bits */
87
88         orl     %eax,%eax
89         jz      L_zero          /* The contents are zero */
90
91 /* L_shift_32: */
92         movl    %eax,%edx
93         xorl    %eax,%eax
94         subl    $32,EXP(%ebx)   /* This can cause an underflow */
95
96 /* We need to shift left by 1 - 31 bits */
97 L_shift_1:
98         bsrl    %edx,%ecx       /* get the required shift in %ecx */
99         subl    $31,%ecx
100         negl    %ecx
101         shld    %cl,%eax,%edx
102         shl     %cl,%eax
103         subl    %ecx,EXP(%ebx)  /* This can cause an underflow */
104
105         movl    %edx,SIGH(%ebx)
106         movl    %eax,SIGL(%ebx)
107
108 L_done:
109         cmpl    EXP_OVER,EXP(%ebx)
110         jge     L_overflow
111
112         cmpl    EXP_UNDER,EXP(%ebx)
113         jle     L_underflow
114
115 L_exit:
116         popl    %ebx
117         leave
118         ret
119
120
121 L_zero:
122         movl    EXP_UNDER,EXP(%ebx)
123         movb    TW_Zero,TAG(%ebx)
124         jmp     L_exit
125
126 L_underflow:
127         push    %ebx
128         call    _arith_underflow
129         pop     %ebx
130         jmp     L_exit
131
132 L_overflow:
133         push    %ebx
134         call    _arith_overflow
135         pop     %ebx
136         jmp     L_exit
137
138
139
140 /* Normalise without reporting underflow or overflow */
141 ENTRY(normalize_nuo)
142         pushl   %ebp
143         movl    %esp,%ebp
144         pushl   %ebx
145
146         movl    PARAM1,%ebx
147
148         movl    SIGH(%ebx),%edx
149         movl    SIGL(%ebx),%eax
150
151         orl     %edx,%edx       /* ms bits */
152         js      L_exit          /* Already normalized */
153         jnz     L_nuo_shift_1   /* Shift left 1 - 31 bits */
154
155         orl     %eax,%eax
156         jz      L_zero          /* The contents are zero */
157
158 /* L_nuo_shift_32: */
159         movl    %eax,%edx
160         xorl    %eax,%eax
161         subl    $32,EXP(%ebx)   /* This can cause an underflow */
162
163 /* We need to shift left by 1 - 31 bits */
164 L_nuo_shift_1:
165         bsrl    %edx,%ecx       /* get the required shift in %ecx */
166         subl    $31,%ecx
167         negl    %ecx
168         shld    %cl,%eax,%edx
169         shl     %cl,%eax
170         subl    %ecx,EXP(%ebx)  /* This can cause an underflow */
171
172         movl    %edx,SIGH(%ebx)
173         movl    %eax,SIGL(%ebx)
174         jmp     L_exit
175
176