Initial import from FreeBSD RELENG_4:
[games.git] / sys / i386 / gnu / fpemul / reg_u_mul.s
1         .file   "reg_u_mul.S"
2 /*
3  *  reg_u_mul.S
4  *
5  * Core multiplication routine
6  *
7  *
8  * Copyright (C) 1992,1993,1994
9  *                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
10  *                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au
11  * All rights reserved.
12  *
13  * This copyright notice covers the redistribution and use of the
14  * FPU emulator developed by W. Metzenthen. It covers only its use
15  * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
16  * use is not permitted under this copyright.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must include information specifying
24  *    that source code for the emulator is freely available and include
25  *    either:
26  *      a) an offer to provide the source code for a nominal distribution
27  *         fee, or
28  *      b) list at least two alternative methods whereby the source
29  *         can be obtained, e.g. a publically accessible bulletin board
30  *         and an anonymous ftp site from which the software can be
31  *         downloaded.
32  * 3. All advertising materials specifically mentioning features or use of
33  *    this emulator must acknowledge that it was developed by W. Metzenthen.
34  * 4. The name of W. Metzenthen may not be used to endorse or promote
35  *    products derived from this software without specific prior written
36  *    permission.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
39  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
40  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
41  * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
43  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
44  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
46  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  *
49  *
50  * The purpose of this copyright, based upon the Berkeley copyright, is to
51  * ensure that the covered software remains freely available to everyone.
52  *
53  * The software (with necessary differences) is also available, but under
54  * the terms of the GNU copyleft, for the Linux operating system and for
55  * the djgpp ms-dos extender.
56  *
57  * W. Metzenthen   June 1994.
58  *
59  *
60  * $FreeBSD: src/sys/gnu/i386/fpemul/reg_u_mul.s,v 1.9 1999/08/28 00:42:58 peter Exp $
61  *
62  */
63
64 /*---------------------------------------------------------------------------+
65  |   Basic multiplication routine.                                           |
66  |   Does not check the resulting exponent for overflow/underflow            |
67  |                                                                           |
68  |   reg_u_mul(FPU_REG *a, FPU_REG *b, FPU_REG *c, unsigned int cw);         |
69  |                                                                           |
70  |   Internal working is at approx 128 bits.                                 |
71  |   Result is rounded to nearest 53 or 64 bits, using "nearest or even".    |
72  +---------------------------------------------------------------------------*/
73
74 #include <gnu/i386/fpemul/fpu_asm.h>
75
76
77 .data
78         ALIGN_DATA
79 accum_0:
80         .long   0
81 accum_1:
82         .long   0
83
84
85 .text
86 ENTRY(reg_u_mul)
87         pushl   %ebp
88         movl    %esp,%ebp
89         pushl   %esi
90         pushl   %edi
91         pushl   %ebx
92
93         movl    PARAM1,%esi
94         movl    PARAM2,%edi
95
96 #ifdef PARANOID
97         testl   $0x80000000,SIGH(%esi)
98         jz      L_bugged
99         testl   $0x80000000,SIGH(%edi)
100         jz      L_bugged
101 #endif PARANOID
102
103 #ifdef DENORM_OPERAND
104         movl    EXP(%esi),%eax
105         cmpl    EXP_UNDER,%eax
106         jg      xOp1_not_denorm
107
108         call    _denormal_operand
109         orl     %eax,%eax
110         jnz     FPU_Arith_exit
111
112 xOp1_not_denorm:
113         movl    EXP(%edi),%eax
114         cmpl    EXP_UNDER,%eax
115         jg      xOp2_not_denorm
116
117         call    _denormal_operand
118         orl     %eax,%eax
119         jnz     FPU_Arith_exit
120
121 xOp2_not_denorm:
122 #endif DENORM_OPERAND
123
124         xorl    %ecx,%ecx
125         xorl    %ebx,%ebx
126
127         movl    SIGL(%esi),%eax
128         mull    SIGL(%edi)
129         movl    %eax,accum_0
130         movl    %edx,accum_1
131
132         movl    SIGL(%esi),%eax
133         mull    SIGH(%edi)
134         addl    %eax,accum_1
135         adcl    %edx,%ebx
136 /*      adcl    $0,%ecx         *//* overflow here is not possible */
137
138         movl    SIGH(%esi),%eax
139         mull    SIGL(%edi)
140         addl    %eax,accum_1
141         adcl    %edx,%ebx
142         adcl    $0,%ecx
143
144         movl    SIGH(%esi),%eax
145         mull    SIGH(%edi)
146         addl    %eax,%ebx
147         adcl    %edx,%ecx
148
149         movl    EXP(%esi),%eax  /* Compute the exponent */
150         addl    EXP(%edi),%eax
151         subl    EXP_BIAS-1,%eax
152 /*  Have now finished with the sources */
153         movl    PARAM3,%edi     /* Point to the destination */
154         movl    %eax,EXP(%edi)
155
156 /*  Now make sure that the result is normalized */
157         testl   $0x80000000,%ecx
158         jnz     LResult_Normalised
159
160         /* Normalize by shifting left one bit */
161         shll    $1,accum_0
162         rcll    $1,accum_1
163         rcll    $1,%ebx
164         rcll    $1,%ecx
165         decl    EXP(%edi)
166
167 LResult_Normalised:
168         movl    accum_0,%eax
169         movl    accum_1,%edx
170         orl     %eax,%eax
171         jz      L_extent_zero
172
173         orl     $1,%edx
174
175 L_extent_zero:
176         movl    %ecx,%eax
177         jmp     FPU_round
178
179
180 #ifdef PARANOID
181 L_bugged:
182         pushl   EX_INTERNAL|0x205
183         call    EXCEPTION
184         pop     %ebx
185         jmp     L_exit
186
187 L_exit:
188         popl    %ebx
189         popl    %edi
190         popl    %esi
191         leave
192         ret
193 #endif PARANOID
194