/* 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"2728s64 ieee754sp_tlong(ieee754sp x)29{30COMPXDP; /* <-- need 64-bit mantissa tmp */3132CLEARCX;3334EXPLODEXSP;35FLUSHXSP;3637switch (xc) {38case IEEE754_CLASS_SNAN:39case IEEE754_CLASS_QNAN:40case IEEE754_CLASS_INF:41SETCX(IEEE754_INVALID_OPERATION);42return ieee754di_xcpt(ieee754di_indef(), "sp_tlong", x);43case IEEE754_CLASS_ZERO:44return 0;45case IEEE754_CLASS_DNORM:46case IEEE754_CLASS_NORM:47break;48}49if (xe >= 63) {50/* look for valid corner case */51if (xe == 63 && xs && xm == SP_HIDDEN_BIT)52return -0x8000000000000000LL;53/* Set invalid. We will only use overflow for floating54point overflow */55SETCX(IEEE754_INVALID_OPERATION);56return ieee754di_xcpt(ieee754di_indef(), "sp_tlong", x);57}58/* oh gawd */59if (xe > SP_MBITS) {60xm <<= xe - SP_MBITS;61} else if (xe < SP_MBITS) {62u32 residue;63int round;64int sticky;65int odd;6667if (xe < -1) {68residue = xm;69round = 0;70sticky = residue != 0;71xm = 0;72} else {73residue = xm << (32 - SP_MBITS + xe);74round = (residue >> 31) != 0;75sticky = (residue << 1) != 0;76xm >>= SP_MBITS - xe;77}78odd = (xm & 0x1) != 0x0;79switch (ieee754_csr.rm) {80case IEEE754_RN:81if (round && (sticky || odd))82xm++;83break;84case IEEE754_RZ:85break;86case IEEE754_RU: /* toward +Infinity */87if ((round || sticky) && !xs)88xm++;89break;90case IEEE754_RD: /* toward -Infinity */91if ((round || sticky) && xs)92xm++;93break;94}95if ((xm >> 63) != 0) {96/* This can happen after rounding */97SETCX(IEEE754_INVALID_OPERATION);98return ieee754di_xcpt(ieee754di_indef(), "sp_tlong", x);99}100if (round || sticky)101SETCX(IEEE754_INEXACT);102}103if (xs)104return -xm;105else106return xm;107}108109110u64 ieee754sp_tulong(ieee754sp x)111{112ieee754sp hb = ieee754sp_1e63();113114/* what if x < 0 ?? */115if (ieee754sp_lt(x, hb))116return (u64) ieee754sp_tlong(x);117118return (u64) ieee754sp_tlong(ieee754sp_sub(x, hb)) |119(1ULL << 63);120}121122123