1 /*---------------------------------------------------------------------------+
2 | reg_mul.c |
3 | |
4 | Multiply one FPU_REG by another, put the result in a destination FPU_REG. |
5 | |
6 | Copyright (C) 1992 W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
7 | Australia. E-mail apm233m@vaxc.cc.monash.edu.au |
8 | |
9 | |
10 +---------------------------------------------------------------------------*/
11
12 /*---------------------------------------------------------------------------+
13 | The destination may be any FPU_REG, including one of the source FPU_REGs. |
14 +---------------------------------------------------------------------------*/
15
16 #include "exception.h"
17 #include "reg_constant.h"
18 #include "fpu_emu.h"
19
20
21 /* This routine must be called with non-empty registers */
22 void reg_mul(FPU_REG *a, FPU_REG *b, FPU_REG *dest)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
23 {
24 if (!(a->tag | b->tag))
25 {
26 /* This should be the most common case */
27 reg_u_mul(a, b, dest);
28 dest->exp += - EXP_BIAS + 1;
29 dest->sign = (a->sign ^ b->sign);
30 dest->tag = TW_Valid;
31 if ( dest->exp <= EXP_UNDER )
32 { arith_underflow(FPU_st0_ptr); }
33 else if ( dest->exp >= EXP_OVER )
34 { arith_overflow(FPU_st0_ptr); }
35 return;
36 }
37 else if ((a->tag <= TW_Zero) && (b->tag <= TW_Zero))
38 {
39 /* Must have either both arguments == zero, or
40 one valid and the other zero.
41 The result is therefore zero. */
42 reg_move(&CONST_Z, dest);
43 }
44 else if ((a->tag <= TW_Denormal) && (b->tag <= TW_Denormal))
45 {
46 /* One or both arguments are de-normalized */
47 /* Internal de-normalized numbers are not supported yet */
48 EXCEPTION(EX_INTERNAL|0x105);
49 reg_move(&CONST_Z, dest);
50 }
51 else
52 {
53 /* Must have infinities, NaNs, etc */
54 if ( (a->tag == TW_NaN) || (b->tag == TW_NaN) )
55 { real_2op_NaN(a, b, dest); return; }
56 else if (a->tag == TW_Infinity)
57 {
58 if (b->tag == TW_Zero)
59 { arith_invalid(dest); return; }
60 else
61 {
62 reg_move(a, dest);
63 dest->sign = a->sign == b->sign ? SIGN_POS : SIGN_NEG;
64 }
65 }
66 else if (b->tag == TW_Infinity)
67 {
68 if (a->tag == TW_Zero)
69 { arith_invalid(dest); return; }
70 else
71 {
72 reg_move(b, dest);
73 dest->sign = a->sign == b->sign ? SIGN_POS : SIGN_NEG;
74 }
75 }
76 #ifdef PARANOID
77 else
78 {
79 EXCEPTION(EX_INTERNAL|0x102);
80 }
81 #endif PARANOID
82 dest->sign = (a->sign ^ b->sign);
83 }
84 }