n_cbrt.S revision 1.2
11.2Smatt/* $NetBSD: n_cbrt.S,v 1.2 1998/10/31 02:06:02 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 * @(#)cbrt.s 8.1 (Berkeley) 6/4/93 351.1Sragge */ 361.1Sragge 371.1Sragge/* 381.1Sragge * double cbrt(double arg) 391.1Sragge * W. Kahan, 10/13/80. revised 1/13/84 for keeping sign symmetry 401.1Sragge * error check by E LeBlanc, 8/18/82 411.1Sragge * Revised and tested by K.C. Ng, 5/2/85 421.1Sragge * Max error less than 0.667 ulps (unit in the last places) 431.1Sragge */ 441.1Sragge 451.1Sragge .globl _cbrt 461.2Smatt .type _cbrt,@function 471.1Sragge .globl _d_cbrt 481.2Smatt .type _d_cbrt,@function 491.2Smatt .globl _dcbrt_ 501.2Smatt .type _dcbrt_,@function 511.1Sragge .text 521.1Sragge .align 1 531.1Sragge 541.1Sragge_cbrt: 551.1Sragge_d_cbrt: 561.1Sragge .word 0x00fc # save r2 to r7 571.1Sragge movq 4(ap),r0 # r0 = argument x 581.1Sragge jmp dcbrt2 591.1Sragge_dcbrt_: 601.1Sragge .word 0x00fc # save r2 to r7 611.1Sragge movq *4(ap),r0 # r0 = argument x 621.1Sragge 631.1Sraggedcbrt2: bicw3 $0x807f,r0,r2 # biased exponent of x 641.1Sragge jeql return # dcbrt(0)=0 dcbrt(res)=res. operand 651.1Sragge bicw3 $0x7fff,r0,ap # ap has sign(x) 661.1Sragge xorw2 ap,r0 # r0 is abs(x) 671.1Sragge movl r0,r2 # r2 has abs(x) 681.1Sragge rotl $16,r2,r2 # r2 = |x| with bits unscrambled 691.1Sragge divl2 $3,r2 # rough dcbrt with bias/3 701.1Sragge addl2 B,r2 # restore bias, diminish fraction 711.1Sragge rotl $16,r2,r2 # r2=|q|=|dcbrt| to 5 bits 721.1Sragge mulf3 r2,r2,r3 # r3 =qq 731.1Sragge divf2 r0,r3 # r3 = qq/x 741.1Sragge mulf2 r2,r3 751.1Sragge addf2 C,r3 # r3 = s = C + qqq/x 761.1Sragge divf3 r3,D,r4 # r4 = D/s 771.1Sragge addf2 E,r4 781.1Sragge addf2 r4,r3 # r3 = s + E + D/s 791.1Sragge divf3 r3,F,r3 # r3 = F / (s + E + D/s) 801.1Sragge addf2 G,r3 # r3 = G + F / (s + E + D/s) 811.1Sragge mulf2 r3,r2 # r2 = qr3 = new q to 23 bits 821.1Sragge clrl r3 # r2:r3 = q as double float 831.1Sragge muld3 r2,r2,r4 # r4:r5 = qq exactly 841.1Sragge divd2 r4,r0 # r0:r1 = x/(q*q) rounded 851.1Sragge subd3 r2,r0,r6 # r6:r7 = x/(q*q) - q exactly 861.1Sragge movq r2,r4 # r4:r5 = q 871.1Sragge addw2 $0x80,r4 # r4:r5 = 2 * q 881.1Sragge addd2 r0,r4 # r4:r5 = 2*q + x/(q*q) 891.1Sragge divd2 r4,r6 # r6:r7 = (x/(q*q)-q)/(2*q+x/(q*q)) 901.1Sragge muld2 r2,r6 # r6:r7 = q*(x/(q*q)-q)/(2*q+x/(q*q)) 911.1Sragge addd3 r6,r2,r0 # r0:r1 = q + r6:r7 921.1Sragge bisw2 ap,r0 # restore the sign bit 931.1Sraggereturn: 941.1Sragge ret # error less than 0.667 ulps 951.1Sragge 961.1Sragge.data 971.1Sragge.align 2 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 1041.1Sragge 105