n_cbrt.S revision 1.6
11.6Sagc/* $NetBSD: n_cbrt.S,v 1.6 2003/08/07 16:44:45 agc 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.4SmattALTENTRY(cbrt) 441.5SmattENTRY(d_cbrt, 0x00c0) # save %r6 & %r7 451.5Smatt movq 4(%ap),%r0 # %r0 = argument x 461.4Smatt jbr dcbrt2 471.4Smatt 481.5SmattENTRY(dcbrt_, 0x00c0) # save %r6 & %r7 491.5Smatt movq *4(%ap),%r0 # %r0 = argument x 501.1Sragge 511.5Smattdcbrt2: bicw3 $0x807f,%r0,%r2 # biased exponent of x 521.1Sragge jeql return # dcbrt(0)=0 dcbrt(res)=res. operand 531.5Smatt bicw3 $0x7fff,%r0,%ap # ap has sign(x) 541.5Smatt xorw2 %ap,%r0 # %r0 is abs(x) 551.5Smatt movl %r0,%r2 # %r2 has abs(x) 561.5Smatt rotl $16,%r2,%r2 # %r2 = |x| with bits unscrambled 571.5Smatt divl2 $3,%r2 # rough dcbrt with bias/3 581.5Smatt addl2 B,%r2 # restore bias, diminish fraction 591.5Smatt rotl $16,%r2,%r2 # %r2=|q|=|dcbrt| to 5 bits 601.5Smatt mulf3 %r2,%r2,%r3 # %r3 =qq 611.5Smatt divf2 %r0,%r3 # %r3 = qq/x 621.5Smatt mulf2 %r2,%r3 631.5Smatt addf2 C,%r3 # %r3 = s = C + qqq/x 641.5Smatt divf3 %r3,D,%r4 # %r4 = D/s 651.5Smatt addf2 E,%r4 661.5Smatt addf2 %r4,%r3 # %r3 = s + E + D/s 671.5Smatt divf3 %r3,F,%r3 # %r3 = F / (s + E + D/s) 681.5Smatt addf2 G,%r3 # %r3 = G + F / (s + E + D/s) 691.5Smatt mulf2 %r3,%r2 # %r2 = q%r3 = new q to 23 bits 701.5Smatt clrl %r3 # %r2:%r3 = q as double float 711.5Smatt muld3 %r2,%r2,%r4 # %r4:%r5 = qq exactly 721.5Smatt divd2 %r4,%r0 # %r0:%r1 = x/(q*q) rounded 731.5Smatt subd3 %r2,%r0,%r6 # %r6:%r7 = x/(q*q) - q exactly 741.5Smatt movq %r2,%r4 # %r4:%r5 = q 751.5Smatt addw2 $0x80,%r4 # %r4:%r5 = 2 * q 761.5Smatt addd2 %r0,%r4 # %r4:%r5 = 2*q + x/(q*q) 771.5Smatt divd2 %r4,%r6 # %r6:%r7 = (x/(q*q)-q)/(2*q+x/(q*q)) 781.5Smatt muld2 %r2,%r6 # %r6:%r7 = q*(x/(q*q)-q)/(2*q+x/(q*q)) 791.5Smatt addd3 %r6,%r2,%r0 # %r0:%r1 = q + %r6:%r7 801.5Smatt bisw2 %ap,%r0 # restore the sign bit 811.1Sraggereturn: 821.1Sragge ret # error less than 0.667 ulps 831.1Sragge 841.4Smatt _ALIGN_TEXT 851.1SraggeB : .long 721142941 # (86-0.03306235651)*(2^23) 861.1SraggeC : .float 0f0.5428571429 # 19/35 871.1SraggeD : .float 0f-0.7053061224 # -864/1225 881.1SraggeE : .float 0f1.414285714 # 99/70 891.1SraggeF : .float 0f1.607142857 # 45/28 901.1SraggeG : .float 0f0.3571428571 # 5/14 91