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
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
29*6812Sraf #include "lint.h"
300Sstevel@tonic-gate #include "base_conversion.h"
310Sstevel@tonic-gate
320Sstevel@tonic-gate /* The following should be coded as inline expansion templates. */
330Sstevel@tonic-gate
340Sstevel@tonic-gate /*
350Sstevel@tonic-gate * Multiplies two normal or subnormal doubles, returns result and exceptions.
360Sstevel@tonic-gate */
370Sstevel@tonic-gate double
__mul_set(double x,double y,int * pe)380Sstevel@tonic-gate __mul_set(double x, double y, int *pe) {
390Sstevel@tonic-gate extern void _putsw(), _getsw();
400Sstevel@tonic-gate int sw;
410Sstevel@tonic-gate double z;
420Sstevel@tonic-gate
430Sstevel@tonic-gate _putsw(0);
440Sstevel@tonic-gate z = x * y;
450Sstevel@tonic-gate _getsw(&sw);
460Sstevel@tonic-gate if ((sw & 0x3f) == 0) {
470Sstevel@tonic-gate *pe = 0;
480Sstevel@tonic-gate } else {
490Sstevel@tonic-gate /* Result may not be exact. */
500Sstevel@tonic-gate *pe = 1;
510Sstevel@tonic-gate }
520Sstevel@tonic-gate return (z);
530Sstevel@tonic-gate }
540Sstevel@tonic-gate
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate * Divides two normal or subnormal doubles x/y, returns result and exceptions.
570Sstevel@tonic-gate */
580Sstevel@tonic-gate double
__div_set(double x,double y,int * pe)590Sstevel@tonic-gate __div_set(double x, double y, int *pe) {
600Sstevel@tonic-gate extern void _putsw(), _getsw();
610Sstevel@tonic-gate int sw;
620Sstevel@tonic-gate double z;
630Sstevel@tonic-gate
640Sstevel@tonic-gate _putsw(0);
650Sstevel@tonic-gate z = x / y;
660Sstevel@tonic-gate _getsw(&sw);
670Sstevel@tonic-gate if ((sw & 0x3f) == 0) {
680Sstevel@tonic-gate *pe = 0;
690Sstevel@tonic-gate } else {
700Sstevel@tonic-gate *pe = 1;
710Sstevel@tonic-gate }
720Sstevel@tonic-gate return (z);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate double
__dabs(double * d)760Sstevel@tonic-gate __dabs(double *d)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate /* should use hardware fabs instruction */
790Sstevel@tonic-gate return ((*d < 0.0) ? -*d : *d);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate * Returns IEEE mode/status and
840Sstevel@tonic-gate * sets up standard environment for base conversion.
850Sstevel@tonic-gate */
860Sstevel@tonic-gate void
__get_ieee_flags(__ieee_flags_type * b)870Sstevel@tonic-gate __get_ieee_flags(__ieee_flags_type *b) {
880Sstevel@tonic-gate extern void _getcw(), _getsw(), _putcw();
890Sstevel@tonic-gate int cw;
900Sstevel@tonic-gate
910Sstevel@tonic-gate _getcw(&cw);
920Sstevel@tonic-gate b->mode = cw;
930Sstevel@tonic-gate _getsw(&b->status);
940Sstevel@tonic-gate /*
950Sstevel@tonic-gate * set CW to...
960Sstevel@tonic-gate * RC (bits 10:11) 0 == round to nearest even
970Sstevel@tonic-gate * PC (bits 8:9) 2 == round to double
980Sstevel@tonic-gate * EM (bits 0:5) 0x3f == all exception trapping masked off
990Sstevel@tonic-gate */
1000Sstevel@tonic-gate cw = (cw & ~0xf3f) | 0x23f;
1010Sstevel@tonic-gate _putcw(cw);
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate /*
1050Sstevel@tonic-gate * Restores previous IEEE mode/status
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gate void
__set_ieee_flags(__ieee_flags_type * b)1080Sstevel@tonic-gate __set_ieee_flags(__ieee_flags_type *b) {
1090Sstevel@tonic-gate extern void _putcw(), _putsw();
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate _putcw(b->mode);
1120Sstevel@tonic-gate _putsw(b->status);
1130Sstevel@tonic-gate }
114