124568Szliu# 224568Szliu# Copyright (c) 1985 Regents of the University of California. 324568Szliu# 424568Szliu# Use and reproduction of this software are granted in accordance with 524568Szliu# the terms and conditions specified in the Berkeley Software License 624568Szliu# Agreement (in particular, this entails acknowledgement of the programs' 724568Szliu# source, and inclusion of this notice) with the additional understanding 824568Szliu# that all recipients should regard themselves as participants in an 924568Szliu# ongoing research project and hence should feel obligated to report 1024568Szliu# their experiences (good or bad) with these elementary function codes, 1124568Szliu# using "sendbug 4bsd-bugs@BERKELEY", to the authors. 1224568Szliu# 13*24729Selefunt .data 14*24729Selefunt .align 2 15*24729Selefunt_sccsid: 16*24729Selefunt.asciz "@(#)cbrt.s 1.1 (Berkeley) 5/23/85; 1.3 (ucb.elefunt) 09/12/85" 1724568Szliu 1824568Szliu# double cbrt(double arg) 1924568Szliu# W. Kahan, 10/13/80. revised 1/13/84 for keeping sign symmetry 2024568Szliu# error check by E LeBlanc, 8/18/82 2124568Szliu# Revised and tested by K.C. Ng, 5/2/85 2224568Szliu# Max error less than 0.667 ulps (unit in the last places) 2324568Szliu .globl _cbrt 2424568Szliu .globl _d_cbrt 2524568Szliu .globl _dcbrt_ 2624568Szliu .text 2724568Szliu .align 1 2824568Szliu 2924568Szliu_cbrt: 3024568Szliu_d_cbrt: 3124568Szliu .word 0x00fc # save r2 to r7 3224568Szliu movq 4(ap),r0 # r0 = argument x 3324568Szliu jmp dcbrt2 3424568Szliu_dcbrt_: 3524568Szliu .word 0x00fc # save r2 to r7 3624568Szliu movq *4(ap),r0 # r0 = argument x 3724568Szliu 3824568Szliudcbrt2: bicw3 $0x807f,r0,r2 # biased exponent of x 3924568Szliu jeql return # dcbrt(0)=0 dcbrt(res)=res. operand 4024568Szliu bicw3 $0x7fff,r0,ap # ap has sign(x) 4124568Szliu xorw2 ap,r0 # r0 is abs(x) 4224568Szliu movl r0,r2 # r2 has abs(x) 4324568Szliu rotl $16,r2,r2 # r2 = |x| with bits unscrambled 4424568Szliu divl2 $3,r2 # rough dcbrt with bias/3 4524568Szliu addl2 B,r2 # restore bias, diminish fraction 4624568Szliu rotl $16,r2,r2 # r2=|q|=|dcbrt| to 5 bits 4724568Szliu mulf3 r2,r2,r3 # r3 =qq 4824568Szliu divf2 r0,r3 # r3 = qq/x 4924568Szliu mulf2 r2,r3 5024568Szliu addf2 C,r3 # r3 = s = C + qqq/x 5124568Szliu divf3 r3,D,r4 # r4 = D/s 5224568Szliu addf2 E,r4 5324568Szliu addf2 r4,r3 # r3 = s + E + D/s 5424568Szliu divf3 r3,F,r3 # r3 = F / (s + E + D/s) 5524568Szliu addf2 G,r3 # r3 = G + F / (s + E + D/s) 5624568Szliu mulf2 r3,r2 # r2 = qr3 = new q to 23 bits 5724568Szliu clrl r3 # r2:r3 = q as double float 5824568Szliu muld3 r2,r2,r4 # r4:r5 = qq exactly 5924568Szliu divd2 r4,r0 # r0:r1 = x/(q*q) rounded 6024568Szliu subd3 r2,r0,r6 # r6:r7 = x/(q*q) - q exactly 6124568Szliu movq r2,r4 # r4:r5 = q 6224568Szliu addw2 $0x80,r4 # r4:r5 = 2 * q 6324568Szliu addd2 r0,r4 # r4:r5 = 2*q + x/(q*q) 6424568Szliu divd2 r4,r6 # r6:r7 = (x/(q*q)-q)/(2*q+x/(q*q)) 6524568Szliu muld2 r2,r6 # r6:r7 = q*(x/(q*q)-q)/(2*q+x/(q*q)) 6624568Szliu addd3 r6,r2,r0 # r0:r1 = q + r6:r7 6724568Szliu bisw2 ap,r0 # restore the sign bit 6824568Szliureturn: 6924568Szliu ret # error less than 0.667 ulps 7024568Szliu 7124568Szliu.data 7224568Szliu.align 2 7324568SzliuB : .long 721142941 # (86-0.03306235651)*(2^23) 7424568SzliuC : .float 0f0.5428571429 # 19/35 7524568SzliuD : .float 0f-0.7053061224 # -864/1225 7624568SzliuE : .float 0f1.414285714 # 99/70 7724568SzliuF : .float 0f1.607142857 # 45/28 7824568SzliuG : .float 0f0.3571428571 # 5/14 7924568Szliu 80