Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* IEEE754 floating point arithmetic
0003  * single precision
0004  */
0005 /*
0006  * MIPS floating point support
0007  * Copyright (C) 1994-2000 Algorithmics Ltd.
0008  */
0009 
0010 #include "ieee754sp.h"
0011 
0012 union ieee754sp ieee754sp_fint(int x)
0013 {
0014     unsigned int xm;
0015     int xe;
0016     int xs;
0017 
0018     ieee754_clearcx();
0019 
0020     if (x == 0)
0021         return ieee754sp_zero(0);
0022     if (x == 1 || x == -1)
0023         return ieee754sp_one(x < 0);
0024     if (x == 10 || x == -10)
0025         return ieee754sp_ten(x < 0);
0026 
0027     xs = (x < 0);
0028     if (xs) {
0029         if (x == (1 << 31))
0030             xm = ((unsigned) 1 << 31);  /* max neg can't be safely negated */
0031         else
0032             xm = -x;
0033     } else {
0034         xm = x;
0035     }
0036     xe = SP_FBITS + 3;
0037 
0038     if (xm >> (SP_FBITS + 1 + 3)) {
0039         /* shunt out overflow bits
0040          */
0041         while (xm >> (SP_FBITS + 1 + 3)) {
0042             SPXSRSX1();
0043         }
0044     } else {
0045         /* normalize in grs extended single precision
0046          */
0047         while ((xm >> (SP_FBITS + 3)) == 0) {
0048             xm <<= 1;
0049             xe--;
0050         }
0051     }
0052     return ieee754sp_format(xs, xe, xm);
0053 }