s_remquof.S revision 217108
1219820Sjeff/*-
2219820Sjeff * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
3219820Sjeff * All rights reserved.
4219820Sjeff *
5219820Sjeff * Redistribution and use in source and binary forms, with or without
6219820Sjeff * modification, are permitted provided that the following conditions
7219820Sjeff * are met:
8219820Sjeff * 1. Redistributions of source code must retain the above copyright
9219820Sjeff *    notice, this list of conditions and the following disclaimer.
10219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright
11219820Sjeff *    notice, this list of conditions and the following disclaimer in the
12219820Sjeff *    documentation and/or other materials provided with the distribution.
13219820Sjeff *
14219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15219820Sjeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16219820Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17219820Sjeff * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18219820Sjeff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19219820Sjeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20219820Sjeff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21219820Sjeff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22219820Sjeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23219820Sjeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24219820Sjeff * SUCH DAMAGE.
25219820Sjeff */
26219820Sjeff
27219820Sjeff/*
28219820Sjeff * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>.
29219820Sjeff */
30219820Sjeff
31219820Sjeff#include <machine/asm.h>
32219820Sjeff__FBSDID("$FreeBSD: head/lib/msun/i387/s_remquof.S 217108 2011-01-07 16:13:12Z kib $");
33219820Sjeff
34219820SjeffENTRY(remquof)
35219820Sjeff	flds	8(%esp)
36219820Sjeff	flds	4(%esp)
37219820Sjeff1:	fprem1
38219820Sjeff	fstsw	%ax
39219820Sjeff	sahf
40219820Sjeff	jp	1b
41219820Sjeff	fstp	%st(1)
42219820Sjeff/* Extract the three low-order bits of the quotient from C0,C3,C1. */
43219820Sjeff	shrl	$6,%eax
44219820Sjeff	movl	%eax,%ecx
45219820Sjeff	andl	$0x108,%eax
46219820Sjeff	rorl	$7,%eax
47219820Sjeff	orl	%eax,%ecx
48219820Sjeff	roll	$4,%eax
49219820Sjeff	orl	%ecx,%eax
50219820Sjeff	andl	$7,%eax
51219820Sjeff/* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
52219820Sjeff	movl	8(%esp),%ecx
53219820Sjeff	xorl	4(%esp),%ecx
54219820Sjeff	sarl	$16,%ecx
55219820Sjeff	sarl	$16,%ecx
56219820Sjeff	xorl	%ecx,%eax
57219820Sjeff	andl	$1,%ecx
58219820Sjeff	addl	%ecx,%eax
59219820Sjeff/* Store the quotient and return. */
60219820Sjeff	movl	12(%esp),%ecx
61219820Sjeff	movl	%eax,(%ecx)
62219820Sjeff	ret
63219820SjeffEND(remquof)
64219820Sjeff
65219820Sjeff	.section .note.GNU-stack,"",%progbits
66219820Sjeff