/* IEEE754 floating point arithmetic1* double precision: common utilities2*/3/*4* MIPS floating point support5* Copyright (C) 1994-2000 Algorithmics Ltd.6*7* ########################################################################8*9* This program is free software; you can distribute it and/or modify it10* under the terms of the GNU General Public License (Version 2) as11* published by the Free Software Foundation.12*13* This program is distributed in the hope it will be useful, but WITHOUT14* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or15* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License16* for more details.17*18* You should have received a copy of the GNU General Public License along19* with this program; if not, write to the Free Software Foundation, Inc.,20* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.21*22* ########################################################################23*/242526#include "ieee754dp.h"2728ieee754dp ieee754dp_flong(s64 x)29{30u64 xm;31int xe;32int xs;3334CLEARCX;3536if (x == 0)37return ieee754dp_zero(0);38if (x == 1 || x == -1)39return ieee754dp_one(x < 0);40if (x == 10 || x == -10)41return ieee754dp_ten(x < 0);4243xs = (x < 0);44if (xs) {45if (x == (1ULL << 63))46xm = (1ULL << 63); /* max neg can't be safely negated */47else48xm = -x;49} else {50xm = x;51}5253/* normalize */54xe = DP_MBITS + 3;55if (xm >> (DP_MBITS + 1 + 3)) {56/* shunt out overflow bits */57while (xm >> (DP_MBITS + 1 + 3)) {58XDPSRSX1();59}60} else {61/* normalize in grs extended double precision */62while ((xm >> (DP_MBITS + 3)) == 0) {63xm <<= 1;64xe--;65}66}67DPNORMRET1(xs, xe, xm, "dp_flong", x);68}6970ieee754dp ieee754dp_fulong(u64 u)71{72if ((s64) u < 0)73return ieee754dp_add(ieee754dp_1e63(),74ieee754dp_flong(u & ~(1ULL << 63)));75return ieee754dp_flong(u);76}777879