Get LINT to build.
[dragonfly.git] / sys / i386 / gnu / fpemul / reg_mul.c
1 /*
2  *  reg_mul.c
3  *
4  * Multiply one FPU_REG by another, put the result in a destination FPU_REG.
5  *
6  *
7  * Copyright (C) 1992,1993,1994
8  *                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
9  *                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au
10  * All rights reserved.
11  *
12  * This copyright notice covers the redistribution and use of the
13  * FPU emulator developed by W. Metzenthen. It covers only its use
14  * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
15  * use is not permitted under this copyright.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must include information specifying
23  *    that source code for the emulator is freely available and include
24  *    either:
25  *      a) an offer to provide the source code for a nominal distribution
26  *         fee, or
27  *      b) list at least two alternative methods whereby the source
28  *         can be obtained, e.g. a publically accessible bulletin board
29  *         and an anonymous ftp site from which the software can be
30  *         downloaded.
31  * 3. All advertising materials specifically mentioning features or use of
32  *    this emulator must acknowledge that it was developed by W. Metzenthen.
33  * 4. The name of W. Metzenthen may not be used to endorse or promote
34  *    products derived from this software without specific prior written
35  *    permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
38  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
39  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
40  * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
44  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  *
48  *
49  * The purpose of this copyright, based upon the Berkeley copyright, is to
50  * ensure that the covered software remains freely available to everyone.
51  *
52  * The software (with necessary differences) is also available, but under
53  * the terms of the GNU copyleft, for the Linux operating system and for
54  * the djgpp ms-dos extender.
55  *
56  * W. Metzenthen   June 1994.
57  *
58  *
59  * $FreeBSD: src/sys/gnu/i386/fpemul/reg_mul.c,v 1.8 1999/08/28 00:42:56 peter Exp $
60  * $DragonFly: src/sys/i386/gnu/fpemul/Attic/reg_mul.c,v 1.2 2003/06/17 04:28:34 dillon Exp $
61  *
62  */
63
64 /*---------------------------------------------------------------------------+
65  | The destination may be any FPU_REG, including one of the source FPU_REGs. |
66  +---------------------------------------------------------------------------*/
67
68 #include <gnu/i386/fpemul/reg_constant.h>
69
70
71 /* This routine must be called with non-empty source registers */
72 void
73 reg_mul(FPU_REG * a, FPU_REG * b, FPU_REG * dest, unsigned int control_w)
74 {
75         char    sign = (a->sign ^ b->sign);
76
77         if (!(a->tag | b->tag)) {
78                 /* This should be the most common case */
79                 reg_u_mul(a, b, dest, control_w);
80                 dest->sign = sign;
81                 return;
82         } else
83                 if ((a->tag <= TW_Zero) && (b->tag <= TW_Zero)) {
84 #ifdef DENORM_OPERAND
85                         if (((b->tag == TW_Valid) && (b->exp <= EXP_UNDER)) ||
86                             ((a->tag == TW_Valid) && (a->exp <= EXP_UNDER))) {
87                                 if (denormal_operand())
88                                         return;
89                         }
90 #endif                          /* DENORM_OPERAND */
91                         /* Must have either both arguments == zero, or one
92                          * valid and the other zero. The result is therefore
93                          * zero. */
94                         reg_move(&CONST_Z, dest);
95 #ifdef PECULIAR_486
96                         /* The 80486 book says that the answer is +0, but a
97                          * real 80486 appears to behave this way... */
98                         dest->sign = sign;
99 #endif                          /* PECULIAR_486 */
100                         return;
101                 }
102 #if 0                           /* TW_Denormal is not used yet... perhaps
103                                  * never will be. */
104                 else
105                         if ((a->tag <= TW_Denormal) && (b->tag <= TW_Denormal)) {
106                                 /* One or both arguments are de-normalized */
107                                 /* Internal de-normalized numbers are not
108                                  * supported yet */
109                                 EXCEPTION(EX_INTERNAL | 0x105);
110                                 reg_move(&CONST_Z, dest);
111                         }
112 #endif
113                         else {
114                                 /* Must have infinities, NaNs, etc */
115                                 if ((a->tag == TW_NaN) || (b->tag == TW_NaN)) {
116                                         real_2op_NaN(a, b, dest);
117                                         return;
118                                 } else
119                                         if (a->tag == TW_Infinity) {
120                                                 if (b->tag == TW_Zero) {
121                                                         arith_invalid(dest);
122                                                         return;
123                                                 }
124                                                 /* Zero*Infinity is invalid */
125                                                 else {
126 #ifdef DENORM_OPERAND
127                                                         if ((b->tag == TW_Valid) && (b->exp <= EXP_UNDER) &&
128                                                             denormal_operand())
129                                                                 return;
130 #endif                          /* DENORM_OPERAND */
131                                                         reg_move(a, dest);
132                                                         dest->sign = sign;
133                                                 }
134                                                 return;
135                                         } else
136                                                 if (b->tag == TW_Infinity) {
137                                                         if (a->tag == TW_Zero) {
138                                                                 arith_invalid(dest);
139                                                                 return;
140                                                         }
141                                                         /* Zero*Infinity is
142                                                          * invalid */
143                                                         else {
144 #ifdef DENORM_OPERAND
145                                                                 if ((a->tag == TW_Valid) && (a->exp <= EXP_UNDER) &&
146                                                                     denormal_operand())
147                                                                         return;
148 #endif                          /* DENORM_OPERAND */
149                                                                 reg_move(b, dest);
150                                                                 dest->sign = sign;
151                                                         }
152                                                         return;
153                                                 }
154 #ifdef PARANOID
155                                                 else {
156                                                         EXCEPTION(EX_INTERNAL | 0x102);
157                                                 }
158 #endif                          /* PARANOID */
159                         }
160 }