/* 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_fint(int x)29{30unsigned xm;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 == (1 << 31))46xm = ((unsigned) 1 << 31); /* 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 precision62*/63while ((xm >> (SP_MBITS + 3)) == 0) {64xm <<= 1;65xe--;66}67}68SPNORMRET1(xs, xe, xm, "fint", x);69}707172ieee754sp ieee754sp_funs(unsigned int u)73{74if ((int) u < 0)75return ieee754sp_add(ieee754sp_1e31(),76ieee754sp_fint(u & ~(1 << 31)));77return ieee754sp_fint(u);78}798081