Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* IEEE754 floating point arithmetic
0003  * double precision: common utilities
0004  */
0005 /*
0006  * MIPS floating point support
0007  * Copyright (C) 1994-2000 Algorithmics Ltd.
0008  */
0009 
0010 #include "ieee754sp.h"
0011 #include "ieee754dp.h"
0012 
0013 static inline union ieee754dp ieee754dp_nan_fsp(int xs, u64 xm)
0014 {
0015     return builddp(xs, DP_EMAX + 1 + DP_EBIAS,
0016                xm << (DP_FBITS - SP_FBITS));
0017 }
0018 
0019 union ieee754dp ieee754dp_fsp(union ieee754sp x)
0020 {
0021     COMPXSP;
0022 
0023     EXPLODEXSP;
0024 
0025     ieee754_clearcx();
0026 
0027     FLUSHXSP;
0028 
0029     switch (xc) {
0030     case IEEE754_CLASS_SNAN:
0031         return ieee754dp_nanxcpt(ieee754dp_nan_fsp(xs, xm));
0032 
0033     case IEEE754_CLASS_QNAN:
0034         return ieee754dp_nan_fsp(xs, xm);
0035 
0036     case IEEE754_CLASS_INF:
0037         return ieee754dp_inf(xs);
0038 
0039     case IEEE754_CLASS_ZERO:
0040         return ieee754dp_zero(xs);
0041 
0042     case IEEE754_CLASS_DNORM:
0043         /* normalize */
0044         while ((xm >> SP_FBITS) == 0) {
0045             xm <<= 1;
0046             xe--;
0047         }
0048         break;
0049 
0050     case IEEE754_CLASS_NORM:
0051         break;
0052     }
0053 
0054     /*
0055      * Can't possibly overflow,underflow, or need rounding
0056      */
0057 
0058     /* drop the hidden bit */
0059     xm &= ~SP_HIDDEN_BIT;
0060 
0061     return builddp(xs, xe + DP_EBIAS,
0062                (u64) xm << (DP_FBITS - SP_FBITS));
0063 }