13b9141eeSDavid Schultz/*- 23b9141eeSDavid Schultz * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> 33b9141eeSDavid Schultz * All rights reserved. 43b9141eeSDavid Schultz * 53b9141eeSDavid Schultz * Redistribution and use in source and binary forms, with or without 63b9141eeSDavid Schultz * modification, are permitted provided that the following conditions 73b9141eeSDavid Schultz * are met: 83b9141eeSDavid Schultz * 1. Redistributions of source code must retain the above copyright 93b9141eeSDavid Schultz * notice, this list of conditions and the following disclaimer. 103b9141eeSDavid Schultz * 2. Redistributions in binary form must reproduce the above copyright 113b9141eeSDavid Schultz * notice, this list of conditions and the following disclaimer in the 123b9141eeSDavid Schultz * documentation and/or other materials provided with the distribution. 133b9141eeSDavid Schultz * 143b9141eeSDavid Schultz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 153b9141eeSDavid Schultz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 163b9141eeSDavid Schultz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 173b9141eeSDavid Schultz * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 183b9141eeSDavid Schultz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 193b9141eeSDavid Schultz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 203b9141eeSDavid Schultz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 213b9141eeSDavid Schultz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 223b9141eeSDavid Schultz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 233b9141eeSDavid Schultz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 243b9141eeSDavid Schultz * SUCH DAMAGE. 253b9141eeSDavid Schultz */ 263b9141eeSDavid Schultz 273b9141eeSDavid Schultz/* 283b9141eeSDavid Schultz * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>. 293b9141eeSDavid Schultz */ 303b9141eeSDavid Schultz 313b9141eeSDavid Schultz#include <machine/asm.h> 323b9141eeSDavid SchultzENTRY(remquof) 333b9141eeSDavid Schultz flds 8(%esp) 343b9141eeSDavid Schultz flds 4(%esp) 353b9141eeSDavid Schultz1: fprem1 363b9141eeSDavid Schultz fstsw %ax 373b9141eeSDavid Schultz sahf 383b9141eeSDavid Schultz jp 1b 393b9141eeSDavid Schultz fstp %st(1) 403b9141eeSDavid Schultz/* Extract the three low-order bits of the quotient from C0,C3,C1. */ 413b9141eeSDavid Schultz shrl $6,%eax 423b9141eeSDavid Schultz movl %eax,%ecx 433b9141eeSDavid Schultz andl $0x108,%eax 443b9141eeSDavid Schultz rorl $7,%eax 453b9141eeSDavid Schultz orl %eax,%ecx 463b9141eeSDavid Schultz roll $4,%eax 473b9141eeSDavid Schultz orl %ecx,%eax 483b9141eeSDavid Schultz andl $7,%eax 493b9141eeSDavid Schultz/* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ 503b9141eeSDavid Schultz movl 8(%esp),%ecx 513b9141eeSDavid Schultz xorl 4(%esp),%ecx 523b9141eeSDavid Schultz sarl $16,%ecx 533b9141eeSDavid Schultz sarl $16,%ecx 543b9141eeSDavid Schultz xorl %ecx,%eax 553b9141eeSDavid Schultz andl $1,%ecx 563b9141eeSDavid Schultz addl %ecx,%eax 573b9141eeSDavid Schultz/* Store the quotient and return. */ 583b9141eeSDavid Schultz movl 12(%esp),%ecx 593b9141eeSDavid Schultz movl %eax,(%ecx) 603b9141eeSDavid Schultz ret 619235ed71SAttilio RaoEND(remquof) 62*8997563cSKonstantin Belousov 63*8997563cSKonstantin Belousov .section .note.GNU-stack,"",%progbits 64