4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / lib / libc / mips / gen / modf.s
CommitLineData
7780eb5e 1/*-
234579bd
KB
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
7780eb5e
KB
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ralph Campbell.
7 *
8 * %sccs.include.redist.c%
9 */
10
073522ce 11#include <machine/machAsmDefs.h>
f1e99c02 12
7780eb5e 13#if defined(LIBC_SCCS) && !defined(lint)
234579bd 14 ASMSTR("@(#)modf.s 8.1 (Berkeley) %G%")
7780eb5e
KB
15#endif /* LIBC_SCCS and not lint */
16
7780eb5e
KB
17/*
18 * double modf(val, iptr)
19 * double val, *iptr;
20 * returns: xxx and n (in *iptr) where val == n.xxx
21 */
22LEAF(modf)
528228db
RC
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
7780eb5e
KB
33 j ra
34END(modf)