xref: /linux/arch/mips/math-emu/sp_2008class.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*ea65cc9bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
238db37baSMarkos Chandras /*
338db37baSMarkos Chandras  * IEEE754 floating point arithmetic
438db37baSMarkos Chandras  * single precision: CLASS.f
538db37baSMarkos Chandras  * FPR[fd] = class(FPR[fs])
638db37baSMarkos Chandras  *
738db37baSMarkos Chandras  * MIPS floating point support
838db37baSMarkos Chandras  * Copyright (C) 2015 Imagination Technologies, Ltd.
938db37baSMarkos Chandras  * Author: Markos Chandras <markos.chandras@imgtec.com>
1038db37baSMarkos Chandras  */
1138db37baSMarkos Chandras 
1238db37baSMarkos Chandras #include "ieee754sp.h"
1338db37baSMarkos Chandras 
ieee754sp_2008class(union ieee754sp x)1438db37baSMarkos Chandras int ieee754sp_2008class(union ieee754sp x)
1538db37baSMarkos Chandras {
1638db37baSMarkos Chandras 	COMPXSP;
1738db37baSMarkos Chandras 
1838db37baSMarkos Chandras 	EXPLODEXSP;
1938db37baSMarkos Chandras 
2038db37baSMarkos Chandras 	/*
2138db37baSMarkos Chandras 	 * 10 bit mask as follows:
2238db37baSMarkos Chandras 	 *
2338db37baSMarkos Chandras 	 * bit0 = SNAN
2438db37baSMarkos Chandras 	 * bit1 = QNAN
2538db37baSMarkos Chandras 	 * bit2 = -INF
2638db37baSMarkos Chandras 	 * bit3 = -NORM
2738db37baSMarkos Chandras 	 * bit4 = -DNORM
2838db37baSMarkos Chandras 	 * bit5 = -ZERO
2938db37baSMarkos Chandras 	 * bit6 = INF
3038db37baSMarkos Chandras 	 * bit7 = NORM
3138db37baSMarkos Chandras 	 * bit8 = DNORM
3238db37baSMarkos Chandras 	 * bit9 = ZERO
3338db37baSMarkos Chandras 	 */
3438db37baSMarkos Chandras 
3538db37baSMarkos Chandras 	switch(xc) {
3638db37baSMarkos Chandras 	case IEEE754_CLASS_SNAN:
3738db37baSMarkos Chandras 		return 0x01;
3838db37baSMarkos Chandras 	case IEEE754_CLASS_QNAN:
3938db37baSMarkos Chandras 		return 0x02;
4038db37baSMarkos Chandras 	case IEEE754_CLASS_INF:
4138db37baSMarkos Chandras 		return 0x04 << (xs ? 0 : 4);
4238db37baSMarkos Chandras 	case IEEE754_CLASS_NORM:
4338db37baSMarkos Chandras 		return 0x08 << (xs ? 0 : 4);
4438db37baSMarkos Chandras 	case IEEE754_CLASS_DNORM:
4538db37baSMarkos Chandras 		return 0x10 << (xs ? 0 : 4);
4638db37baSMarkos Chandras 	case IEEE754_CLASS_ZERO:
4738db37baSMarkos Chandras 		return 0x20 << (xs ? 0 : 4);
4838db37baSMarkos Chandras 	default:
4938db37baSMarkos Chandras 		pr_err("Unknown class: %d\n", xc);
5038db37baSMarkos Chandras 		return 0;
5138db37baSMarkos Chandras 	}
5238db37baSMarkos Chandras }
53