xref: /csrg-svn/lib/libc/mips/gen/modf.s (revision 61143)
152707Sbostic/*-
2*61143Sbostic * Copyright (c) 1991, 1993
3*61143Sbostic *	The Regents of the University of California.  All rights reserved.
452707Sbostic *
552707Sbostic * This code is derived from software contributed to Berkeley by
652707Sbostic * Ralph Campbell.
752707Sbostic *
852707Sbostic * %sccs.include.redist.c%
952707Sbostic */
1052707Sbostic
1155705Sralph#include <machine/machAsmDefs.h>
1252739Sbostic
1352707Sbostic#if defined(LIBC_SCCS) && !defined(lint)
14*61143Sbostic	ASMSTR("@(#)modf.s	8.1 (Berkeley) 06/04/93")
1552707Sbostic#endif /* LIBC_SCCS and not lint */
1652707Sbostic
1752707Sbostic/*
1852707Sbostic * double modf(val, iptr)
1952707Sbostic *	double val, *iptr;
2052707Sbostic * returns: xxx and n (in *iptr) where val == n.xxx
2152707Sbostic */
2252707SbosticLEAF(modf)
2352962Sralph	cfc1	t0, $31			# get the control register
2452962Sralph	cfc1	t0, $31			# get the control register
2552962Sralph	or	t1, t0, 0x3		# set rounding mode to round to zero
2652962Sralph	xor	t1, t1, 0x2		#  (i.e., 01)
2752962Sralph	ctc1	t1, $31
2852962Sralph	cvt.w.d	$f0, $f12		# convert val to integer
2952962Sralph	cvt.d.w	$f0, $f0		# convert back to double
3052962Sralph	ctc1	t0, $31			# restore old rounding mode
3152962Sralph	s.d	$f0, 0(a2)		# save the integer part
3252962Sralph	sub.d	$f0, $f12, $f0		# subtract val - integer part
3352707Sbostic	j	ra
3452707SbosticEND(modf)
35