1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1988 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate */
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SunOS-4.1 1.8 88/12/06 */
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate #include <sys/fpu/fpu_simulator.h>
29*7c478bd9Sstevel@tonic-gate #include <sys/fpu/globals.h>
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate void
_fp_mul(pfpsd,px,py,pz)32*7c478bd9Sstevel@tonic-gate _fp_mul(pfpsd, px, py, pz)
33*7c478bd9Sstevel@tonic-gate fp_simd_type *pfpsd;
34*7c478bd9Sstevel@tonic-gate unpacked *px, *py, *pz;
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate {
37*7c478bd9Sstevel@tonic-gate unpacked *pt;
38*7c478bd9Sstevel@tonic-gate unsigned acc[4]; /* Product accumulator. */
39*7c478bd9Sstevel@tonic-gate unsigned j, y, *x, s, r, c;
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate if ((int) px->fpclass <= (int) py->fpclass) {
42*7c478bd9Sstevel@tonic-gate pt = px;
43*7c478bd9Sstevel@tonic-gate px = py;
44*7c478bd9Sstevel@tonic-gate py = pt;
45*7c478bd9Sstevel@tonic-gate }
46*7c478bd9Sstevel@tonic-gate /* Now class(x) >= class(y). */
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate *pz = *px;
49*7c478bd9Sstevel@tonic-gate if (pz->fpclass < fp_quiet)
50*7c478bd9Sstevel@tonic-gate pz->sign = px->sign ^ py->sign;
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate switch (px->fpclass) {
53*7c478bd9Sstevel@tonic-gate case fp_quiet:
54*7c478bd9Sstevel@tonic-gate case fp_signaling:
55*7c478bd9Sstevel@tonic-gate case fp_zero:
56*7c478bd9Sstevel@tonic-gate return;
57*7c478bd9Sstevel@tonic-gate case fp_infinity:
58*7c478bd9Sstevel@tonic-gate if (py->fpclass == fp_zero) {
59*7c478bd9Sstevel@tonic-gate fpu_error_nan(pfpsd, pz);
60*7c478bd9Sstevel@tonic-gate pz->fpclass = fp_quiet;
61*7c478bd9Sstevel@tonic-gate }
62*7c478bd9Sstevel@tonic-gate return;
63*7c478bd9Sstevel@tonic-gate case fp_normal:
64*7c478bd9Sstevel@tonic-gate if (py->fpclass == fp_zero) {
65*7c478bd9Sstevel@tonic-gate pz->fpclass = fp_zero;
66*7c478bd9Sstevel@tonic-gate return;
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate }
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate /* Now x and y are both normal or subnormal. */
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate x = px->significand; /* save typing */
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gate /* intialize acc to zero */
75*7c478bd9Sstevel@tonic-gate s = r = acc[0] = acc[1] = acc[2] = acc[3] = 0;
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate y = py->significand[3]; /* py->significand[3] * x */
78*7c478bd9Sstevel@tonic-gate if (y != 0) {
79*7c478bd9Sstevel@tonic-gate j = 1;
80*7c478bd9Sstevel@tonic-gate do {
81*7c478bd9Sstevel@tonic-gate s |= r; /* shift acc right one bit */
82*7c478bd9Sstevel@tonic-gate r = acc[3]&1;
83*7c478bd9Sstevel@tonic-gate acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1);
84*7c478bd9Sstevel@tonic-gate acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1);
85*7c478bd9Sstevel@tonic-gate acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1);
86*7c478bd9Sstevel@tonic-gate acc[0] = (acc[0]>>1);
87*7c478bd9Sstevel@tonic-gate if (j&y) { /* bit i of y != 0, add x to acc */
88*7c478bd9Sstevel@tonic-gate c = 0;
89*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[3], acc[3], x[3], c);
90*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[2], acc[2], x[2], c);
91*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[1], acc[1], x[1], c);
92*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[0], acc[0], x[0], c);
93*7c478bd9Sstevel@tonic-gate }
94*7c478bd9Sstevel@tonic-gate j += j;
95*7c478bd9Sstevel@tonic-gate } while (j != 0);
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate y = py->significand[2]; /* py->significand[2] * x */
99*7c478bd9Sstevel@tonic-gate if (y != 0) {
100*7c478bd9Sstevel@tonic-gate j = 1;
101*7c478bd9Sstevel@tonic-gate do {
102*7c478bd9Sstevel@tonic-gate s |= r; /* shift acc right one bit */
103*7c478bd9Sstevel@tonic-gate r = acc[3]&1;
104*7c478bd9Sstevel@tonic-gate acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1);
105*7c478bd9Sstevel@tonic-gate acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1);
106*7c478bd9Sstevel@tonic-gate acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1);
107*7c478bd9Sstevel@tonic-gate acc[0] = (acc[0]>>1);
108*7c478bd9Sstevel@tonic-gate if (j&y) { /* bit i of y != 0, add x to acc */
109*7c478bd9Sstevel@tonic-gate c = 0;
110*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[3], acc[3], x[3], c);
111*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[2], acc[2], x[2], c);
112*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[1], acc[1], x[1], c);
113*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[0], acc[0], x[0], c);
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate j += j;
116*7c478bd9Sstevel@tonic-gate } while (j != 0);
117*7c478bd9Sstevel@tonic-gate } else {
118*7c478bd9Sstevel@tonic-gate s |= r|(acc[3]&0x7fffffff);
119*7c478bd9Sstevel@tonic-gate r = (acc[3]&0x80000000)>>31;
120*7c478bd9Sstevel@tonic-gate acc[3] = acc[2]; acc[2] = acc[1]; acc[1] = acc[0]; acc[0] = 0;
121*7c478bd9Sstevel@tonic-gate }
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate y = py->significand[1]; /* py->significand[1] * x */
124*7c478bd9Sstevel@tonic-gate if (y != 0) {
125*7c478bd9Sstevel@tonic-gate j = 1;
126*7c478bd9Sstevel@tonic-gate do {
127*7c478bd9Sstevel@tonic-gate s |= r; /* shift acc right one bit */
128*7c478bd9Sstevel@tonic-gate r = acc[3]&1;
129*7c478bd9Sstevel@tonic-gate acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1);
130*7c478bd9Sstevel@tonic-gate acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1);
131*7c478bd9Sstevel@tonic-gate acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1);
132*7c478bd9Sstevel@tonic-gate acc[0] = (acc[0]>>1);
133*7c478bd9Sstevel@tonic-gate if (j&y) { /* bit i of y != 0, add x to acc */
134*7c478bd9Sstevel@tonic-gate c = 0;
135*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[3], acc[3], x[3], c);
136*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[2], acc[2], x[2], c);
137*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[1], acc[1], x[1], c);
138*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[0], acc[0], x[0], c);
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate j += j;
141*7c478bd9Sstevel@tonic-gate } while (j != 0);
142*7c478bd9Sstevel@tonic-gate } else {
143*7c478bd9Sstevel@tonic-gate s |= r|(acc[3]&0x7fffffff);
144*7c478bd9Sstevel@tonic-gate r = (acc[3]&0x80000000)>>31;
145*7c478bd9Sstevel@tonic-gate acc[3] = acc[2]; acc[2] = acc[1]; acc[1] = acc[0]; acc[0] = 0;
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate /* py->significand[0] * x */
149*7c478bd9Sstevel@tonic-gate y = py->significand[0]; /* y is of form 0x0001???? */
150*7c478bd9Sstevel@tonic-gate j = 1;
151*7c478bd9Sstevel@tonic-gate do {
152*7c478bd9Sstevel@tonic-gate s |= r; /* shift acc right one bit */
153*7c478bd9Sstevel@tonic-gate r = acc[3]&1;
154*7c478bd9Sstevel@tonic-gate acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1);
155*7c478bd9Sstevel@tonic-gate acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1);
156*7c478bd9Sstevel@tonic-gate acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1);
157*7c478bd9Sstevel@tonic-gate acc[0] = (acc[0]>>1);
158*7c478bd9Sstevel@tonic-gate if (j&y) { /* bit i of y != 0, add x to acc */
159*7c478bd9Sstevel@tonic-gate c = 0;
160*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[3], acc[3], x[3], c);
161*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[2], acc[2], x[2], c);
162*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[1], acc[1], x[1], c);
163*7c478bd9Sstevel@tonic-gate c = fpu_add3wc(&acc[0], acc[0], x[0], c);
164*7c478bd9Sstevel@tonic-gate }
165*7c478bd9Sstevel@tonic-gate j += j;
166*7c478bd9Sstevel@tonic-gate } while (j <= y);
167*7c478bd9Sstevel@tonic-gate
168*7c478bd9Sstevel@tonic-gate if (acc[0] >= 0x20000) { /* right shift one bit to normalize */
169*7c478bd9Sstevel@tonic-gate pz->exponent = px->exponent + py->exponent + 1;
170*7c478bd9Sstevel@tonic-gate pz->sticky = s|r;
171*7c478bd9Sstevel@tonic-gate pz->rounded = acc[3]&1;
172*7c478bd9Sstevel@tonic-gate pz->significand[3] = ((acc[2]&1)<<31)|(acc[3]>>1);
173*7c478bd9Sstevel@tonic-gate pz->significand[2] = ((acc[1]&1)<<31)|(acc[2]>>1);
174*7c478bd9Sstevel@tonic-gate pz->significand[1] = ((acc[0]&1)<<31)|(acc[1]>>1);
175*7c478bd9Sstevel@tonic-gate pz->significand[0] = (acc[0]>>1);
176*7c478bd9Sstevel@tonic-gate } else {
177*7c478bd9Sstevel@tonic-gate pz->exponent = px->exponent + py->exponent;
178*7c478bd9Sstevel@tonic-gate pz->sticky = s;
179*7c478bd9Sstevel@tonic-gate pz->rounded = r;
180*7c478bd9Sstevel@tonic-gate pz->significand[3] = acc[3];
181*7c478bd9Sstevel@tonic-gate pz->significand[2] = acc[2];
182*7c478bd9Sstevel@tonic-gate pz->significand[1] = acc[1];
183*7c478bd9Sstevel@tonic-gate pz->significand[0] = acc[0];
184*7c478bd9Sstevel@tonic-gate }
185*7c478bd9Sstevel@tonic-gate }
186