1144091Sdas/*-
2144091Sdas * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
3144091Sdas * All rights reserved.
4144091Sdas *
5144091Sdas * Redistribution and use in source and binary forms, with or without
6144091Sdas * modification, are permitted provided that the following conditions
7144091Sdas * are met:
8144091Sdas * 1. Redistributions of source code must retain the above copyright
9144091Sdas *    notice, this list of conditions and the following disclaimer.
10144091Sdas * 2. Redistributions in binary form must reproduce the above copyright
11144091Sdas *    notice, this list of conditions and the following disclaimer in the
12144091Sdas *    documentation and/or other materials provided with the distribution.
13144091Sdas *
14144091Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15144091Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16144091Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17144091Sdas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18144091Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19144091Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20144091Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21144091Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22144091Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23144091Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24144091Sdas * SUCH DAMAGE.
25144091Sdas */
26144091Sdas
27144091Sdas/*
28144091Sdas * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>.
29144091Sdas */
30144091Sdas
31144091Sdas#include <machine/asm.h>
32144091Sdas__FBSDID("$FreeBSD$");
33144091Sdas
34144091SdasENTRY(remquof)
35144091Sdas	flds	8(%esp)
36144091Sdas	flds	4(%esp)
37144091Sdas1:	fprem1
38144091Sdas	fstsw	%ax
39144091Sdas	sahf
40144091Sdas	jp	1b
41144091Sdas	fstp	%st(1)
42144091Sdas/* Extract the three low-order bits of the quotient from C0,C3,C1. */
43144091Sdas	shrl	$6,%eax
44144091Sdas	movl	%eax,%ecx
45144091Sdas	andl	$0x108,%eax
46144091Sdas	rorl	$7,%eax
47144091Sdas	orl	%eax,%ecx
48144091Sdas	roll	$4,%eax
49144091Sdas	orl	%ecx,%eax
50144091Sdas	andl	$7,%eax
51144091Sdas/* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
52144091Sdas	movl	8(%esp),%ecx
53144091Sdas	xorl	4(%esp),%ecx
54144091Sdas	sarl	$16,%ecx
55144091Sdas	sarl	$16,%ecx
56144091Sdas	xorl	%ecx,%eax
57144091Sdas	andl	$1,%ecx
58144091Sdas	addl	%ecx,%eax
59144091Sdas/* Store the quotient and return. */
60144091Sdas	movl	12(%esp),%ecx
61144091Sdas	movl	%eax,(%ecx)
62144091Sdas	ret
63192760SattilioEND(remquof)
64217108Skib
65217108Skib	.section .note.GNU-stack,"",%progbits
66