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]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #if !defined(sparc) && !defined(__sparc)
30 #error This code is for SPARC only
34 * _Q_scl(x, n) sets *x = *x * 2^n.
36 * This routine tacitly assumes the result will be either zero
37 * or normal, so there is no need to raise any exceptions.
40 _Q_scl(long double *x
, int n
)
49 hx
= xx
.i
[0] & ~0x80000000;
51 if (hx
< 0x10000) { /* x is zero or subnormal */
52 if ((hx
| xx
.i
[1] | xx
.i
[2] | xx
.i
[3]) == 0)
56 while (hx
== 0 && xx
.i
[1] < 0x10000) {
63 while (hx
< 0x10000) {
64 hx
= (hx
<< 1) | (xx
.i
[1] >> 31);
65 xx
.i
[1] = (xx
.i
[1] << 1) | (xx
.i
[2] >> 31);
66 xx
.i
[2] = (xx
.i
[2] << 1) | (xx
.i
[3] >> 31);
70 xx
.i
[0] = hx
| (xx
.i
[0] & 0x80000000);
73 if ((hx
>> 16) + n
< 1) {
74 /* for subnormal result, just deliver zero */
75 xx
.i
[0] = xx
.i
[0] & 0x80000000;
76 xx
.i
[1] = xx
.i
[2] = xx
.i
[3] = 0;
86 { 0x7ffe0000, 0, 0, 0 },
87 { 0x00010000, 0, 0, 0 }
91 * _Q_scle(x, n) sets *x = *x * 2^n, raising overflow or underflow
94 * This routine tacitly assumes the argument is either zero or normal.
97 _Q_scle(long double *x
, int n
)
106 hx
= (xx
.i
[0] >> 16) & 0x7fff;
108 if (hx
== 0) /* x must be zero */
112 if (hx
>= 0x7fff) { /* overflow */
113 xx
.i
[0] = 0x7ffe0000 | (xx
.i
[0] & 0x80000000);
114 xx
.i
[1] = xx
.i
[2] = xx
.i
[3] = 0;
116 } else if (hx
< 1) { /* possible underflow */
118 xx
.i
[0] = 0x00010000 | (xx
.i
[0] & 0x80000000);
119 xx
.i
[1] = xx
.i
[2] = xx
.i
[3] = 0;
121 xx
.i
[0] = (0x3ffe0000 + (hx
<< 16)) |
122 (xx
.i
[0] & 0x8000ffff);
126 xx
.i
[0] += (n
<< 16);