/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
/* $Header: fp_class.s,v 1.9.2.1 92/06/24 13:59:22 marker Exp $ */

#include "sys/regdef.h"
#include "sys/asm.h"
#include "fp_class.h"
#include "sys/softfp.h"

/*
 * fp_class_d(d)	
 * double d;
 */
#ifdef  SYSTYPE_POSIX
LEAF(_fp_class_d)
#else  	/* !SYSTYPE_POSIX */
LEAF(fp_class_d)
#endif 	/* !SYSTYPE_POSIX */
	# Get the double from f12
	mfc1	a2,$f13
	mfc1	a3,$f12

	# Break down the double into sign, exponent and fraction
	srl	a1,a2,DEXP_SHIFT
	move	a0,a1
	and	a1,DEXP_MASK
	and	a0,SIGNBIT>>DEXP_SHIFT
	and	a2,DFRAC_MASK

	# Check for infinities and Nan's
	bne	a1,DEXP_INF,4f
	bne	a2,zero,2f
	bne	a3,zero,2f
	bne	a0,zero,1f
	li	v0,FP_POS_INF
	j	ra
1:
	li	v0,FP_NEG_INF
	j	ra
2:	# Check to see if this is a signaling NaN
	and	a0,a2,DSNANBIT_MASK
	beq	a0,zero,3f
	li	v0,FP_SNAN
	j	ra
3:	li	v0,FP_QNAN
	j	ra
4:
	# Check for zeroes and denorms
	bne	a1,zero,8f
	bne	a2,zero,6f
	bne	a3,zero,6f
	bne	a0,zero,5f
	li	v0,FP_POS_ZERO
	j	ra
5:	li	v0,FP_NEG_ZERO
	j	ra
6:	bne	a0,zero,7f
	li	v0,FP_POS_DENORM
	j	ra
7:	li	v0,FP_NEG_DENORM
	j	ra
8:
	# It is just a normal number
	bne	a0,zero,9f
	li	v0,FP_POS_NORM
	j	ra
9:	li	v0,FP_NEG_NORM
	j	ra
#ifdef  SYSTYPE_POSIX
END(_fp_class_d)
#else  	/* !SYSTYPE_POSIX */
END(fp_class_d)
#endif 	/* !SYSTYPE_POSIX */

/*
 * fp_class_f(f)	
 * float d;
 */
#ifdef  SYSTYPE_POSIX
LEAF(_fp_class_f)
#else  	/* !SYSTYPE_POSIX */
LEAF(fp_class_f)
#endif 	/* !SYSTYPE_POSIX */
	# Get the float from f12
	mfc1	a2,$f12

	# Break down the float into sign, exponent and fraction
	srl	a1,a2,SEXP_SHIFT
	move	a0,a1
	and	a1,SEXP_MASK
	and	a0,SIGNBIT>>SEXP_SHIFT
	and	a2,SFRAC_MASK

	# Check for infinities and Nan's
	bne	a1,SEXP_INF,4f
	bne	a2,zero,2f
	bne	a0,zero,1f
	li	v0,FP_POS_INF
	j	ra
1:
	li	v0,FP_NEG_INF
	j	ra
2:	# Check to see if this is a signaling NaN
	and	a0,a2,SSNANBIT_MASK
	beq	a0,zero,3f
	li	v0,FP_SNAN
	j	ra
3:	li	v0,FP_QNAN
	j	ra
4:
	# Check for zeroes and denorms
	bne	a1,zero,8f
	bne	a2,zero,6f
	bne	a0,zero,5f
	li	v0,FP_POS_ZERO
	j	ra
5:	li	v0,FP_NEG_ZERO
	j	ra
6:	bne	a0,zero,7f
	li	v0,FP_POS_DENORM
	j	ra
7:	li	v0,FP_NEG_DENORM
	j	ra
8:
	# It is just a normal number
	bne	a0,zero,9f
	li	v0,FP_POS_NORM
	j	ra
9:	li	v0,FP_NEG_NORM
	j	ra
#ifdef  SYSTYPE_POSIX
END(_fp_class_f)
#else  	/* !SYSTYPE_POSIX */
END(fp_class_f)
#endif 	/* !SYSTYPE_POSIX */
