1178580Simp/* $NetBSD: modf.S,v 1.10 2003/08/07 16:42:15 agc Exp $ */ 2178580Simp 3178580Simp/*- 4178580Simp * Copyright (c) 1991, 1993, 1995 5178580Simp * The Regents of the University of California. All rights reserved. 6178580Simp * 7178580Simp * This code is derived from software contributed to Berkeley by 8178580Simp * Ralph Campbell. 9178580Simp * 10178580Simp * Redistribution and use in source and binary forms, with or without 11178580Simp * modification, are permitted provided that the following conditions 12178580Simp * are met: 13178580Simp * 1. Redistributions of source code must retain the above copyright 14178580Simp * notice, this list of conditions and the following disclaimer. 15178580Simp * 2. Redistributions in binary form must reproduce the above copyright 16178580Simp * notice, this list of conditions and the following disclaimer in the 17178580Simp * documentation and/or other materials provided with the distribution. 18178580Simp * 3. Neither the name of the University nor the names of its contributors 19178580Simp * may be used to endorse or promote products derived from this software 20178580Simp * without specific prior written permission. 21178580Simp * 22178580Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23178580Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24178580Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25178580Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26178580Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27178580Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28178580Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29178580Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30178580Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31178580Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32178580Simp * SUCH DAMAGE. 33178580Simp */ 34178580Simp 35178580Simp#include <machine/asm.h> 36178580Simp__FBSDID("$FreeBSD$"); 37178580Simp 38178580Simp#if defined(LIBC_SCCS) && !defined(lint) 39178580Simp ASMSTR("from: @(#)modf.s 8.1 (Berkeley) 6/4/93") 40178580Simp ASMSTR("$NetBSD: modf.S,v 1.10 2003/08/07 16:42:15 agc Exp $") 41178580Simp#endif /* LIBC_SCCS and not lint */ 42178580Simp 43178580Simp#ifdef __ABICALLS__ 44178580Simp .abicalls 45178580Simp#endif 46178580Simp 47178580Simp/* 48178580Simp * double modf(val, iptr) 49178580Simp * double val, *iptr; 50178580Simp * returns: xxx and n (in *iptr) where val == n.xxx 51178580Simp */ 52178580SimpLEAF(modf) 53178580Simp#ifdef __ABICALLS__ 54178580Simp .set noreorder 55178580Simp .cpload t9 56178580Simp .set reorder 57178580Simp#endif 58178580Simp cfc1 t0, $31 # get the control register 59178580Simp li.d $f2, 4503599627370496e0 # f2 <- 2^52 60178580Simp 61178580Simp or t1, t0, 0x3 # set rounding mode to round to zero 62178580Simp xor t1, t1, 0x2 # (i.e., 01) 63178580Simp ctc1 t1, $31 64178580Simp 65178580Simp mov.d $f0, $f12 # f0 <- f12 66178580Simp abs.d $f4, $f12 # f4 <- |f12| 67178580Simp c.olt.d $f4, $f2 # f4 ? < f2 68178580Simp bc1f 1f # leave f0 alone if Nan, infinity 69178580Simp # or >=2^52 70178580Simp c.eq.d $f12,$f4 # was f12 positive ? 71178580Simp add.d $f4,$f2,$f4 # round off to integer 72178580Simp bc1f 2f # No -> will have to negate result 73178580Simp sub.d $f0,$f4,$f2 # Remove fudge factor 74178580Simp j 1f # integer fraction got 75178580Simp2: 76178580Simp sub.d $f0,$f2,$f4 # Remove fudge factor and negate 77178580Simp1: 78178580Simp ctc1 t0, $31 # restore old rounding mode 79178580Simp s.d $f0, 0(a2) # save the integer part 80178580Simp sub.d $f0, $f12, $f0 # subtract val - integer part 81178580Simp j ra 82178580SimpEND(modf) 83