/* 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_fdp(ieee754dp x)29{30COMPXDP;31ieee754sp nan;3233EXPLODEXDP;3435CLEARCX;3637FLUSHXDP;3839switch (xc) {40case IEEE754_CLASS_SNAN:41SETCX(IEEE754_INVALID_OPERATION);42return ieee754sp_nanxcpt(ieee754sp_indef(), "fdp");43case IEEE754_CLASS_QNAN:44nan = buildsp(xs, SP_EMAX + 1 + SP_EBIAS, (u32)45(xm >> (DP_MBITS - SP_MBITS)));46if (!ieee754sp_isnan(nan))47nan = ieee754sp_indef();48return ieee754sp_nanxcpt(nan, "fdp", x);49case IEEE754_CLASS_INF:50return ieee754sp_inf(xs);51case IEEE754_CLASS_ZERO:52return ieee754sp_zero(xs);53case IEEE754_CLASS_DNORM:54/* can't possibly be sp representable */55SETCX(IEEE754_UNDERFLOW);56SETCX(IEEE754_INEXACT);57if ((ieee754_csr.rm == IEEE754_RU && !xs) ||58(ieee754_csr.rm == IEEE754_RD && xs))59return ieee754sp_xcpt(ieee754sp_mind(xs), "fdp", x);60return ieee754sp_xcpt(ieee754sp_zero(xs), "fdp", x);61case IEEE754_CLASS_NORM:62break;63}6465{66u32 rm;6768/* convert from DP_MBITS to SP_MBITS+3 with sticky right shift69*/70rm = (xm >> (DP_MBITS - (SP_MBITS + 3))) |71((xm << (64 - (DP_MBITS - (SP_MBITS + 3)))) != 0);7273SPNORMRET1(xs, xe, rm, "fdp", x);74}75}767778