| 1 | /*- |
| 2 | * Copyright (c) 1991 The Regents of the University of California. |
| 3 | * 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 5.4 (Berkeley) %G%") |
| 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 | */ |
| 22 | LEAF(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 |
| 34 | END(modf) |