s_remquo.S revision 144091
1226584Sdim/*- 2226584Sdim * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> 3226584Sdim * All rights reserved. 4226584Sdim * 5226584Sdim * Redistribution and use in source and binary forms, with or without 6226584Sdim * modification, are permitted provided that the following conditions 7226584Sdim * are met: 8226584Sdim * 1. Redistributions of source code must retain the above copyright 9226584Sdim * notice, this list of conditions and the following disclaimer. 10226584Sdim * 2. Redistributions in binary form must reproduce the above copyright 11226584Sdim * notice, this list of conditions and the following disclaimer in the 12226584Sdim * documentation and/or other materials provided with the distribution. 13226584Sdim * 14226584Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15226584Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16226584Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17226584Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18252723Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19252723Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20252723Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21226584Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22226584Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23226584Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24226584Sdim * SUCH DAMAGE. 25226584Sdim */ 26226584Sdim 27226584Sdim/* 28226584Sdim * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>. 29226584Sdim */ 30226584Sdim 31226584Sdim#include <machine/asm.h> 32226584Sdim__FBSDID("$FreeBSD: head/lib/msun/i387/s_remquo.S 144091 2005-03-25 04:40:44Z das $"); 33235633Sdim 34235633SdimENTRY(remquo) 35235633Sdim fldl 12(%esp) 36235633Sdim fldl 4(%esp) 37235633Sdim1: fprem1 38235633Sdim fstsw %ax 39235633Sdim sahf 40235633Sdim jp 1b 41235633Sdim fstp %st(1) 42235633Sdim/* Extract the three low-order bits of the quotient from C0,C3,C1. */ 43235633Sdim shrl $6,%eax 44235633Sdim movl %eax,%ecx 45235633Sdim andl $0x108,%eax 46235633Sdim rorl $7,%eax 47235633Sdim orl %eax,%ecx 48235633Sdim roll $4,%eax 49235633Sdim orl %ecx,%eax 50235633Sdim andl $7,%eax 51235633Sdim/* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ 52235633Sdim movl 16(%esp),%ecx 53252723Sdim xorl 8(%esp),%ecx 54252723Sdim sarl $16,%ecx 55252723Sdim sarl $16,%ecx 56252723Sdim xorl %ecx,%eax 57252723Sdim andl $1,%ecx 58252723Sdim addl %ecx,%eax 59252723Sdim/* Store the quotient and return. */ 60252723Sdim movl 20(%esp),%ecx 61252723Sdim movl %eax,(%ecx) 62252723Sdim ret 63252723Sdim