1177768Sdas/*-
2177768Sdas * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>
3177768Sdas * All rights reserved.
4177768Sdas *
5177768Sdas * Redistribution and use in source and binary forms, with or without
6177768Sdas * modification, are permitted provided that the following conditions
7177768Sdas * are met:
8177768Sdas * 1. Redistributions of source code must retain the above copyright
9177768Sdas *    notice, this list of conditions and the following disclaimer.
10177768Sdas * 2. Redistributions in binary form must reproduce the above copyright
11177768Sdas *    notice, this list of conditions and the following disclaimer in the
12177768Sdas *    documentation and/or other materials provided with the distribution.
13177768Sdas *
14177768Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15177768Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16177768Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17177768Sdas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18177768Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19177768Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20177768Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21177768Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22177768Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23177768Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24177768Sdas * SUCH DAMAGE.
25177768Sdas */
26177768Sdas
27177768Sdas/*
28177768Sdas * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>.
29177768Sdas */
30177768Sdas
31177768Sdas#include <machine/asm.h>
32177768Sdas__FBSDID("$FreeBSD$");
33177768Sdas
34177768SdasENTRY(remquol)
35177768Sdas	fldt	16(%esp)
36177768Sdas	fldt	4(%esp)
37177768Sdas1:	fprem1
38177768Sdas	fstsw	%ax
39177768Sdas	sahf
40177768Sdas	jp	1b
41177768Sdas	fstp	%st(1)
42177768Sdas/* Extract the three low-order bits of the quotient from C0,C3,C1. */
43177768Sdas	shrl	$6,%eax
44177768Sdas	movl	%eax,%ecx
45177768Sdas	andl	$0x108,%eax
46177768Sdas	rorl	$7,%eax
47177768Sdas	orl	%eax,%ecx
48177768Sdas	roll	$4,%eax
49177768Sdas	orl	%ecx,%eax
50177768Sdas	andl	$7,%eax
51177768Sdas/* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
52177768Sdas	movl	24(%esp),%ecx
53177768Sdas	xorl	12(%esp),%ecx
54177768Sdas	movsx	%cx,%ecx
55177768Sdas	sarl	$16,%ecx
56177768Sdas	sarl	$16,%ecx
57177768Sdas	xorl	%ecx,%eax
58177768Sdas	andl	$1,%ecx
59177768Sdas	addl	%ecx,%eax
60177768Sdas/* Store the quotient and return. */
61177768Sdas	movl	28(%esp),%ecx
62177768Sdas	movl	%eax,(%ecx)
63177768Sdas	ret
64217108Skib
65217108Skib	.section .note.GNU-stack,"",%progbits
66