/* IEEE754 floating point arithmetic1* single precision2*/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 "ieee754sp.h"2728ieee754sp ieee754sp_flong(s64 x)29{30u64 xm; /* <--- need 64-bit mantissa temp */31int xe;32int xs;3334CLEARCX;3536if (x == 0)37return ieee754sp_zero(0);38if (x == 1 || x == -1)39return ieee754sp_one(x < 0);40if (x == 10 || x == -10)41return ieee754sp_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}52xe = SP_MBITS + 3;5354if (xm >> (SP_MBITS + 1 + 3)) {55/* shunt out overflow bits56*/57while (xm >> (SP_MBITS + 1 + 3)) {58SPXSRSX1();59}60} else {61/* normalize in grs extended single precision */62while ((xm >> (SP_MBITS + 3)) == 0) {63xm <<= 1;64xe--;65}66}67SPNORMRET1(xs, xe, xm, "sp_flong", x);68}697071ieee754sp ieee754sp_fulong(u64 u)72{73if ((s64) u < 0)74return ieee754sp_add(ieee754sp_1e63(),75ieee754sp_flong(u & ~(1ULL << 63)));76return ieee754sp_flong(u);77}787980