11.9Sriastrad/* $NetBSD: n_cbrt.S,v 1.9 2024/05/07 15:15:31 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 * @(#)cbrt.s 8.1 (Berkeley) 6/4/93 311.1Sragge */ 321.1Sragge 331.4Smatt#include <machine/asm.h> 341.4Smatt 351.1Sragge/* 361.1Sragge * double cbrt(double arg) 371.1Sragge * W. Kahan, 10/13/80. revised 1/13/84 for keeping sign symmetry 381.1Sragge * error check by E LeBlanc, 8/18/82 391.3Ssimonb * Revised and tested by K.C. Ng, 5/2/85 401.1Sragge * Max error less than 0.667 ulps (unit in the last places) 411.1Sragge */ 421.1Sragge 431.7SmartinENTRY(cbrtf, 0) 441.7Smartin cvtfd 4(%ap),-(%sp) 451.7Smartin calls $2,_C_LABEL(cbrt) 461.7Smartin cvtdf %r0,%r0 471.7Smartin ret 481.8SriastradEND(cbrtf) 491.7Smartin 501.7Smartin#ifdef WEAK_ALIAS 511.7SmartinWEAK_ALIAS(cbrtl, cbrt) 521.7Smartin#endif 531.7Smartin 541.9SriastradSTRONG_ALIAS(cbrt, d_cbrt) 551.5SmattENTRY(d_cbrt, 0x00c0) # save %r6 & %r7 561.5Smatt movq 4(%ap),%r0 # %r0 = argument x 571.4Smatt jbr dcbrt2 581.8SriastradEND(d_cbrt) 591.4Smatt 601.5SmattENTRY(dcbrt_, 0x00c0) # save %r6 & %r7 611.5Smatt movq *4(%ap),%r0 # %r0 = argument x 621.1Sragge 631.5Smattdcbrt2: bicw3 $0x807f,%r0,%r2 # biased exponent of x 641.1Sragge jeql return # dcbrt(0)=0 dcbrt(res)=res. operand 651.5Smatt bicw3 $0x7fff,%r0,%ap # ap has sign(x) 661.5Smatt xorw2 %ap,%r0 # %r0 is abs(x) 671.5Smatt movl %r0,%r2 # %r2 has abs(x) 681.5Smatt rotl $16,%r2,%r2 # %r2 = |x| with bits unscrambled 691.5Smatt divl2 $3,%r2 # rough dcbrt with bias/3 701.5Smatt addl2 B,%r2 # restore bias, diminish fraction 711.5Smatt rotl $16,%r2,%r2 # %r2=|q|=|dcbrt| to 5 bits 721.5Smatt mulf3 %r2,%r2,%r3 # %r3 =qq 731.5Smatt divf2 %r0,%r3 # %r3 = qq/x 741.5Smatt mulf2 %r2,%r3 751.5Smatt addf2 C,%r3 # %r3 = s = C + qqq/x 761.5Smatt divf3 %r3,D,%r4 # %r4 = D/s 771.5Smatt addf2 E,%r4 781.5Smatt addf2 %r4,%r3 # %r3 = s + E + D/s 791.5Smatt divf3 %r3,F,%r3 # %r3 = F / (s + E + D/s) 801.5Smatt addf2 G,%r3 # %r3 = G + F / (s + E + D/s) 811.5Smatt mulf2 %r3,%r2 # %r2 = q%r3 = new q to 23 bits 821.5Smatt clrl %r3 # %r2:%r3 = q as double float 831.5Smatt muld3 %r2,%r2,%r4 # %r4:%r5 = qq exactly 841.5Smatt divd2 %r4,%r0 # %r0:%r1 = x/(q*q) rounded 851.5Smatt subd3 %r2,%r0,%r6 # %r6:%r7 = x/(q*q) - q exactly 861.5Smatt movq %r2,%r4 # %r4:%r5 = q 871.5Smatt addw2 $0x80,%r4 # %r4:%r5 = 2 * q 881.5Smatt addd2 %r0,%r4 # %r4:%r5 = 2*q + x/(q*q) 891.5Smatt divd2 %r4,%r6 # %r6:%r7 = (x/(q*q)-q)/(2*q+x/(q*q)) 901.5Smatt muld2 %r2,%r6 # %r6:%r7 = q*(x/(q*q)-q)/(2*q+x/(q*q)) 911.5Smatt addd3 %r6,%r2,%r0 # %r0:%r1 = q + %r6:%r7 921.5Smatt bisw2 %ap,%r0 # restore the sign bit 931.1Sraggereturn: 941.1Sragge ret # error less than 0.667 ulps 951.8SriastradEND(dcbrt_) 961.1Sragge 971.4Smatt _ALIGN_TEXT 981.1SraggeB : .long 721142941 # (86-0.03306235651)*(2^23) 991.1SraggeC : .float 0f0.5428571429 # 19/35 1001.1SraggeD : .float 0f-0.7053061224 # -864/1225 1011.1SraggeE : .float 0f1.414285714 # 99/70 1021.1SraggeF : .float 0f1.607142857 # 45/28 1031.1SraggeG : .float 0f0.3571428571 # 5/14 104