s_remquof.S revision 144091
1198892Srdivacky/*-
2198892Srdivacky * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
3198892Srdivacky * All rights reserved.
4198892Srdivacky *
5198892Srdivacky * Redistribution and use in source and binary forms, with or without
6198892Srdivacky * modification, are permitted provided that the following conditions
7198892Srdivacky * are met:
8198892Srdivacky * 1. Redistributions of source code must retain the above copyright
9198892Srdivacky *    notice, this list of conditions and the following disclaimer.
10198892Srdivacky * 2. Redistributions in binary form must reproduce the above copyright
11249423Sdim *    notice, this list of conditions and the following disclaimer in the
12198892Srdivacky *    documentation and/or other materials provided with the distribution.
13198892Srdivacky *
14198892Srdivacky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15239462Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16249423Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17249423Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18239462Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19199481Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20249423Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21249423Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22249423Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23249423Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24249423Sdim * SUCH DAMAGE.
25249423Sdim */
26239462Sdim
27239462Sdim/*
28239462Sdim * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>.
29243830Sdim */
30239462Sdim
31198892Srdivacky#include <machine/asm.h>
32198892Srdivacky__FBSDID("$FreeBSD: head/lib/msun/amd64/s_remquof.S 144091 2005-03-25 04:40:44Z das $");
33239462Sdim
34263508SdimENTRY(remquof)
35263508Sdim	movss	%xmm0,-4(%rsp)
36263508Sdim	movss	%xmm1,-8(%rsp)
37263508Sdim	flds	-8(%rsp)
38263508Sdim	flds	-4(%rsp)
39239462Sdim1:	fprem1
40263508Sdim	fstsw	%ax
41239462Sdim	btw	$10,%ax
42198892Srdivacky	jc	1b
43239462Sdim	fstp	%st(1)
44243830Sdim/* Extract the three low-order bits of the quotient from C0,C3,C1. */
45239462Sdim	shrl	$6,%eax
46239462Sdim	movl	%eax,%ecx
47239462Sdim	andl	$0x108,%eax
48239462Sdim	rorl	$7,%eax
49239462Sdim	orl	%eax,%ecx
50239462Sdim	roll	$4,%eax
51239462Sdim	orl	%ecx,%eax
52239462Sdim	andl	$7,%eax
53239462Sdim/* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
54243830Sdim	movl	-8(%rsp),%ecx
55243830Sdim	xorl	-4(%rsp),%ecx
56263508Sdim	sarl	$16,%ecx
57243830Sdim	sarl	$16,%ecx
58263508Sdim	xorl	%ecx,%eax
59243830Sdim	andl	$1,%ecx
60263508Sdim	addl	%ecx,%eax
61243830Sdim/* Store the quotient and return. */
62263508Sdim	movl	%eax,(%rdi)
63243830Sdim	fstps	-4(%rsp)
64243830Sdim	movss	-4(%rsp),%xmm0
65243830Sdim	ret
66243830Sdim