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