xref: /original-bsd/lib/libm/vax/tan.s (revision cd18b70b)
1#
2# Copyright (c) 1985 Regents of the University of California.
3#
4# Use and reproduction of this software are granted  in  accordance  with
5# the terms and conditions specified in  the  Berkeley  Software  License
6# Agreement (in particular, this entails acknowledgement of the programs'
7# source, and inclusion of this notice) with the additional understanding
8# that  all  recipients  should regard themselves as participants  in  an
9# ongoing  research  project and hence should  feel  obligated  to report
10# their  experiences (good or bad) with these elementary function  codes,
11# using "sendbug 4bsd-bugs@BERKELEY", to the authors.
12#
13	.data
14	.align	2
15_sccsid:
16.asciz	"@(#)tan.s	1.1 (Berkeley) 8/21/85; 5.1 (ucb.elefunt) 11/30/87"
17
18#  This is the implementation of Peter Tang's double precision
19#  tangent for the VAX using Bob Corbett's argument reduction.
20#
21#  Notes:
22#       under 1,024,000 random arguments testing on [0,2*pi]
23#       tan() observed maximum error = 2.15 ulps
24#
25# double tan(arg)
26# double arg;
27# method: true range reduction to [-pi/4,pi/4], P. Tang  &  B. Corbett
28# S. McDonald, April 4,  1985
29#
30	.globl	_tan
31	.text
32	.align	1
33
34_tan:	.word	0xffc		# save r2-r11
35	movq	4(ap),r0
36	bicw3	$0x807f,r0,r2
37	beql	1f		# if x is zero or reserved operand then return x
38#
39# Save the PSL's IV & FU bits on the stack.
40#
41	movpsl	r2
42	bicw3	$0xff9f,r2,-(sp)
43#
44#  Clear the IV & FU bits.
45#
46	bicpsw	$0x0060
47	jsb	libm$argred
48#
49#  At this point,
50#	   r0  contains the quadrant number, 0, 1, 2, or 3;
51#	r2/r1  contains the reduced argument as a D-format number;
52#  	   r3  contains a F-format extension to the reduced argument;
53#
54#  Save  r3/r0  so that we can call cosine after calling sine.
55#
56	movq	r2,-(sp)
57	movq	r0,-(sp)
58#
59#  Call sine.  r4 = 0  implies sine.
60#
61	movl	$0,r4
62	jsb	libm$sincos
63#
64#  Save  sin(x)  in  r11/r10 .
65#
66	movd	r0,r10
67#
68#  Call cosine.  r4 = 1  implies cosine.
69#
70	movq	(sp)+,r0
71	movq	(sp)+,r2
72	movl	$1,r4
73	jsb	libm$sincos
74	divd3	r0,r10,r0
75	bispsw	(sp)+
761:	ret
77