arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / parisc / math-emu / sfsqrt.c
blobbd6a84f468d8f9d90daedf107da4b1d4c44862fb
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
6 * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
7 */
8 /*
9 * BEGIN_DESC
11 * File:
12 * @(#) pa/spmath/sfsqrt.c $Revision: 1.1 $
14 * Purpose:
15 * Single Floating-point Square Root
17 * External Interfaces:
18 * sgl_fsqrt(srcptr,nullptr,dstptr,status)
20 * Internal Interfaces:
22 * Theory:
23 * <<please update with a overview of the operation of this file>>
25 * END_DESC
29 #include "float.h"
30 #include "sgl_float.h"
33 * Single Floating-point Square Root
36 /*ARGSUSED*/
37 unsigned int
38 sgl_fsqrt(
39 sgl_floating_point *srcptr,
40 unsigned int *nullptr,
41 sgl_floating_point *dstptr,
42 unsigned int *status)
44 register unsigned int src, result;
45 register int src_exponent;
46 register unsigned int newbit, sum;
47 register boolean guardbit = FALSE, even_exponent;
49 src = *srcptr;
51 * check source operand for NaN or infinity
53 if ((src_exponent = Sgl_exponent(src)) == SGL_INFINITY_EXPONENT) {
55 * is signaling NaN?
57 if (Sgl_isone_signaling(src)) {
58 /* trap if INVALIDTRAP enabled */
59 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
60 /* make NaN quiet */
61 Set_invalidflag();
62 Sgl_set_quiet(src);
65 * Return quiet NaN or positive infinity.
66 * Fall through to negative test if negative infinity.
68 if (Sgl_iszero_sign(src) || Sgl_isnotzero_mantissa(src)) {
69 *dstptr = src;
70 return(NOEXCEPTION);
75 * check for zero source operand
77 if (Sgl_iszero_exponentmantissa(src)) {
78 *dstptr = src;
79 return(NOEXCEPTION);
83 * check for negative source operand
85 if (Sgl_isone_sign(src)) {
86 /* trap if INVALIDTRAP enabled */
87 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
88 /* make NaN quiet */
89 Set_invalidflag();
90 Sgl_makequietnan(src);
91 *dstptr = src;
92 return(NOEXCEPTION);
96 * Generate result
98 if (src_exponent > 0) {
99 even_exponent = Sgl_hidden(src);
100 Sgl_clear_signexponent_set_hidden(src);
102 else {
103 /* normalize operand */
104 Sgl_clear_signexponent(src);
105 src_exponent++;
106 Sgl_normalize(src,src_exponent);
107 even_exponent = src_exponent & 1;
109 if (even_exponent) {
110 /* exponent is even */
111 /* Add comment here. Explain why odd exponent needs correction */
112 Sgl_leftshiftby1(src);
115 * Add comment here. Explain following algorithm.
117 * Trust me, it works.
120 Sgl_setzero(result);
121 newbit = 1 << SGL_P;
122 while (newbit && Sgl_isnotzero(src)) {
123 Sgl_addition(result,newbit,sum);
124 if(sum <= Sgl_all(src)) {
125 /* update result */
126 Sgl_addition(result,(newbit<<1),result);
127 Sgl_subtract(src,sum,src);
129 Sgl_rightshiftby1(newbit);
130 Sgl_leftshiftby1(src);
132 /* correct exponent for pre-shift */
133 if (even_exponent) {
134 Sgl_rightshiftby1(result);
137 /* check for inexact */
138 if (Sgl_isnotzero(src)) {
139 if (!even_exponent && Sgl_islessthan(result,src))
140 Sgl_increment(result);
141 guardbit = Sgl_lowmantissa(result);
142 Sgl_rightshiftby1(result);
144 /* now round result */
145 switch (Rounding_mode()) {
146 case ROUNDPLUS:
147 Sgl_increment(result);
148 break;
149 case ROUNDNEAREST:
150 /* stickybit is always true, so guardbit
151 * is enough to determine rounding */
152 if (guardbit) {
153 Sgl_increment(result);
155 break;
157 /* increment result exponent by 1 if mantissa overflowed */
158 if (Sgl_isone_hiddenoverflow(result)) src_exponent+=2;
160 if (Is_inexacttrap_enabled()) {
161 Sgl_set_exponent(result,
162 ((src_exponent-SGL_BIAS)>>1)+SGL_BIAS);
163 *dstptr = result;
164 return(INEXACTEXCEPTION);
166 else Set_inexactflag();
168 else {
169 Sgl_rightshiftby1(result);
171 Sgl_set_exponent(result,((src_exponent-SGL_BIAS)>>1)+SGL_BIAS);
172 *dstptr = result;
173 return(NOEXCEPTION);