xref: /original-bsd/lib/libc/mips/gen/modf.s (revision c3e32dec)
1/*-
2 * Copyright (c) 1991, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ralph Campbell.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#include <machine/machAsmDefs.h>
12
13#if defined(LIBC_SCCS) && !defined(lint)
14	ASMSTR("@(#)modf.s	8.1 (Berkeley) 06/04/93")
15#endif /* LIBC_SCCS and not lint */
16
17/*
18 * double modf(val, iptr)
19 *	double val, *iptr;
20 * returns: xxx and n (in *iptr) where val == n.xxx
21 */
22LEAF(modf)
23	cfc1	t0, $31			# get the control register
24	cfc1	t0, $31			# get the control register
25	or	t1, t0, 0x3		# set rounding mode to round to zero
26	xor	t1, t1, 0x2		#  (i.e., 01)
27	ctc1	t1, $31
28	cvt.w.d	$f0, $f12		# convert val to integer
29	cvt.d.w	$f0, $f0		# convert back to double
30	ctc1	t0, $31			# restore old rounding mode
31	s.d	$f0, 0(a2)		# save the integer part
32	sub.d	$f0, $f12, $f0		# subtract val - integer part
33	j	ra
34END(modf)
35