4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 #pragma ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1988 by Sun Microsystems, Inc.
28 /* Unpack procedures for Sparc FPU simulator. */
31 #include "_Qglobals.h"
35 unpacked
*pu
; /* unpacked result */
36 int x
; /* packed integer */
39 pu
->sticky
= pu
->rounded
= 0;
42 pu
->fpclass
= fp_zero
;
45 (*pu
).fpclass
= fp_normal
;
46 (*pu
).exponent
= INTEGER_BIAS
;
47 if(x
<0) ux
= -x
; else ux
= x
;
48 (*pu
).significand
[0] = ux
>>15;
49 (*pu
).significand
[1] = (ux
&0x7fff)<<17;
50 (*pu
).significand
[2] = 0;
51 (*pu
).significand
[3] = 0;
58 unpacked
*pu
; /* unpacked result */
59 single_type x
; /* packed single */
62 pu
->sticky
= pu
->rounded
= 0;
65 pu
->significand
[1] = 0;
66 pu
->significand
[2] = 0;
67 pu
->significand
[3] = 0;
68 if (x
.exponent
== 0) { /* zero or sub */
69 if (x
.significand
== 0) { /* zero */
70 pu
->fpclass
= fp_zero
;
72 } else { /* subnormal */
73 pu
->fpclass
= fp_normal
;
74 pu
->exponent
= -SINGLE_BIAS
-6;
79 } else if (x
.exponent
== 0xff) { /* inf or nan */
80 if (x
.significand
== 0) { /* inf */
81 pu
->fpclass
= fp_infinity
;
84 if ((u
& 0x400000) != 0) { /* quiet */
85 pu
->fpclass
= fp_quiet
;
86 } else {/* signaling */
87 pu
->fpclass
= fp_signaling
;
88 fpu_set_exception(fp_invalid
);
90 pu
->significand
[0] = 0x18000 | (u
>> 7);
91 (*pu
).significand
[1]=((u
&0x7f)<<25);
95 (*pu
).exponent
= x
.exponent
- SINGLE_BIAS
;
96 (*pu
).fpclass
= fp_normal
;
97 (*pu
).significand
[0]=0x10000|(u
>>7);
98 (*pu
).significand
[1]=((u
&0x7f)<<25);
102 unpackdouble(pu
, x
, y
)
103 unpacked
*pu
; /* unpacked result */
104 double_type x
; /* packed double */
108 pu
->sticky
= pu
->rounded
= 0;
111 pu
->significand
[1] = y
;
112 pu
->significand
[2] = 0;
113 pu
->significand
[3] = 0;
114 if (x
.exponent
== 0) { /* zero or sub */
115 if ((x
.significand
== 0) && (y
== 0)) { /* zero */
116 pu
->fpclass
= fp_zero
;
118 } else { /* subnormal */
119 pu
->fpclass
= fp_normal
;
120 pu
->exponent
= -DOUBLE_BIAS
-3;
121 pu
->significand
[0] = u
;
125 } else if (x
.exponent
== 0x7ff) { /* inf or nan */
126 if ((u
|y
) == 0) { /* inf */
127 pu
->fpclass
= fp_infinity
;
130 if ((u
& 0x80000) != 0) { /* quiet */
131 pu
->fpclass
= fp_quiet
;
132 } else {/* signaling */
133 pu
->fpclass
= fp_signaling
;
134 fpu_set_exception(fp_invalid
);
136 pu
->significand
[0] = 0x18000 | (u
>> 4);
137 (*pu
).significand
[1]=((u
&0xf)<<28)|(y
>>4);
138 (*pu
).significand
[2]=((y
&0xf)<<28);
142 (*pu
).exponent
= x
.exponent
- DOUBLE_BIAS
;
143 (*pu
).fpclass
= fp_normal
;
144 (*pu
).significand
[0]=0x10000|(u
>>4);
145 (*pu
).significand
[1]=((u
&0xf)<<28)|(y
>>4);
146 (*pu
).significand
[2]=((y
&0xf)<<28);
150 unpackextended(pu
, x
, y
, z
, w
)
151 unpacked
*pu
; /* unpacked result */
152 extended_type x
; /* packed extended */
156 pu
->sticky
= pu
->rounded
= 0;
159 (*pu
).fpclass
= fp_normal
;
160 (*pu
).exponent
= x
.exponent
- EXTENDED_BIAS
;
161 (*pu
).significand
[0] = (x
.exponent
==0)? u
:0x10000|u
;
162 (*pu
).significand
[1] = y
;
163 (*pu
).significand
[2] = z
;
164 (*pu
).significand
[3] = w
;
165 if (x
.exponent
< 0x7fff) { /* zero, normal, or subnormal */
166 if ((z
|y
|w
|pu
->significand
[0]) == 0) { /* zero */
167 pu
->fpclass
= fp_zero
;
169 } else { /* normal or subnormal */
176 } else { /* inf or nan */
177 if ((u
|z
|y
|w
) == 0) { /* inf */
178 pu
->fpclass
= fp_infinity
;
181 if ((u
& 0x00008000) != 0) { /* quiet */
182 pu
->fpclass
= fp_quiet
;
183 } else {/* signaling */
184 pu
->fpclass
= fp_signaling
;
185 fpu_set_exception(fp_invalid
);
187 pu
->significand
[0] |= 0x8000; /* make quiet */
194 _fp_unpack(pu
, n
, dtype
)
195 unpacked
*pu
; /* unpacked result */
196 int *n
; /* input array */
197 enum fp_op_type dtype
; /* type of datum */
200 switch ((int) dtype
) {
202 unpackinteger(pu
, n
[0]);
214 double t
=1.0; int i0
,i1
;
215 if((*(int*)&t
)!=0) {i0
=0;i1
=1;} else {i0
=1;i1
=0;}
217 unpackdouble(pu
, x
, n
[i1
]);
223 double t
=1.0; int i0
,i1
,i2
,i3
;
224 if((*(int*)&t
)!=0) {i0
=0;i1
=1;i2
=2;i3
=3;}
225 else {i0
=3;i1
=2;i2
=1;i3
=0;}
227 unpackextended(pu
, x
, n
[i1
], n
[i2
], n
[i3
]);