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 #include <sys/isa_defs.h>
320Sstevel@tonic-gate
330Sstevel@tonic-gate #define CSR_DEFAULT 0x1f80
340Sstevel@tonic-gate
350Sstevel@tonic-gate /* The following should be coded as inline expansion templates. */
360Sstevel@tonic-gate
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate * Multiplies two normal or subnormal doubles, returns result and exceptions.
390Sstevel@tonic-gate */
400Sstevel@tonic-gate double
__mul_set(double x,double y,int * pe)410Sstevel@tonic-gate __mul_set(double x, double y, int *pe) {
420Sstevel@tonic-gate extern void _putmxcsr(), _getmxcsr();
430Sstevel@tonic-gate int csr;
440Sstevel@tonic-gate double z;
450Sstevel@tonic-gate
460Sstevel@tonic-gate _putmxcsr(CSR_DEFAULT);
470Sstevel@tonic-gate z = x * y;
480Sstevel@tonic-gate _getmxcsr(&csr);
490Sstevel@tonic-gate if ((csr & 0x3f) == 0) {
500Sstevel@tonic-gate *pe = 0;
510Sstevel@tonic-gate } else {
520Sstevel@tonic-gate /* Result may not be exact. */
530Sstevel@tonic-gate *pe = 1;
540Sstevel@tonic-gate }
550Sstevel@tonic-gate return (z);
560Sstevel@tonic-gate }
570Sstevel@tonic-gate
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate * Divides two normal or subnormal doubles x/y, returns result and exceptions.
600Sstevel@tonic-gate */
610Sstevel@tonic-gate double
__div_set(double x,double y,int * pe)620Sstevel@tonic-gate __div_set(double x, double y, int *pe) {
630Sstevel@tonic-gate extern void _putmxcsr(), _getmxcsr();
640Sstevel@tonic-gate int csr;
650Sstevel@tonic-gate double z;
660Sstevel@tonic-gate
670Sstevel@tonic-gate _putmxcsr(CSR_DEFAULT);
680Sstevel@tonic-gate z = x / y;
690Sstevel@tonic-gate _getmxcsr(&csr);
700Sstevel@tonic-gate if ((csr & 0x3f) == 0) {
710Sstevel@tonic-gate *pe = 0;
720Sstevel@tonic-gate } else {
730Sstevel@tonic-gate *pe = 1;
740Sstevel@tonic-gate }
750Sstevel@tonic-gate return (z);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate
780Sstevel@tonic-gate double
__dabs(double * d)790Sstevel@tonic-gate __dabs(double *d)
800Sstevel@tonic-gate {
810Sstevel@tonic-gate /* should use hardware fabs instruction */
820Sstevel@tonic-gate return ((*d < 0.0) ? -*d : *d);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate * Returns IEEE mode/status and
870Sstevel@tonic-gate * sets up standard environment for base conversion.
880Sstevel@tonic-gate */
890Sstevel@tonic-gate void
__get_ieee_flags(__ieee_flags_type * b)900Sstevel@tonic-gate __get_ieee_flags(__ieee_flags_type *b) {
910Sstevel@tonic-gate extern void _getmxcsr(), _putmxcsr();
920Sstevel@tonic-gate
930Sstevel@tonic-gate _getmxcsr(&b->status);
940Sstevel@tonic-gate
950Sstevel@tonic-gate /* round-to-nearest, all exceptions masked, gradual underflow */
960Sstevel@tonic-gate _putmxcsr(CSR_DEFAULT);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate * Restores previous IEEE mode/status
1010Sstevel@tonic-gate */
1020Sstevel@tonic-gate void
__set_ieee_flags(__ieee_flags_type * b)1030Sstevel@tonic-gate __set_ieee_flags(__ieee_flags_type *b) {
1040Sstevel@tonic-gate extern void _putmxcsr();
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate _putmxcsr(b->status);
1070Sstevel@tonic-gate }
108