xref: /onnv-gate/usr/src/lib/libbc/libc/gen/common/_Qfpack.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
23*0Sstevel@tonic-gate 
24*0Sstevel@tonic-gate /*
25*0Sstevel@tonic-gate  * Copyright (c) 1988 by Sun Microsystems, Inc.
26*0Sstevel@tonic-gate  */
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate /* Pack procedures for Sparc FPU simulator. */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #include "_Qquad.h"
31*0Sstevel@tonic-gate #include "_Qglobals.h"
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate PRIVATE int
overflow_to_infinity(sign)34*0Sstevel@tonic-gate overflow_to_infinity(sign)
35*0Sstevel@tonic-gate 	int             sign;
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate /* Returns 1 if overflow should go to infinity, 0 if to max finite. */
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate {
40*0Sstevel@tonic-gate 	int             inf;
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate 	switch (fp_direction) {
43*0Sstevel@tonic-gate 	case fp_nearest:
44*0Sstevel@tonic-gate 		inf = 1;
45*0Sstevel@tonic-gate 		break;
46*0Sstevel@tonic-gate 	case fp_tozero:
47*0Sstevel@tonic-gate 		inf = 0;
48*0Sstevel@tonic-gate 		break;
49*0Sstevel@tonic-gate 	case fp_positive:
50*0Sstevel@tonic-gate 		inf = !sign;
51*0Sstevel@tonic-gate 		break;
52*0Sstevel@tonic-gate 	case fp_negative:
53*0Sstevel@tonic-gate 		inf = sign;
54*0Sstevel@tonic-gate 		break;
55*0Sstevel@tonic-gate 	}
56*0Sstevel@tonic-gate 	return (inf);
57*0Sstevel@tonic-gate }
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate PRIVATE void
round(pu)60*0Sstevel@tonic-gate round(pu)
61*0Sstevel@tonic-gate 	unpacked       *pu;
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate /* Round according to current rounding mode.	 */
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate {
66*0Sstevel@tonic-gate 	int             increment;	/* boolean to indicate round up */
67*0Sstevel@tonic-gate 	int sr;
68*0Sstevel@tonic-gate 	sr = pu->sticky|pu->rounded;
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate 	if (sr == 0)
71*0Sstevel@tonic-gate 		return;
72*0Sstevel@tonic-gate 	fpu_set_exception(fp_inexact);
73*0Sstevel@tonic-gate 	switch (fp_direction) {
74*0Sstevel@tonic-gate 	case fp_nearest:
75*0Sstevel@tonic-gate 		increment = pu->rounded;
76*0Sstevel@tonic-gate 		break;
77*0Sstevel@tonic-gate 	case fp_tozero:
78*0Sstevel@tonic-gate 		increment = 0;
79*0Sstevel@tonic-gate 		break;
80*0Sstevel@tonic-gate 	case fp_positive:
81*0Sstevel@tonic-gate 		increment = (pu->sign == 0) & (sr != 0);
82*0Sstevel@tonic-gate 		break;
83*0Sstevel@tonic-gate 	case fp_negative:
84*0Sstevel@tonic-gate 		increment = (pu->sign != 0) & (sr != 0);
85*0Sstevel@tonic-gate 		break;
86*0Sstevel@tonic-gate 	}
87*0Sstevel@tonic-gate 	if (increment) {
88*0Sstevel@tonic-gate 	    pu->significand[3]++;
89*0Sstevel@tonic-gate 	    if (pu->significand[3] == 0) {
90*0Sstevel@tonic-gate 		pu->significand[2]++;
91*0Sstevel@tonic-gate 		if (pu->significand[2] == 0) {
92*0Sstevel@tonic-gate 		    pu->significand[1]++;
93*0Sstevel@tonic-gate 		    if (pu->significand[1] == 0) {
94*0Sstevel@tonic-gate 			pu->significand[0]++;	/* rounding carried out */
95*0Sstevel@tonic-gate 			if( pu->significand[0] == 0x20000) {
96*0Sstevel@tonic-gate 			    pu->exponent++;
97*0Sstevel@tonic-gate 			    pu->significand[0] = 0x10000;
98*0Sstevel@tonic-gate 			}
99*0Sstevel@tonic-gate 		    }
100*0Sstevel@tonic-gate 		}
101*0Sstevel@tonic-gate 	    }
102*0Sstevel@tonic-gate 	}
103*0Sstevel@tonic-gate 	if ((fp_direction == fp_nearest) &&
104*0Sstevel@tonic-gate 		(pu->sticky == 0) && increment!=0) {	/* ambiguous case */
105*0Sstevel@tonic-gate 		pu->significand[3] &= 0xfffffffe;	/* force round to even */
106*0Sstevel@tonic-gate 	}
107*0Sstevel@tonic-gate }
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate PRIVATE void
packinteger(pu,px)110*0Sstevel@tonic-gate packinteger(pu, px)
111*0Sstevel@tonic-gate 	unpacked       *pu;	/* unpacked result */
112*0Sstevel@tonic-gate 	int            *px;	/* packed integer */
113*0Sstevel@tonic-gate {
114*0Sstevel@tonic-gate 	switch (pu->fpclass) {
115*0Sstevel@tonic-gate 	case fp_zero:
116*0Sstevel@tonic-gate 		*px = 0;
117*0Sstevel@tonic-gate 		break;
118*0Sstevel@tonic-gate 	case fp_normal:
119*0Sstevel@tonic-gate 		if (pu->exponent >= 32)
120*0Sstevel@tonic-gate 			goto overflow;
121*0Sstevel@tonic-gate 		fpu_rightshift(pu, 112 - pu->exponent);
122*0Sstevel@tonic-gate 		round(pu);
123*0Sstevel@tonic-gate 		if (pu->significand[3] >= 0x80000000)
124*0Sstevel@tonic-gate 			if ((pu->sign == 0)||(pu->significand[3] > 0x80000000))
125*0Sstevel@tonic-gate 				goto overflow;
126*0Sstevel@tonic-gate 		*px = pu->significand[3];
127*0Sstevel@tonic-gate 		if (pu->sign)
128*0Sstevel@tonic-gate 			*px = -*px;
129*0Sstevel@tonic-gate 		break;
130*0Sstevel@tonic-gate 	case fp_infinity:
131*0Sstevel@tonic-gate 	case fp_quiet:
132*0Sstevel@tonic-gate 	case fp_signaling:
133*0Sstevel@tonic-gate overflow:
134*0Sstevel@tonic-gate 		if (pu->sign)
135*0Sstevel@tonic-gate 			*px = 0x80000000;
136*0Sstevel@tonic-gate 		else
137*0Sstevel@tonic-gate 			*px = 0x7fffffff;
138*0Sstevel@tonic-gate 		_fp_current_exceptions &= ~(1 << (int) fp_inexact);
139*0Sstevel@tonic-gate 		fpu_set_exception(fp_invalid);
140*0Sstevel@tonic-gate 		break;
141*0Sstevel@tonic-gate 	}
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate PRIVATE void
packsingle(pu,px)145*0Sstevel@tonic-gate packsingle(pu, px)
146*0Sstevel@tonic-gate 	unpacked       *pu;	/* unpacked result */
147*0Sstevel@tonic-gate 	single_type    *px;	/* packed single */
148*0Sstevel@tonic-gate {
149*0Sstevel@tonic-gate 	px->sign = pu->sign;
150*0Sstevel@tonic-gate 	switch (pu->fpclass) {
151*0Sstevel@tonic-gate 	case fp_zero:
152*0Sstevel@tonic-gate 		px->exponent = 0;
153*0Sstevel@tonic-gate 		px->significand = 0;
154*0Sstevel@tonic-gate 		break;
155*0Sstevel@tonic-gate 	case fp_infinity:
156*0Sstevel@tonic-gate infinity:
157*0Sstevel@tonic-gate 		px->exponent = 0xff;
158*0Sstevel@tonic-gate 		px->significand = 0;
159*0Sstevel@tonic-gate 		break;
160*0Sstevel@tonic-gate 	case fp_quiet:
161*0Sstevel@tonic-gate 	case fp_signaling:
162*0Sstevel@tonic-gate 		fpu_rightshift(pu, 113-24);
163*0Sstevel@tonic-gate 		px->exponent = 0xff;
164*0Sstevel@tonic-gate 		px->significand = 0x400000|(0x3fffff&pu->significand[3]);
165*0Sstevel@tonic-gate 		break;
166*0Sstevel@tonic-gate 	case fp_normal:
167*0Sstevel@tonic-gate 		fpu_rightshift(pu, 113-24);
168*0Sstevel@tonic-gate 		pu->exponent += SINGLE_BIAS;
169*0Sstevel@tonic-gate 		if (pu->exponent <= 0) {
170*0Sstevel@tonic-gate 			px->exponent = 0;
171*0Sstevel@tonic-gate 			fpu_rightshift(pu, 1 - pu->exponent);
172*0Sstevel@tonic-gate 			round(pu);
173*0Sstevel@tonic-gate 			if (pu->significand[3] == 0x800000) {	/* rounded
174*0Sstevel@tonic-gate 								 * back up to
175*0Sstevel@tonic-gate 								 * normal */
176*0Sstevel@tonic-gate 				px->exponent = 1;
177*0Sstevel@tonic-gate 				px->significand = 0;
178*0Sstevel@tonic-gate 				return;
179*0Sstevel@tonic-gate 			}
180*0Sstevel@tonic-gate 			if (_fp_current_exceptions & (1 << fp_inexact))
181*0Sstevel@tonic-gate 				fpu_set_exception(fp_underflow);
182*0Sstevel@tonic-gate 			px->significand = 0x7fffff & pu->significand[3];
183*0Sstevel@tonic-gate 			return;
184*0Sstevel@tonic-gate 		}
185*0Sstevel@tonic-gate 		round(pu);
186*0Sstevel@tonic-gate 		if (pu->significand[3] == 0x1000000) {	/* rounding overflow */
187*0Sstevel@tonic-gate 			pu->significand[3] = 0x800000;
188*0Sstevel@tonic-gate 			pu->exponent += 1;
189*0Sstevel@tonic-gate 		}
190*0Sstevel@tonic-gate 		if (pu->exponent >= 0xff) {
191*0Sstevel@tonic-gate 			fpu_set_exception(fp_overflow);
192*0Sstevel@tonic-gate 			fpu_set_exception(fp_inexact);
193*0Sstevel@tonic-gate 			if (overflow_to_infinity(pu->sign))
194*0Sstevel@tonic-gate 				goto infinity;
195*0Sstevel@tonic-gate 			px->exponent = 0xfe;
196*0Sstevel@tonic-gate 			px->significand = 0x7fffff;
197*0Sstevel@tonic-gate 			return;
198*0Sstevel@tonic-gate 		}
199*0Sstevel@tonic-gate 		px->exponent = pu->exponent;
200*0Sstevel@tonic-gate 		px->significand = 0x7fffff & pu->significand[3];
201*0Sstevel@tonic-gate 	}
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate PRIVATE void
packdouble(pu,px,py)205*0Sstevel@tonic-gate packdouble(pu, px, py)
206*0Sstevel@tonic-gate 	unpacked       *pu;	/* unpacked result */
207*0Sstevel@tonic-gate 	double_type    *px;	/* packed double */
208*0Sstevel@tonic-gate 	unsigned       *py;
209*0Sstevel@tonic-gate {
210*0Sstevel@tonic-gate 	px->sign = pu->sign;
211*0Sstevel@tonic-gate 	switch (pu->fpclass) {
212*0Sstevel@tonic-gate 	case fp_zero:
213*0Sstevel@tonic-gate 		px->exponent = 0;
214*0Sstevel@tonic-gate 		px->significand = 0;
215*0Sstevel@tonic-gate 		*py = 0;
216*0Sstevel@tonic-gate 		break;
217*0Sstevel@tonic-gate 	case fp_infinity:
218*0Sstevel@tonic-gate infinity:
219*0Sstevel@tonic-gate 		px->exponent = 0x7ff;
220*0Sstevel@tonic-gate 		px->significand = 0;
221*0Sstevel@tonic-gate 		*py = 0;
222*0Sstevel@tonic-gate 		break;
223*0Sstevel@tonic-gate 	case fp_quiet:
224*0Sstevel@tonic-gate 	case fp_signaling:
225*0Sstevel@tonic-gate 		fpu_rightshift(pu, 113-53);
226*0Sstevel@tonic-gate 		px->exponent = 0x7ff;
227*0Sstevel@tonic-gate 		px->significand = 0x80000 | (0x7ffff & pu->significand[2]);
228*0Sstevel@tonic-gate 		*py = pu->significand[3];
229*0Sstevel@tonic-gate 		break;
230*0Sstevel@tonic-gate 	case fp_normal:
231*0Sstevel@tonic-gate 		fpu_rightshift(pu, 113-53);
232*0Sstevel@tonic-gate 		pu->exponent += DOUBLE_BIAS;
233*0Sstevel@tonic-gate 		if (pu->exponent <= 0) {	/* underflow */
234*0Sstevel@tonic-gate 			px->exponent = 0;
235*0Sstevel@tonic-gate 			fpu_rightshift(pu, 1 - pu->exponent);
236*0Sstevel@tonic-gate 			round(pu);
237*0Sstevel@tonic-gate 			if (pu->significand[2] == 0x100000) {	/* rounded
238*0Sstevel@tonic-gate 								 * back up to
239*0Sstevel@tonic-gate 								 * normal */
240*0Sstevel@tonic-gate 				px->exponent = 1;
241*0Sstevel@tonic-gate 				px->significand = 0;
242*0Sstevel@tonic-gate 				*py = 0;
243*0Sstevel@tonic-gate 				return;
244*0Sstevel@tonic-gate 			}
245*0Sstevel@tonic-gate 			if (_fp_current_exceptions & (1 << fp_inexact))
246*0Sstevel@tonic-gate 				fpu_set_exception(fp_underflow);
247*0Sstevel@tonic-gate 			px->exponent = 0;
248*0Sstevel@tonic-gate 			px->significand = 0xfffff & pu->significand[2];
249*0Sstevel@tonic-gate 			*py = pu->significand[3];
250*0Sstevel@tonic-gate 			return;
251*0Sstevel@tonic-gate 		}
252*0Sstevel@tonic-gate 		round(pu);
253*0Sstevel@tonic-gate 		if (pu->significand[2] == 0x200000) {	/* rounding overflow */
254*0Sstevel@tonic-gate 			pu->significand[2] = 0x100000;
255*0Sstevel@tonic-gate 			pu->exponent += 1;
256*0Sstevel@tonic-gate 		}
257*0Sstevel@tonic-gate 		if (pu->exponent >= 0x7ff) {	/* overflow */
258*0Sstevel@tonic-gate 			fpu_set_exception(fp_overflow);
259*0Sstevel@tonic-gate 			fpu_set_exception(fp_inexact);
260*0Sstevel@tonic-gate 			if (overflow_to_infinity(pu->sign))
261*0Sstevel@tonic-gate 				goto infinity;
262*0Sstevel@tonic-gate 			px->exponent = 0x7fe;
263*0Sstevel@tonic-gate 			px->significand = 0xfffff;
264*0Sstevel@tonic-gate 			*py = 0xffffffff;
265*0Sstevel@tonic-gate 			return;
266*0Sstevel@tonic-gate 		}
267*0Sstevel@tonic-gate 		px->exponent = pu->exponent;
268*0Sstevel@tonic-gate 		px->significand = 0xfffff & pu->significand[2];
269*0Sstevel@tonic-gate 		*py = pu->significand[3];
270*0Sstevel@tonic-gate 		break;
271*0Sstevel@tonic-gate 	}
272*0Sstevel@tonic-gate }
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate PRIVATE void
packextended(pu,px,py,pz,pw)275*0Sstevel@tonic-gate packextended(pu, px, py, pz, pw)
276*0Sstevel@tonic-gate 	unpacked       *pu;	/* unpacked result */
277*0Sstevel@tonic-gate 	extended_type  *px;	/* packed extended */
278*0Sstevel@tonic-gate 	unsigned       *py, *pz, *pw;
279*0Sstevel@tonic-gate {
280*0Sstevel@tonic-gate 	px->sign = pu->sign;
281*0Sstevel@tonic-gate 	switch (pu->fpclass) {
282*0Sstevel@tonic-gate 	case fp_zero:
283*0Sstevel@tonic-gate 		px->exponent = 0;
284*0Sstevel@tonic-gate 		px->significand = 0;
285*0Sstevel@tonic-gate 		*pz = 0;
286*0Sstevel@tonic-gate 		*py = 0;
287*0Sstevel@tonic-gate 		*pw = 0;
288*0Sstevel@tonic-gate 		break;
289*0Sstevel@tonic-gate 	case fp_infinity:
290*0Sstevel@tonic-gate infinity:
291*0Sstevel@tonic-gate 		px->exponent = 0x7fff;
292*0Sstevel@tonic-gate 		px->significand = 0;
293*0Sstevel@tonic-gate 		*pz = 0;
294*0Sstevel@tonic-gate 		*py = 0;
295*0Sstevel@tonic-gate 		*pw = 0;
296*0Sstevel@tonic-gate 		break;
297*0Sstevel@tonic-gate 	case fp_quiet:
298*0Sstevel@tonic-gate 	case fp_signaling:
299*0Sstevel@tonic-gate 		px->exponent = 0x7fff;
300*0Sstevel@tonic-gate 		px->significand = 0x8000 | pu->significand[0];	/* Insure quiet
301*0Sstevel@tonic-gate 								 * nan. */
302*0Sstevel@tonic-gate 		*py = pu->significand[1];
303*0Sstevel@tonic-gate 		*pz = pu->significand[2];
304*0Sstevel@tonic-gate 		*pw = pu->significand[3];
305*0Sstevel@tonic-gate 		break;
306*0Sstevel@tonic-gate 	case fp_normal:
307*0Sstevel@tonic-gate 		pu->exponent += EXTENDED_BIAS;
308*0Sstevel@tonic-gate 		if (pu->exponent <= 0) {	/* underflow */
309*0Sstevel@tonic-gate 			fpu_rightshift(pu, 1-pu->exponent);
310*0Sstevel@tonic-gate 			round(pu);
311*0Sstevel@tonic-gate 			if (pu->significand[0] < 0x00010000) {	/* not rounded
312*0Sstevel@tonic-gate 								 * back up
313*0Sstevel@tonic-gate 								 * to normal */
314*0Sstevel@tonic-gate 				if (_fp_current_exceptions & (1 << fp_inexact))
315*0Sstevel@tonic-gate 					fpu_set_exception(fp_underflow);
316*0Sstevel@tonic-gate 				px->exponent = 0;
317*0Sstevel@tonic-gate 			} else
318*0Sstevel@tonic-gate 				px->exponent = 1;
319*0Sstevel@tonic-gate 			px->significand = pu->significand[0];
320*0Sstevel@tonic-gate 			*py = pu->significand[1];
321*0Sstevel@tonic-gate 			*pz = pu->significand[2];
322*0Sstevel@tonic-gate 			*pw = pu->significand[3];
323*0Sstevel@tonic-gate 			return;
324*0Sstevel@tonic-gate 		}
325*0Sstevel@tonic-gate 		round(pu);	/* rounding overflow handled in round() */
326*0Sstevel@tonic-gate 		if (pu->exponent >= 0x7fff) {	/* overflow */
327*0Sstevel@tonic-gate 			fpu_set_exception(fp_overflow);
328*0Sstevel@tonic-gate 			fpu_set_exception(fp_inexact);
329*0Sstevel@tonic-gate 			if (overflow_to_infinity(pu->sign))
330*0Sstevel@tonic-gate 				goto infinity;
331*0Sstevel@tonic-gate 			px->exponent = 0x7ffe;	/* overflow to max norm */
332*0Sstevel@tonic-gate 			px->significand = 0xffff;
333*0Sstevel@tonic-gate 			*py = 0xffffffff;
334*0Sstevel@tonic-gate 			*pz = 0xffffffff;
335*0Sstevel@tonic-gate 			*pw = 0xffffffff;
336*0Sstevel@tonic-gate 			return;
337*0Sstevel@tonic-gate 		}
338*0Sstevel@tonic-gate 		px->exponent = pu->exponent;
339*0Sstevel@tonic-gate 		px->significand = pu->significand[0];
340*0Sstevel@tonic-gate 		*py = pu->significand[1];
341*0Sstevel@tonic-gate 		*pz = pu->significand[2];
342*0Sstevel@tonic-gate 		*pw = pu->significand[3];
343*0Sstevel@tonic-gate 		break;
344*0Sstevel@tonic-gate 	}
345*0Sstevel@tonic-gate }
346*0Sstevel@tonic-gate 
347*0Sstevel@tonic-gate void
_fp_pack(pu,n,type)348*0Sstevel@tonic-gate _fp_pack(pu, n, type)
349*0Sstevel@tonic-gate 	unpacked       *pu;	/* unpacked operand */
350*0Sstevel@tonic-gate 	int 		*n;	/* output result's address */
351*0Sstevel@tonic-gate 	enum fp_op_type type;	/* type of datum */
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate {
354*0Sstevel@tonic-gate 	switch (type) {
355*0Sstevel@tonic-gate 	case fp_op_integer:
356*0Sstevel@tonic-gate 		{
357*0Sstevel@tonic-gate 			packinteger(pu, n);
358*0Sstevel@tonic-gate 			break;
359*0Sstevel@tonic-gate 		}
360*0Sstevel@tonic-gate 	case fp_op_single:
361*0Sstevel@tonic-gate 		{
362*0Sstevel@tonic-gate 			single_type     x;
363*0Sstevel@tonic-gate 			packsingle(pu, &x);
364*0Sstevel@tonic-gate 			n[0] = *(int*)&x;
365*0Sstevel@tonic-gate 			break;
366*0Sstevel@tonic-gate 		}
367*0Sstevel@tonic-gate 	case fp_op_double:
368*0Sstevel@tonic-gate 		{
369*0Sstevel@tonic-gate 			double_type     x;
370*0Sstevel@tonic-gate 			double		t=1.0;
371*0Sstevel@tonic-gate 			int		i0,i1;
372*0Sstevel@tonic-gate 			if((*(int*)&t)!=0) {i0=0;i1=1;} else {i0=1;i1=0;}
373*0Sstevel@tonic-gate 			packdouble(pu, &x,&n[i1]);
374*0Sstevel@tonic-gate 			n[i0] = *(int*)&x;
375*0Sstevel@tonic-gate 			break;
376*0Sstevel@tonic-gate 		}
377*0Sstevel@tonic-gate 	case fp_op_extended:
378*0Sstevel@tonic-gate 		{
379*0Sstevel@tonic-gate 			extended_type   x;
380*0Sstevel@tonic-gate 			unsigned        y, z, w;
381*0Sstevel@tonic-gate 			unpacked        u;
382*0Sstevel@tonic-gate 			int		k;
383*0Sstevel@tonic-gate 			switch (fp_precision) {	/* Implement extended
384*0Sstevel@tonic-gate 						 * rounding precision mode. */
385*0Sstevel@tonic-gate 			case fp_single:
386*0Sstevel@tonic-gate 				{
387*0Sstevel@tonic-gate 					single_type     tx;
388*0Sstevel@tonic-gate 					packsingle(pu, &tx);
389*0Sstevel@tonic-gate 					pu = &u;
390*0Sstevel@tonic-gate 					unpacksingle(pu, tx);
391*0Sstevel@tonic-gate 					break;
392*0Sstevel@tonic-gate 				}
393*0Sstevel@tonic-gate 			case fp_double:
394*0Sstevel@tonic-gate 				{
395*0Sstevel@tonic-gate 					double_type     tx;
396*0Sstevel@tonic-gate 					unsigned        ty;
397*0Sstevel@tonic-gate 					packdouble(pu, &tx, &ty);
398*0Sstevel@tonic-gate 					pu = &u;
399*0Sstevel@tonic-gate 					unpackdouble(pu, tx, ty);
400*0Sstevel@tonic-gate 					break;
401*0Sstevel@tonic-gate 				}
402*0Sstevel@tonic-gate 			case fp_precision_3:	/* rounded to 64 bits */
403*0Sstevel@tonic-gate 				{
404*0Sstevel@tonic-gate 					k = pu->exponent+ EXTENDED_BIAS;
405*0Sstevel@tonic-gate 					if(k>=0) k = 113-64;
406*0Sstevel@tonic-gate 					else     k = 113-64-k;
407*0Sstevel@tonic-gate 					fpu_rightshift(pu,113-64);
408*0Sstevel@tonic-gate 					round(pu);
409*0Sstevel@tonic-gate 					pu->sticky=pu->rounded=0;
410*0Sstevel@tonic-gate 					pu->exponent += k;
411*0Sstevel@tonic-gate 					fpu_normalize(pu);
412*0Sstevel@tonic-gate 					break;
413*0Sstevel@tonic-gate 				}
414*0Sstevel@tonic-gate 			}
415*0Sstevel@tonic-gate 			{
416*0Sstevel@tonic-gate 			int		i0,i1,i2,i3;
417*0Sstevel@tonic-gate 			double t = 1.0;
418*0Sstevel@tonic-gate 			if((*(int*)&t)!=0) {i0=0;i1=1;i2=2;i3=3;}
419*0Sstevel@tonic-gate 			else {i0=3;i1=2;i2=1;i3=0;}
420*0Sstevel@tonic-gate 			packextended(pu, &x, &n[i1], &n[i2], &n[i3]);
421*0Sstevel@tonic-gate 			n[i0] = *(int*)&x;
422*0Sstevel@tonic-gate 			}
423*0Sstevel@tonic-gate 
424*0Sstevel@tonic-gate 			break;
425*0Sstevel@tonic-gate 		}
426*0Sstevel@tonic-gate 	}
427*0Sstevel@tonic-gate }
428*0Sstevel@tonic-gate 
429