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 "ieee754dp.h"
0011 
0012 union ieee754dp ieee754dp_flong(s64 x)
0013 {
0014     u64 xm;
0015     int xe;
0016     int xs;
0017 
0018     ieee754_clearcx();
0019 
0020     if (x == 0)
0021         return ieee754dp_zero(0);
0022     if (x == 1 || x == -1)
0023         return ieee754dp_one(x < 0);
0024     if (x == 10 || x == -10)
0025         return ieee754dp_ten(x < 0);
0026 
0027     xs = (x < 0);
0028     if (xs) {
0029         if (x == (1ULL << 63))
0030             xm = (1ULL << 63);  /* max neg can't be safely negated */
0031         else
0032             xm = -x;
0033     } else {
0034         xm = x;
0035     }
0036 
0037     /* normalize */
0038     xe = DP_FBITS + 3;
0039     if (xm >> (DP_FBITS + 1 + 3)) {
0040         /* shunt out overflow bits */
0041         while (xm >> (DP_FBITS + 1 + 3)) {
0042             XDPSRSX1();
0043         }
0044     } else {
0045         /* normalize in grs extended double precision */
0046         while ((xm >> (DP_FBITS + 3)) == 0) {
0047             xm <<= 1;
0048             xe--;
0049         }
0050     }
0051 
0052     return ieee754dp_format(xs, xe, xm);
0053 }