10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22*722Smuffin /*
23*722Smuffin * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
24*722Smuffin * Use is subject to license terms.
25*722Smuffin */
260Sstevel@tonic-gate
27*722Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate /* IEEE function implementations. */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #include "base_conversion.h"
320Sstevel@tonic-gate
330Sstevel@tonic-gate enum fp_class_type
_class_single(single * x)34*722Smuffin _class_single(single *x)
350Sstevel@tonic-gate {
360Sstevel@tonic-gate single_equivalence kluge;
370Sstevel@tonic-gate
380Sstevel@tonic-gate kluge.x = *x;
390Sstevel@tonic-gate if (kluge.f.msw.exponent == 0) { /* 0 or sub */
400Sstevel@tonic-gate if (kluge.f.msw.significand == 0)
410Sstevel@tonic-gate return fp_zero;
420Sstevel@tonic-gate else
430Sstevel@tonic-gate return fp_subnormal;
440Sstevel@tonic-gate } else if (kluge.f.msw.exponent == 0xff) { /* inf or nan */
450Sstevel@tonic-gate if (kluge.f.msw.significand == 0)
460Sstevel@tonic-gate return fp_infinity;
470Sstevel@tonic-gate else if (kluge.f.msw.significand >= 0x400000)
480Sstevel@tonic-gate return fp_quiet;
490Sstevel@tonic-gate else
500Sstevel@tonic-gate return fp_signaling;
510Sstevel@tonic-gate } else
520Sstevel@tonic-gate return fp_normal;
530Sstevel@tonic-gate }
540Sstevel@tonic-gate
550Sstevel@tonic-gate enum fp_class_type
_class_extended(extended * x)56*722Smuffin _class_extended(extended *x)
570Sstevel@tonic-gate {
580Sstevel@tonic-gate extended_equivalence kluge;
590Sstevel@tonic-gate
600Sstevel@tonic-gate kluge.x[0] = (*x)[0];
610Sstevel@tonic-gate kluge.x[1] = (*x)[1];
620Sstevel@tonic-gate kluge.x[2] = (*x)[2];
630Sstevel@tonic-gate if (kluge.f.msw.exponent == 0) { /* 0 or sub */
640Sstevel@tonic-gate if ((kluge.f.significand == 0) && (kluge.f.significand2 == 0))
650Sstevel@tonic-gate return fp_zero;
660Sstevel@tonic-gate else
670Sstevel@tonic-gate return fp_subnormal;
680Sstevel@tonic-gate } else if (kluge.f.msw.exponent == 0x7fff) { /* inf or nan */
690Sstevel@tonic-gate if (((kluge.f.significand & 0x7fffffff) == 0) && (kluge.f.significand2 == 0))
700Sstevel@tonic-gate return fp_infinity;
710Sstevel@tonic-gate else if ((kluge.f.significand & 0x7fffffff) >= 0x40000000)
720Sstevel@tonic-gate return fp_quiet;
730Sstevel@tonic-gate else
740Sstevel@tonic-gate return fp_signaling;
750Sstevel@tonic-gate } else
760Sstevel@tonic-gate return fp_normal;
770Sstevel@tonic-gate }
780Sstevel@tonic-gate
790Sstevel@tonic-gate void
_unpack_single(unpacked * pu,single * px)80*722Smuffin _unpack_single(unpacked *pu, single *px)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate single_equivalence x;
830Sstevel@tonic-gate int i;
840Sstevel@tonic-gate
850Sstevel@tonic-gate x.x = *px;
860Sstevel@tonic-gate (*pu).sign = x.f.msw.sign;
870Sstevel@tonic-gate for (i = 1; i < UNPACKED_SIZE; i++)
880Sstevel@tonic-gate pu->significand[i] = 0;
890Sstevel@tonic-gate if (x.f.msw.exponent == 0) { /* zero or sub */
900Sstevel@tonic-gate if (x.f.msw.significand == 0) { /* zero */
910Sstevel@tonic-gate pu->fpclass = fp_zero;
920Sstevel@tonic-gate return;
930Sstevel@tonic-gate } else { /* subnormal */
940Sstevel@tonic-gate pu->fpclass = fp_normal;
950Sstevel@tonic-gate pu->exponent = -SINGLE_BIAS;
960Sstevel@tonic-gate pu->significand[0] = x.f.msw.significand << 9;
970Sstevel@tonic-gate _fp_normalize(pu);
980Sstevel@tonic-gate return;
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate } else if (x.f.msw.exponent == 0xff) { /* inf or nan */
1010Sstevel@tonic-gate if (x.f.msw.significand == 0) { /* inf */
1020Sstevel@tonic-gate pu->fpclass = fp_infinity;
1030Sstevel@tonic-gate return;
1040Sstevel@tonic-gate } else { /* nan */
1050Sstevel@tonic-gate if ((x.f.msw.significand & 0x400000) != 0) { /* quiet */
1060Sstevel@tonic-gate pu->fpclass = fp_quiet;
1070Sstevel@tonic-gate } else {/* signaling */
1080Sstevel@tonic-gate pu->fpclass = fp_quiet;
1090Sstevel@tonic-gate _fp_set_exception(fp_invalid);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate pu->significand[0] = 0x40000000 | (x.f.msw.significand << 8);
1120Sstevel@tonic-gate return;
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate (*pu).exponent = x.f.msw.exponent - SINGLE_BIAS;
1160Sstevel@tonic-gate (*pu).fpclass = fp_normal;
1170Sstevel@tonic-gate (*pu).significand[0] = 0x80000000 | (x.f.msw.significand << 8);
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate void
_unpack_extended(unpacked * pu,extended * px)121*722Smuffin _unpack_extended(unpacked *pu, extended *px)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate extended_equivalence x;
1240Sstevel@tonic-gate int i;
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate x.x[0] = (*px)[0];
1270Sstevel@tonic-gate x.x[1] = (*px)[1];
1280Sstevel@tonic-gate x.x[2] = (*px)[2];
1290Sstevel@tonic-gate pu->sign = x.f.msw.sign;
1300Sstevel@tonic-gate pu->fpclass = fp_normal;
1310Sstevel@tonic-gate pu->exponent = x.f.msw.exponent - EXTENDED_BIAS;
1320Sstevel@tonic-gate pu->significand[0] = x.f.significand;
1330Sstevel@tonic-gate pu->significand[1] = x.f.significand2;
1340Sstevel@tonic-gate for (i = 2; i < UNPACKED_SIZE; i++)
1350Sstevel@tonic-gate pu->significand[i] = 0;
1360Sstevel@tonic-gate if (x.f.msw.exponent == 0x7fff) { /* inf or nan */
1370Sstevel@tonic-gate if (((x.f.significand & 0x7fffffff) == 0) && (x.f.significand2 == 0)) { /* inf */
1380Sstevel@tonic-gate pu->fpclass = fp_infinity;
1390Sstevel@tonic-gate return;
1400Sstevel@tonic-gate } else { /* nan */
1410Sstevel@tonic-gate if ((x.f.significand & 0x40000000) != 0) { /* quiet */
1420Sstevel@tonic-gate pu->fpclass = fp_quiet;
1430Sstevel@tonic-gate } else {/* signaling */
1440Sstevel@tonic-gate pu->fpclass = fp_quiet;
1450Sstevel@tonic-gate _fp_set_exception(fp_invalid);
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate return;
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate if (x.f.significand < 0x80000000) { /* zero or unnormal */
1510Sstevel@tonic-gate if ((x.f.significand == 0) && (x.f.significand2 == 0)) { /* zero */
1520Sstevel@tonic-gate pu->fpclass = fp_zero;
1530Sstevel@tonic-gate return;
1540Sstevel@tonic-gate } else { /* unnormal */
1550Sstevel@tonic-gate pu->fpclass = fp_normal;
1560Sstevel@tonic-gate _fp_normalize(pu);
1570Sstevel@tonic-gate return;
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate
162*722Smuffin void
_display_unpacked(unpacked * pu)163*722Smuffin _display_unpacked(unpacked *pu)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate int i, e;
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate (void) printf(" unpacked ");
1680Sstevel@tonic-gate if (pu->sign == 1)
1690Sstevel@tonic-gate (void) printf("-");
1700Sstevel@tonic-gate else
1710Sstevel@tonic-gate (void) printf("+");
1720Sstevel@tonic-gate switch (pu->fpclass) {
1730Sstevel@tonic-gate case fp_zero:
1740Sstevel@tonic-gate (void) printf("0");
1750Sstevel@tonic-gate break;
1760Sstevel@tonic-gate case fp_infinity:
1770Sstevel@tonic-gate (void) printf("Infinity");
1780Sstevel@tonic-gate break;
1790Sstevel@tonic-gate case fp_quiet:
1800Sstevel@tonic-gate (void) printf("NaN(quiet)");
1810Sstevel@tonic-gate break;
1820Sstevel@tonic-gate case fp_signaling:
1830Sstevel@tonic-gate (void) printf("NaN(signaling)");
1840Sstevel@tonic-gate break;
1850Sstevel@tonic-gate case fp_subnormal:
1860Sstevel@tonic-gate case fp_normal:
1870Sstevel@tonic-gate e = 1 + pu->exponent;
1880Sstevel@tonic-gate for (i = 0; i < UNPACKED_SIZE; i++) {
1890Sstevel@tonic-gate e -= 32;
1900Sstevel@tonic-gate (void) printf(" %8X *2**%d + ", pu->significand[i], e);
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate (void) printf("\n");
1940Sstevel@tonic-gate }
195