11da177e4SLinus Torvalds /* IEEE754 floating point arithmetic 21da177e4SLinus Torvalds * single precision 31da177e4SLinus Torvalds */ 41da177e4SLinus Torvalds /* 51da177e4SLinus Torvalds * MIPS floating point support 61da177e4SLinus Torvalds * Copyright (C) 1994-2000 Algorithmics Ltd. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can distribute it and/or modify it 91da177e4SLinus Torvalds * under the terms of the GNU General Public License (Version 2) as 101da177e4SLinus Torvalds * published by the Free Software Foundation. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * This program is distributed in the hope it will be useful, but WITHOUT 131da177e4SLinus Torvalds * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 141da177e4SLinus Torvalds * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 151da177e4SLinus Torvalds * for more details. 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License along 181da177e4SLinus Torvalds * with this program; if not, write to the Free Software Foundation, Inc., 193f7cac41SRalf Baechle * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 201da177e4SLinus Torvalds */ 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include "ieee754sp.h" 231da177e4SLinus Torvalds 242209bcb1SRalf Baechle union ieee754sp ieee754sp_neg(union ieee754sp x) 251da177e4SLinus Torvalds { 26232b6ec5SMaciej W. Rozycki union ieee754sp y; 271da177e4SLinus Torvalds 28198f7058SMaciej W. Rozycki if (ieee754_csr.abs2008) { 29198f7058SMaciej W. Rozycki y = x; 30198f7058SMaciej W. Rozycki SPSIGN(y) = !SPSIGN(x); 31198f7058SMaciej W. Rozycki } else { 32198f7058SMaciej W. Rozycki unsigned int oldrm; 33198f7058SMaciej W. Rozycki 34232b6ec5SMaciej W. Rozycki oldrm = ieee754_csr.rm; 35232b6ec5SMaciej W. Rozycki ieee754_csr.rm = FPU_CSR_RD; 36232b6ec5SMaciej W. Rozycki y = ieee754sp_sub(ieee754sp_zero(0), x); 37232b6ec5SMaciej W. Rozycki ieee754_csr.rm = oldrm; 38198f7058SMaciej W. Rozycki } 39232b6ec5SMaciej W. Rozycki return y; 401da177e4SLinus Torvalds } 411da177e4SLinus Torvalds 422209bcb1SRalf Baechle union ieee754sp ieee754sp_abs(union ieee754sp x) 431da177e4SLinus Torvalds { 44232b6ec5SMaciej W. Rozycki union ieee754sp y; 451da177e4SLinus Torvalds 46198f7058SMaciej W. Rozycki if (ieee754_csr.abs2008) { 47198f7058SMaciej W. Rozycki y = x; 48198f7058SMaciej W. Rozycki SPSIGN(y) = 0; 49198f7058SMaciej W. Rozycki } else { 50198f7058SMaciej W. Rozycki unsigned int oldrm; 51198f7058SMaciej W. Rozycki 52232b6ec5SMaciej W. Rozycki oldrm = ieee754_csr.rm; 53232b6ec5SMaciej W. Rozycki ieee754_csr.rm = FPU_CSR_RD; 54232b6ec5SMaciej W. Rozycki if (SPSIGN(x)) 55232b6ec5SMaciej W. Rozycki y = ieee754sp_sub(ieee754sp_zero(0), x); 56232b6ec5SMaciej W. Rozycki else 57232b6ec5SMaciej W. Rozycki y = ieee754sp_add(ieee754sp_zero(0), x); 58232b6ec5SMaciej W. Rozycki ieee754_csr.rm = oldrm; 59198f7058SMaciej W. Rozycki } 60232b6ec5SMaciej W. Rozycki return y; 611da177e4SLinus Torvalds } 62