s_remquof.S revision 217108
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: head/lib/msun/amd64/s_remquof.S 217108 2011-01-07 16:13:12Z kib $"); 33144091Sdas 34144091SdasENTRY(remquof) 35144091Sdas movss %xmm0,-4(%rsp) 36144091Sdas movss %xmm1,-8(%rsp) 37144091Sdas flds -8(%rsp) 38144091Sdas flds -4(%rsp) 39144091Sdas1: fprem1 40144091Sdas fstsw %ax 41144091Sdas btw $10,%ax 42144091Sdas jc 1b 43144091Sdas fstp %st(1) 44144091Sdas/* Extract the three low-order bits of the quotient from C0,C3,C1. */ 45144091Sdas shrl $6,%eax 46144091Sdas movl %eax,%ecx 47144091Sdas andl $0x108,%eax 48144091Sdas rorl $7,%eax 49144091Sdas orl %eax,%ecx 50144091Sdas roll $4,%eax 51144091Sdas orl %ecx,%eax 52144091Sdas andl $7,%eax 53144091Sdas/* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ 54144091Sdas movl -8(%rsp),%ecx 55144091Sdas xorl -4(%rsp),%ecx 56144091Sdas sarl $16,%ecx 57144091Sdas sarl $16,%ecx 58144091Sdas xorl %ecx,%eax 59144091Sdas andl $1,%ecx 60144091Sdas addl %ecx,%eax 61144091Sdas/* Store the quotient and return. */ 62144091Sdas movl %eax,(%rdi) 63144091Sdas fstps -4(%rsp) 64144091Sdas movss -4(%rsp),%xmm0 65144091Sdas ret 66192760SattilioEND(remquof) 67217108Skib 68217108Skib .section .note.GNU-stack,"",%progbits 69