n_sincos.S revision 1.6
11.6Smatt/*	$NetBSD: n_sincos.S,v 1.6 2002/07/14 19:55:24 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 *	@(#)sincos.s	8.1 (Berkeley) 6/4/93
351.1Sragge */
361.1Sragge
371.1Sragge/*
381.3Ssimonb *  This is the implementation of Peter Tang's double precision
391.1Sragge *  sine and cosine for the VAX using Bob Corbett's argument reduction.
401.3Ssimonb *
411.1Sragge *  Notes:
421.3Ssimonb *       under 1,024,000 random arguments testing on [0,2*pi]
431.1Sragge *       sin() observed maximum error = 0.814 ulps
441.1Sragge *       cos() observed maximum error = 0.792 ulps
451.1Sragge *
461.1Sragge * double sin(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.2Smatt#include <machine/asm.h>
521.4Smatt
531.6SmattENTRY(sinf, 0)
541.6Smatt	cvtfd	4(%ap),-(sp)
551.6Smatt	calls	$2,sin
561.6Smatt	cvtdf	r0,r0
571.6Smatt	ret
581.6Smatt
591.4SmattENTRY(sin, 0xfc0)
601.5Smatt	movq	4(%ap),%r0
611.5Smatt	bicw3	$0x807f,%r0,%r2
621.1Sragge	beql	1f		# if x is zero or reserved operand then return x
631.1Sragge/*
641.1Sragge * Save the PSL's IV & FU bits on the stack.
651.1Sragge */
661.5Smatt	movpsl	%r2
671.5Smatt	bicw3	$0xff9f,%r2,-(%sp)
681.1Sragge/*
691.1Sragge * Clear the IV & FU bits.
701.1Sragge */
711.1Sragge	bicpsw	$0x0060
721.1Sragge/*
731.5Smatt *  Entered by  sine    ; save  0  in  %r4 .
741.1Sragge */
751.4Smatt	jsb	_C_LABEL(__libm_argred)+2
761.5Smatt	movl	$0,%r4
771.4Smatt	jsb	_C_LABEL(__libm_sincos)+2
781.5Smatt	bispsw	(%sp)+
791.1Sragge1:	ret
801.1Sragge
811.1Sragge/*
821.1Sragge * double cos(arg)
831.1Sragge * double arg;
841.1Sragge * method: true range reduction to [-pi/4,pi/4], P. Tang  &  B. Corbett
851.1Sragge * S. McDonald, April 4,  1985
861.1Sragge */
871.6Smatt
881.6SmattENTRY(cosf, 0)
891.6Smatt	cvtfd	4(%ap),-(sp)
901.6Smatt	calls	$2,cos
911.6Smatt	cvtdf	r0,r0
921.6Smatt	ret
931.4Smatt
941.4SmattENTRY(cos, 0x0fc0)
951.5Smatt	movq	4(%ap),%r0
961.5Smatt	bicw3	$0x7f,%r0,%r2
971.5Smatt	cmpw	$0x8000,%r2
981.1Sragge	beql	1f		# if x is reserved operand then return x
991.1Sragge/*
1001.1Sragge * Save the PSL's IV & FU bits on the stack.
1011.1Sragge */
1021.5Smatt	movpsl	%r2
1031.5Smatt	bicw3	$0xff9f,%r2,-(%sp)
1041.1Sragge/*
1051.1Sragge * Clear the IV & FU bits.
1061.1Sragge */
1071.1Sragge	bicpsw	$0x0060
1081.1Sragge/*
1091.5Smatt *  Entered by  cosine  ; save  1  in  %r4 .
1101.1Sragge */
1111.4Smatt	jsb	_C_LABEL(__libm_argred)+2
1121.5Smatt	movl	$1,%r4
1131.4Smatt	jsb	_C_LABEL(__libm_sincos)+2
1141.5Smatt	bispsw	(%sp)+
1151.1Sragge1:	ret
116