xref: /freebsd/lib/msun/amd64/s_remquo.S (revision 8997563c9ac770eed6b5f2e1e8c5df3c1ed6c52e)
13b9141eeSDavid Schultz/*-
23b9141eeSDavid Schultz * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
33b9141eeSDavid Schultz * All rights reserved.
43b9141eeSDavid Schultz *
53b9141eeSDavid Schultz * Redistribution and use in source and binary forms, with or without
63b9141eeSDavid Schultz * modification, are permitted provided that the following conditions
73b9141eeSDavid Schultz * are met:
83b9141eeSDavid Schultz * 1. Redistributions of source code must retain the above copyright
93b9141eeSDavid Schultz *    notice, this list of conditions and the following disclaimer.
103b9141eeSDavid Schultz * 2. Redistributions in binary form must reproduce the above copyright
113b9141eeSDavid Schultz *    notice, this list of conditions and the following disclaimer in the
123b9141eeSDavid Schultz *    documentation and/or other materials provided with the distribution.
133b9141eeSDavid Schultz *
143b9141eeSDavid Schultz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
153b9141eeSDavid Schultz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
163b9141eeSDavid Schultz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
173b9141eeSDavid Schultz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
183b9141eeSDavid Schultz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
193b9141eeSDavid Schultz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
203b9141eeSDavid Schultz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
213b9141eeSDavid Schultz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
223b9141eeSDavid Schultz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
233b9141eeSDavid Schultz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
243b9141eeSDavid Schultz * SUCH DAMAGE.
253b9141eeSDavid Schultz */
263b9141eeSDavid Schultz
273b9141eeSDavid Schultz/*
283b9141eeSDavid Schultz * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>.
293b9141eeSDavid Schultz */
303b9141eeSDavid Schultz
313b9141eeSDavid Schultz#include <machine/asm.h>
323b9141eeSDavid Schultz__FBSDID("$FreeBSD$");
333b9141eeSDavid Schultz
343b9141eeSDavid SchultzENTRY(remquo)
353b9141eeSDavid Schultz	movsd	%xmm0,-8(%rsp)
363b9141eeSDavid Schultz	movsd	%xmm1,-16(%rsp)
373b9141eeSDavid Schultz	fldl	-16(%rsp)
383b9141eeSDavid Schultz	fldl	-8(%rsp)
393b9141eeSDavid Schultz1:	fprem1
403b9141eeSDavid Schultz	fstsw	%ax
413b9141eeSDavid Schultz	btw	$10,%ax
423b9141eeSDavid Schultz	jc	1b
433b9141eeSDavid Schultz	fstp	%st(1)
443b9141eeSDavid Schultz/* Extract the three low-order bits of the quotient from C0,C3,C1. */
453b9141eeSDavid Schultz	shrl	$6,%eax
463b9141eeSDavid Schultz	movl	%eax,%ecx
473b9141eeSDavid Schultz	andl	$0x108,%eax
483b9141eeSDavid Schultz	rorl	$7,%eax
493b9141eeSDavid Schultz	orl	%eax,%ecx
503b9141eeSDavid Schultz	roll	$4,%eax
513b9141eeSDavid Schultz	orl	%ecx,%eax
523b9141eeSDavid Schultz	andl	$7,%eax
533b9141eeSDavid Schultz/* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
543b9141eeSDavid Schultz	movl	-12(%rsp),%ecx
553b9141eeSDavid Schultz	xorl	-4(%rsp),%ecx
563b9141eeSDavid Schultz	sarl	$16,%ecx
573b9141eeSDavid Schultz	sarl	$16,%ecx
583b9141eeSDavid Schultz	xorl	%ecx,%eax
593b9141eeSDavid Schultz	andl	$1,%ecx
603b9141eeSDavid Schultz	addl	%ecx,%eax
613b9141eeSDavid Schultz/* Store the quotient and return. */
623b9141eeSDavid Schultz	movl	%eax,(%rdi)
633b9141eeSDavid Schultz	fstpl	-8(%rsp)
643b9141eeSDavid Schultz	movsd	-8(%rsp),%xmm0
653b9141eeSDavid Schultz	ret
669235ed71SAttilio RaoEND(remquo)
67*8997563cSKonstantin Belousov
68*8997563cSKonstantin Belousov	.section .note.GNU-stack,"",%progbits
69