1/*- 2 * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>. 29 */ 30 31#include <amd64/bsd_asm.h> 32//__FBSDID("$FreeBSD: src/lib/msun/amd64/s_remquol.S,v 1.2 2011/01/07 16:13:12 kib Exp $"); 33 34ENTRY(remquol) 35#ifndef _WIN64 36 fldt 24(%rsp) 37 fldt 8(%rsp) 38#else 39 fldt (%r8) 40 fldt (%rdx) 41 mov %rcx,%r8 42#endif 431: fprem1 44 fstsw %ax 45 btw $10,%ax 46 jc 1b 47 fstp %st(1) 48/* Extract the three low-order bits of the quotient from C0,C3,C1. */ 49 shrl $6,%eax 50 movl %eax,%ecx 51 andl $0x108,%eax 52 rorl $7,%eax 53 orl %eax,%ecx 54 roll $4,%eax 55 orl %ecx,%eax 56 andl $7,%eax 57/* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ 58 movl 32(%rsp),%ecx 59 xorl 16(%rsp),%ecx 60 movsx %cx,%ecx 61 sarl $16,%ecx 62 sarl $16,%ecx 63 xorl %ecx,%eax 64 andl $1,%ecx 65 addl %ecx,%eax 66/* Store the quotient and return. */ 67#ifndef _WIN64 68 movl %eax,(%rdi) 69#else 70 movl %eax,(%r9) 71 mov %r8,%rax 72 movq $0x0,0x8(%r8) 73 fstpt (%r8) 74#endif 75 ret 76 77 78/* Enable stack protection */ 79#if defined(__linux__) && defined(__ELF__) 80.section .note.GNU-stack,"",%progbits 81#endif 82