1074fb64dSDavid Schultz/*- 2074fb64dSDavid Schultz * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG> 3074fb64dSDavid Schultz * All rights reserved. 4074fb64dSDavid Schultz * 5074fb64dSDavid Schultz * Redistribution and use in source and binary forms, with or without 6074fb64dSDavid Schultz * modification, are permitted provided that the following conditions 7074fb64dSDavid Schultz * are met: 8074fb64dSDavid Schultz * 1. Redistributions of source code must retain the above copyright 9074fb64dSDavid Schultz * notice, this list of conditions and the following disclaimer. 10074fb64dSDavid Schultz * 2. Redistributions in binary form must reproduce the above copyright 11074fb64dSDavid Schultz * notice, this list of conditions and the following disclaimer in the 12074fb64dSDavid Schultz * documentation and/or other materials provided with the distribution. 13074fb64dSDavid Schultz * 14074fb64dSDavid Schultz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15074fb64dSDavid Schultz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16074fb64dSDavid Schultz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17074fb64dSDavid Schultz * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18074fb64dSDavid Schultz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19074fb64dSDavid Schultz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20074fb64dSDavid Schultz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21074fb64dSDavid Schultz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22074fb64dSDavid Schultz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23074fb64dSDavid Schultz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24074fb64dSDavid Schultz * SUCH DAMAGE. 25074fb64dSDavid Schultz */ 26074fb64dSDavid Schultz 27074fb64dSDavid Schultz/* 28074fb64dSDavid Schultz * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>. 29074fb64dSDavid Schultz */ 30074fb64dSDavid Schultz 31074fb64dSDavid Schultz#include <machine/asm.h> 32074fb64dSDavid SchultzENTRY(remquol) 33074fb64dSDavid Schultz fldt 16(%esp) 34074fb64dSDavid Schultz fldt 4(%esp) 35074fb64dSDavid Schultz1: fprem1 36074fb64dSDavid Schultz fstsw %ax 37074fb64dSDavid Schultz sahf 38074fb64dSDavid Schultz jp 1b 39074fb64dSDavid Schultz fstp %st(1) 40074fb64dSDavid Schultz/* Extract the three low-order bits of the quotient from C0,C3,C1. */ 41074fb64dSDavid Schultz shrl $6,%eax 42074fb64dSDavid Schultz movl %eax,%ecx 43074fb64dSDavid Schultz andl $0x108,%eax 44074fb64dSDavid Schultz rorl $7,%eax 45074fb64dSDavid Schultz orl %eax,%ecx 46074fb64dSDavid Schultz roll $4,%eax 47074fb64dSDavid Schultz orl %ecx,%eax 48074fb64dSDavid Schultz andl $7,%eax 49074fb64dSDavid Schultz/* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ 50074fb64dSDavid Schultz movl 24(%esp),%ecx 51074fb64dSDavid Schultz xorl 12(%esp),%ecx 52074fb64dSDavid Schultz movsx %cx,%ecx 53074fb64dSDavid Schultz sarl $16,%ecx 54074fb64dSDavid Schultz sarl $16,%ecx 55074fb64dSDavid Schultz xorl %ecx,%eax 56074fb64dSDavid Schultz andl $1,%ecx 57074fb64dSDavid Schultz addl %ecx,%eax 58074fb64dSDavid Schultz/* Store the quotient and return. */ 59074fb64dSDavid Schultz movl 28(%esp),%ecx 60074fb64dSDavid Schultz movl %eax,(%ecx) 61074fb64dSDavid Schultz ret 62*78599c32SConrad MeyerEND(remquol) 638997563cSKonstantin Belousov 648997563cSKonstantin Belousov .section .note.GNU-stack,"",%progbits 65