Merge from vendor branch TCPDUMP:
[dragonfly.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  * $DragonFly: src/sys/i386/gnu/fpemul/Attic/reg_u_mul.s,v 1.4 2003/08/07 21:17:21 dillon Exp $
62  *
63  */
64
65 /*---------------------------------------------------------------------------+
66  |   Basic multiplication routine.                                           |
67  |   Does not check the resulting exponent for overflow/underflow            |
68  |                                                                           |
69  |   reg_u_mul(FPU_REG *a, FPU_REG *b, FPU_REG *c, unsigned int cw);         |
70  |                                                                           |
71  |   Internal working is at approx 128 bits.                                 |
72  |   Result is rounded to nearest 53 or 64 bits, using "nearest or even".    |
73  +---------------------------------------------------------------------------*/
74
75 #include "fpu_asm.h"
76
77
78 .data
79         ALIGN_DATA
80 accum_0:
81         .long   0
82 accum_1:
83         .long   0
84
85
86 .text
87 ENTRY(reg_u_mul)
88         pushl   %ebp
89         movl    %esp,%ebp
90         pushl   %esi
91         pushl   %edi
92         pushl   %ebx
93
94         movl    PARAM1,%esi
95         movl    PARAM2,%edi
96
97 #ifdef PARANOID
98         testl   $0x80000000,SIGH(%esi)
99         jz      L_bugged
100         testl   $0x80000000,SIGH(%edi)
101         jz      L_bugged
102 #endif PARANOID
103
104 #ifdef DENORM_OPERAND
105         movl    EXP(%esi),%eax
106         cmpl    EXP_UNDER,%eax
107         jg      xOp1_not_denorm
108
109         call    denormal_operand
110         orl     %eax,%eax
111         jnz     FPU_Arith_exit
112
113 xOp1_not_denorm:
114         movl    EXP(%edi),%eax
115         cmpl    EXP_UNDER,%eax
116         jg      xOp2_not_denorm
117
118         call    denormal_operand
119         orl     %eax,%eax
120         jnz     FPU_Arith_exit
121
122 xOp2_not_denorm:
123 #endif DENORM_OPERAND
124
125         xorl    %ecx,%ecx
126         xorl    %ebx,%ebx
127
128         movl    SIGL(%esi),%eax
129         mull    SIGL(%edi)
130         movl    %eax,accum_0
131         movl    %edx,accum_1
132
133         movl    SIGL(%esi),%eax
134         mull    SIGH(%edi)
135         addl    %eax,accum_1
136         adcl    %edx,%ebx
137 /*      adcl    $0,%ecx         *//* overflow here is not possible */
138
139         movl    SIGH(%esi),%eax
140         mull    SIGL(%edi)
141         addl    %eax,accum_1
142         adcl    %edx,%ebx
143         adcl    $0,%ecx
144
145         movl    SIGH(%esi),%eax
146         mull    SIGH(%edi)
147         addl    %eax,%ebx
148         adcl    %edx,%ecx
149
150         movl    EXP(%esi),%eax  /* Compute the exponent */
151         addl    EXP(%edi),%eax
152         subl    EXP_BIAS-1,%eax
153 /*  Have now finished with the sources */
154         movl    PARAM3,%edi     /* Point to the destination */
155         movl    %eax,EXP(%edi)
156
157 /*  Now make sure that the result is normalized */
158         testl   $0x80000000,%ecx
159         jnz     LResult_Normalised
160
161         /* Normalize by shifting left one bit */
162         shll    $1,accum_0
163         rcll    $1,accum_1
164         rcll    $1,%ebx
165         rcll    $1,%ecx
166         decl    EXP(%edi)
167
168 LResult_Normalised:
169         movl    accum_0,%eax
170         movl    accum_1,%edx
171         orl     %eax,%eax
172         jz      L_extent_zero
173
174         orl     $1,%edx
175
176 L_extent_zero:
177         movl    %ecx,%eax
178         jmp     FPU_round
179
180
181 #ifdef PARANOID
182 L_bugged:
183         pushl   EX_INTERNAL|0x205
184         call    EXCEPTION
185         pop     %ebx
186         jmp     L_exit
187
188 L_exit:
189         popl    %ebx
190         popl    %edi
191         popl    %esi
192         leave
193         ret
194 #endif PARANOID
195