xref: /titanic_52/usr/src/lib/libm/i386/src/remainder.s (revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af)
1*25c28e83SPiotr Jasiukajtis/*
2*25c28e83SPiotr Jasiukajtis * CDDL HEADER START
3*25c28e83SPiotr Jasiukajtis *
4*25c28e83SPiotr Jasiukajtis * The contents of this file are subject to the terms of the
5*25c28e83SPiotr Jasiukajtis * Common Development and Distribution License (the "License").
6*25c28e83SPiotr Jasiukajtis * You may not use this file except in compliance with the License.
7*25c28e83SPiotr Jasiukajtis *
8*25c28e83SPiotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25c28e83SPiotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
10*25c28e83SPiotr Jasiukajtis * See the License for the specific language governing permissions
11*25c28e83SPiotr Jasiukajtis * and limitations under the License.
12*25c28e83SPiotr Jasiukajtis *
13*25c28e83SPiotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
14*25c28e83SPiotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25c28e83SPiotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
16*25c28e83SPiotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
17*25c28e83SPiotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
18*25c28e83SPiotr Jasiukajtis *
19*25c28e83SPiotr Jasiukajtis * CDDL HEADER END
20*25c28e83SPiotr Jasiukajtis */
21*25c28e83SPiotr Jasiukajtis/*
22*25c28e83SPiotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
23*25c28e83SPiotr Jasiukajtis */
24*25c28e83SPiotr Jasiukajtis/*
25*25c28e83SPiotr Jasiukajtis * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26*25c28e83SPiotr Jasiukajtis * Use is subject to license terms.
27*25c28e83SPiotr Jasiukajtis */
28*25c28e83SPiotr Jasiukajtis
29*25c28e83SPiotr Jasiukajtis	.file "remainder.s"
30*25c28e83SPiotr Jasiukajtis
31*25c28e83SPiotr Jasiukajtis#include "libm.h"
32*25c28e83SPiotr JasiukajtisLIBM_ANSI_PRAGMA_WEAK(remainder,function)
33*25c28e83SPiotr Jasiukajtis#include "libm_protos.h"
34*25c28e83SPiotr Jasiukajtis
35*25c28e83SPiotr Jasiukajtis	ENTRY(remainder)
36*25c28e83SPiotr Jasiukajtis	pushl	%ebp
37*25c28e83SPiotr Jasiukajtis	movl	%esp,%ebp
38*25c28e83SPiotr Jasiukajtis	fldl	16(%esp)		/ load arg y
39*25c28e83SPiotr Jasiukajtis	fldl	8(%esp)			/ load arg x
40*25c28e83SPiotr Jasiukajtis	fucom
41*25c28e83SPiotr Jasiukajtis	fnstsw	%ax
42*25c28e83SPiotr Jasiukajtis	sahf
43*25c28e83SPiotr Jasiukajtis	jp	.rem_loop		/ if x or y is NaN, use fprem1
44*25c28e83SPiotr Jasiukajtis
45*25c28e83SPiotr Jasiukajtis	movl	20(%esp),%eax		/ eax <-- hi_32(y)
46*25c28e83SPiotr Jasiukajtis	andl	$0x7fffffff,%eax	/ eax <-- hi_32(|y|)
47*25c28e83SPiotr Jasiukajtis	orl	16(%esp),%eax		/ eax <-- lo_32(y)|hi_32(|y|)
48*25c28e83SPiotr Jasiukajtis	je	.yzero_or_xinf
49*25c28e83SPiotr Jasiukajtis
50*25c28e83SPiotr Jasiukajtis	movl	12(%esp),%eax		/ eax <-- hi_32(x)
51*25c28e83SPiotr Jasiukajtis	andl	$0x7fffffff,%eax	/ eax <-- hi_32(|x|)
52*25c28e83SPiotr Jasiukajtis	cmpl	$0x7ff00000,%eax
53*25c28e83SPiotr Jasiukajtis	jne	.rem_loop
54*25c28e83SPiotr Jasiukajtis	cmpl	$0,8(%esp)
55*25c28e83SPiotr Jasiukajtis	je	.yzero_or_xinf
56*25c28e83SPiotr Jasiukajtis
57*25c28e83SPiotr Jasiukajtis.rem_loop:
58*25c28e83SPiotr Jasiukajtis	fprem1				/ partial remainder
59*25c28e83SPiotr Jasiukajtis	fstsw	%ax			/ store status word
60*25c28e83SPiotr Jasiukajtis	andw	$0x400,%ax		/ check for incomplete reduction
61*25c28e83SPiotr Jasiukajtis	jne	.rem_loop		/ while incomplete, do fprem1 again
62*25c28e83SPiotr Jasiukajtis	fstp	%st(1)
63*25c28e83SPiotr Jasiukajtis	leave
64*25c28e83SPiotr Jasiukajtis	ret
65*25c28e83SPiotr Jasiukajtis
66*25c28e83SPiotr Jasiukajtis.yzero_or_xinf:
67*25c28e83SPiotr Jasiukajtis	PIC_SETUP(1)
68*25c28e83SPiotr Jasiukajtis	fstp	%st(0)			/ x
69*25c28e83SPiotr Jasiukajtis	fstp	%st(0)			/ empty NPX stack
70*25c28e83SPiotr Jasiukajtis	pushl	$28			/ case 28 in _SVID_libm_err
71*25c28e83SPiotr Jasiukajtis	pushl	20(%ebp)		/ pass y
72*25c28e83SPiotr Jasiukajtis	pushl	16(%ebp)
73*25c28e83SPiotr Jasiukajtis	pushl	12(%ebp)		/ pass x
74*25c28e83SPiotr Jasiukajtis	pushl	8(%ebp)
75*25c28e83SPiotr Jasiukajtis	call	PIC_F(_SVID_libm_err)
76*25c28e83SPiotr Jasiukajtis	addl	$20,%esp
77*25c28e83SPiotr Jasiukajtis	PIC_WRAPUP
78*25c28e83SPiotr Jasiukajtis	leave
79*25c28e83SPiotr Jasiukajtis	ret
80*25c28e83SPiotr Jasiukajtis	.align	4
81*25c28e83SPiotr Jasiukajtis	SET_SIZE(remainder)
82