1*2fe8fb19SBen Gras/* $NetBSD: s_modf.S,v 1.1 2006/03/22 20:45:58 drochner Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras/*- 4*2fe8fb19SBen Gras * Copyright (c) 1990 The Regents of the University of California. 5*2fe8fb19SBen Gras * All rights reserved. 6*2fe8fb19SBen Gras * 7*2fe8fb19SBen Gras * This code is derived from software contributed to Berkeley by 8*2fe8fb19SBen Gras * Sean Eric Fagan. 9*2fe8fb19SBen Gras * 10*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 11*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions 12*2fe8fb19SBen Gras * are met: 13*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 14*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 15*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 16*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 17*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 18*2fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors 19*2fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 20*2fe8fb19SBen Gras * without specific prior written permission. 21*2fe8fb19SBen Gras * 22*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*2fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*2fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*2fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*2fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*2fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*2fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*2fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*2fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*2fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*2fe8fb19SBen Gras * SUCH DAMAGE. 33*2fe8fb19SBen Gras * 34*2fe8fb19SBen Gras * from: @(#)modf.s 5.5 (Berkeley) 3/18/91 35*2fe8fb19SBen Gras */ 36*2fe8fb19SBen Gras 37*2fe8fb19SBen Gras#include <machine/asm.h> 38*2fe8fb19SBen Gras#if defined(LIBC_SCCS) 39*2fe8fb19SBen Gras RCSID("$NetBSD: s_modf.S,v 1.1 2006/03/22 20:45:58 drochner Exp $") 40*2fe8fb19SBen Gras#endif 41*2fe8fb19SBen Gras 42*2fe8fb19SBen Gras/* 43*2fe8fb19SBen Gras * modf(value, iptr): return fractional part of value, and stores the 44*2fe8fb19SBen Gras * integral part into iptr (a pointer to double). 45*2fe8fb19SBen Gras * 46*2fe8fb19SBen Gras * Written by Sean Eric Fagan (sef@kithrup.COM) 47*2fe8fb19SBen Gras * Sun Mar 11 20:27:30 PST 1990 48*2fe8fb19SBen Gras */ 49*2fe8fb19SBen Gras 50*2fe8fb19SBen Gras/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ 51*2fe8fb19SBen GrasENTRY(modf) 52*2fe8fb19SBen Gras#ifdef __x86_64__ 53*2fe8fb19SBen Gras pushq %rbp 54*2fe8fb19SBen Gras movq %rsp,%rbp 55*2fe8fb19SBen Gras subq $24,%rsp 56*2fe8fb19SBen Gras 57*2fe8fb19SBen Gras /* Set chop mode. */ 58*2fe8fb19SBen Gras fnstcw -12(%rbp) 59*2fe8fb19SBen Gras movw -12(%rbp),%dx 60*2fe8fb19SBen Gras orw $3072,%dx 61*2fe8fb19SBen Gras movw %dx,-16(%rbp) 62*2fe8fb19SBen Gras fldcw -16(%rbp) 63*2fe8fb19SBen Gras 64*2fe8fb19SBen Gras /* Get integral part. */ 65*2fe8fb19SBen Gras movsd %xmm0,-24(%rbp) 66*2fe8fb19SBen Gras fldl -24(%rbp) 67*2fe8fb19SBen Gras frndint 68*2fe8fb19SBen Gras fstpl -8(%rbp) 69*2fe8fb19SBen Gras 70*2fe8fb19SBen Gras /* Restore control word. */ 71*2fe8fb19SBen Gras fldcw -12(%rbp) 72*2fe8fb19SBen Gras 73*2fe8fb19SBen Gras /* Store integral part. */ 74*2fe8fb19SBen Gras movsd -8(%rbp),%xmm0 75*2fe8fb19SBen Gras movsd %xmm0,(%rdi) 76*2fe8fb19SBen Gras 77*2fe8fb19SBen Gras /* Get fractional part and return it. */ 78*2fe8fb19SBen Gras fldl -24(%rbp) 79*2fe8fb19SBen Gras fsubl -8(%rbp) 80*2fe8fb19SBen Gras fstpl -24(%rbp) 81*2fe8fb19SBen Gras movsd -24(%rbp),%xmm0 82*2fe8fb19SBen Gras#else 83*2fe8fb19SBen Gras pushl %ebp 84*2fe8fb19SBen Gras movl %esp,%ebp 85*2fe8fb19SBen Gras subl $16,%esp 86*2fe8fb19SBen Gras fnstcw -12(%ebp) 87*2fe8fb19SBen Gras movw -12(%ebp),%dx 88*2fe8fb19SBen Gras orw $3072,%dx 89*2fe8fb19SBen Gras movw %dx,-16(%ebp) 90*2fe8fb19SBen Gras fldcw -16(%ebp) 91*2fe8fb19SBen Gras fldl 8(%ebp) 92*2fe8fb19SBen Gras frndint 93*2fe8fb19SBen Gras fstpl -8(%ebp) 94*2fe8fb19SBen Gras fldcw -12(%ebp) 95*2fe8fb19SBen Gras movl 16(%ebp),%eax 96*2fe8fb19SBen Gras movl -8(%ebp),%edx 97*2fe8fb19SBen Gras movl -4(%ebp),%ecx 98*2fe8fb19SBen Gras movl %edx,(%eax) 99*2fe8fb19SBen Gras movl %ecx,4(%eax) 100*2fe8fb19SBen Gras fldl 8(%ebp) 101*2fe8fb19SBen Gras fsubl -8(%ebp) 102*2fe8fb19SBen Gras jmp L1 103*2fe8fb19SBen GrasL1: 104*2fe8fb19SBen Gras#endif 105*2fe8fb19SBen Gras leave 106*2fe8fb19SBen Gras ret 107