s_remquof.S revision 217108
1209513Simp/*-
2209513Simp * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
3209552Simp * All rights reserved.
4209513Simp *
5209513Simp * Redistribution and use in source and binary forms, with or without
6209513Simp * modification, are permitted provided that the following conditions
7209513Simp * are met:
8209513Simp * 1. Redistributions of source code must retain the above copyright
9209513Simp *    notice, this list of conditions and the following disclaimer.
10209513Simp * 2. Redistributions in binary form must reproduce the above copyright
11209513Simp *    notice, this list of conditions and the following disclaimer in the
12209513Simp *    documentation and/or other materials provided with the distribution.
13209513Simp *
14209513Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15209513Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16209513Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17209513Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18209513Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19209513Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20209513Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21209513Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22209513Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23209513Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24209513Simp * SUCH DAMAGE.
25209513Simp */
26209513Simp
27209513Simp/*
28211489Simp * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>.
29211730Simp */
30212337Simp
31211730Simp#include <machine/asm.h>
32211489Simp__FBSDID("$FreeBSD: head/lib/msun/i387/s_remquof.S 217108 2011-01-07 16:13:12Z kib $");
33211730Simp
34211730SimpENTRY(remquof)
35211730Simp	flds	8(%esp)
36211730Simp	flds	4(%esp)
37211730Simp1:	fprem1
38211730Simp	fstsw	%ax
39211730Simp	sahf
40211730Simp	jp	1b
41211730Simp	fstp	%st(1)
42211730Simp/* Extract the three low-order bits of the quotient from C0,C3,C1. */
43212337Simp	shrl	$6,%eax
44212337Simp	movl	%eax,%ecx
45212337Simp	andl	$0x108,%eax
46211730Simp	rorl	$7,%eax
47211730Simp	orl	%eax,%ecx
48211730Simp	roll	$4,%eax
49211730Simp	orl	%ecx,%eax
50209513Simp	andl	$7,%eax
51209513Simp/* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
52211730Simp	movl	8(%esp),%ecx
53211489Simp	xorl	4(%esp),%ecx
54211730Simp	sarl	$16,%ecx
55211730Simp	sarl	$16,%ecx
56211730Simp	xorl	%ecx,%eax
57211730Simp	andl	$1,%ecx
58211730Simp	addl	%ecx,%eax
59211489Simp/* Store the quotient and return. */
60209513Simp	movl	12(%esp),%ecx
61233222Sjpaetzel	movl	%eax,(%ecx)
62233222Sjpaetzel	ret
63233222SjpaetzelEND(remquof)
64233222Sjpaetzel
65233222Sjpaetzel	.section .note.GNU-stack,"",%progbits
66233573Sjpaetzel