11.8Sriastrad/* $NetBSD: n_tan.S,v 1.8 2024/05/06 15:33:04 riastradh 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.6Sagc * 3. Neither the name of the University nor the names of its contributors 151.1Sragge * may be used to endorse or promote products derived from this software 161.1Sragge * without specific prior written permission. 171.1Sragge * 181.1Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 191.1Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 201.1Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 211.1Sragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 221.1Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 231.1Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 241.1Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 251.1Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 261.1Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271.1Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281.1Sragge * SUCH DAMAGE. 291.1Sragge * 301.1Sragge * @(#)tan.s 8.1 (Berkeley) 6/4/93 311.1Sragge */ 321.1Sragge 331.4Smatt#include <machine/asm.h> 341.4Smatt 351.3Ssimonb/* This is the implementation of Peter Tang's double precision 361.1Sragge * tangent for the VAX using Bob Corbett's argument reduction. 371.3Ssimonb * 381.1Sragge * Notes: 391.3Ssimonb * under 1,024,000 random arguments testing on [0,2*pi] 401.1Sragge * tan() observed maximum error = 2.15 ulps 411.1Sragge * 421.1Sragge * double tan(arg) 431.1Sragge * double arg; 441.1Sragge * method: true range reduction to [-pi/4,pi/4], P. Tang & B. Corbett 451.1Sragge * S. McDonald, April 4, 1985 461.1Sragge */ 471.8Sriastrad 481.8SriastradWEAK_ALIAS(tanl, _tanl) 491.8SriastradSTRONG_ALIAS(_tanl, _tan) 501.8Sriastrad 511.8SriastradWEAK_ALIAS(tan, _tan) 521.8SriastradENTRY(_tan, 0x0fc0) # save %r6-%r11 531.5Smatt movq 4(%ap),%r0 541.5Smatt bicw3 $0x807f,%r0,%r2 551.1Sragge beql 1f # if x is zero or reserved operand then return x 561.1Sragge/* 571.1Sragge * Save the PSL's IV & FU bits on the stack. 581.1Sragge */ 591.5Smatt movpsl %r2 601.5Smatt bicw3 $0xff9f,%r2,-(%sp) 611.1Sragge/* 621.1Sragge * Clear the IV & FU bits. 631.1Sragge */ 641.1Sragge bicpsw $0x0060 651.4Smatt jsb _C_LABEL(__libm_argred)+2 661.1Sragge/* 671.1Sragge * At this point, 681.5Smatt * %r0 contains the quadrant number, 0, 1, 2, or 3; 691.5Smatt * %r2/%r1 contains the reduced argument as a D-format number; 701.5Smatt * %r3 contains a F-format extension to the reduced argument; 711.1Sragge * 721.5Smatt * Save %r3/%r0 so that we can call cosine after calling sine. 731.1Sragge */ 741.5Smatt movq %r2,-(%sp) 751.5Smatt movq %r0,-(%sp) 761.1Sragge/* 771.5Smatt * Call sine. %r4 = 0 implies sine. 781.1Sragge */ 791.5Smatt movl $0,%r4 801.4Smatt jsb _C_LABEL(__libm_sincos)+2 811.1Sragge/* 821.5Smatt * Save sin(x) in %r11/%r10 . 831.1Sragge */ 841.5Smatt movd %r0,%r10 851.1Sragge/* 861.5Smatt * Call cosine. %r4 = 1 implies cosine. 871.1Sragge */ 881.5Smatt movq (%sp)+,%r0 891.5Smatt movq (%sp)+,%r2 901.5Smatt movl $1,%r4 911.4Smatt jsb _C_LABEL(__libm_sincos)+2 921.5Smatt divd3 %r0,%r10,%r0 931.5Smatt bispsw (%sp)+ 941.1Sragge1: ret 951.8SriastradEND(_tan) 961.7Smartin 971.8SriastradWEAK_ALIAS(tanf, _tanf) 981.8SriastradENTRY(_tanf, 0) 991.7Smartin cvtfd 4(%ap),-(%sp) 1001.8Sriastrad calls $2,_C_LABEL(_tan) 1011.7Smartin cvtdf %r0,%r0 1021.7Smartin ret 1031.8SriastradEND(_tanf) 104