n_tan.S revision 1.5
11.5Smatt/*	$NetBSD: n_tan.S,v 1.5 2002/02/24 01:06:21 matt Exp $	*/
21.1Sragge/*
31.1Sragge * Copyright (c) 1985, 1993
41.1Sragge *	The Regents of the University of California.  All rights reserved.
51.1Sragge *
61.1Sragge * Redistribution and use in source and binary forms, with or without
71.1Sragge * modification, are permitted provided that the following conditions
81.1Sragge * are met:
91.1Sragge * 1. Redistributions of source code must retain the above copyright
101.1Sragge *    notice, this list of conditions and the following disclaimer.
111.1Sragge * 2. Redistributions in binary form must reproduce the above copyright
121.1Sragge *    notice, this list of conditions and the following disclaimer in the
131.1Sragge *    documentation and/or other materials provided with the distribution.
141.1Sragge * 3. All advertising materials mentioning features or use of this software
151.1Sragge *    must display the following acknowledgement:
161.1Sragge *	This product includes software developed by the University of
171.1Sragge *	California, Berkeley and its contributors.
181.1Sragge * 4. Neither the name of the University nor the names of its contributors
191.1Sragge *    may be used to endorse or promote products derived from this software
201.1Sragge *    without specific prior written permission.
211.1Sragge *
221.1Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Sragge * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Sragge * SUCH DAMAGE.
331.1Sragge *
341.1Sragge *	@(#)tan.s	8.1 (Berkeley) 6/4/93
351.1Sragge */
361.1Sragge
371.4Smatt#include <machine/asm.h>
381.4Smatt
391.3Ssimonb/*  This is the implementation of Peter Tang's double precision
401.1Sragge *  tangent for the VAX using Bob Corbett's argument reduction.
411.3Ssimonb *
421.1Sragge *  Notes:
431.3Ssimonb *       under 1,024,000 random arguments testing on [0,2*pi]
441.1Sragge *       tan() observed maximum error = 2.15 ulps
451.1Sragge *
461.1Sragge * double tan(arg)
471.1Sragge * double arg;
481.1Sragge * method: true range reduction to [-pi/4,pi/4], P. Tang  &  B. Corbett
491.1Sragge * S. McDonald, April 4,  1985
501.1Sragge */
511.5SmattENTRY(tan, 0x0fc0)		# save %r6-%r11
521.5Smatt	movq	4(%ap),%r0
531.5Smatt	bicw3	$0x807f,%r0,%r2
541.1Sragge	beql	1f		# if x is zero or reserved operand then return x
551.1Sragge/*
561.1Sragge * Save the PSL's IV & FU bits on the stack.
571.1Sragge */
581.5Smatt	movpsl	%r2
591.5Smatt	bicw3	$0xff9f,%r2,-(%sp)
601.1Sragge/*
611.1Sragge *  Clear the IV & FU bits.
621.1Sragge */
631.1Sragge	bicpsw	$0x0060
641.4Smatt	jsb	_C_LABEL(__libm_argred)+2
651.1Sragge/*
661.1Sragge *  At this point,
671.5Smatt *	   %r0  contains the quadrant number, 0, 1, 2, or 3;
681.5Smatt *	%r2/%r1  contains the reduced argument as a D-format number;
691.5Smatt *  	   %r3  contains a F-format extension to the reduced argument;
701.1Sragge *
711.5Smatt *  Save  %r3/%r0  so that we can call cosine after calling sine.
721.1Sragge */
731.5Smatt	movq	%r2,-(%sp)
741.5Smatt	movq	%r0,-(%sp)
751.1Sragge/*
761.5Smatt *  Call sine.  %r4 = 0  implies sine.
771.1Sragge */
781.5Smatt	movl	$0,%r4
791.4Smatt	jsb	_C_LABEL(__libm_sincos)+2
801.1Sragge/*
811.5Smatt *  Save  sin(x)  in  %r11/%r10 .
821.1Sragge */
831.5Smatt	movd	%r0,%r10
841.1Sragge/*
851.5Smatt *  Call cosine.  %r4 = 1  implies cosine.
861.1Sragge */
871.5Smatt	movq	(%sp)+,%r0
881.5Smatt	movq	(%sp)+,%r2
891.5Smatt	movl	$1,%r4
901.4Smatt	jsb	_C_LABEL(__libm_sincos)+2
911.5Smatt	divd3	%r0,%r10,%r0
921.5Smatt	bispsw	(%sp)+
931.1Sragge1:	ret
94