1*61318Sbostic# Copyright (c) 1985, 1993 2*61318Sbostic# The Regents of the University of California. All rights reserved. 324568Szliu# 445308Sbostic# %sccs.include.redist.sh% 534125Sbostic# 6*61318Sbostic# @(#)cbrt.s 8.1 (Berkeley) 06/04/93 734125Sbostic# 824729Selefunt .data 924729Selefunt .align 2 1024729Selefunt_sccsid: 11*61318Sbostic.asciz "@(#)cbrt.s 1.1 (Berkeley) 5/23/85; 8.1 (ucb.elefunt) 06/04/93" 1224568Szliu 1324568Szliu# double cbrt(double arg) 1424568Szliu# W. Kahan, 10/13/80. revised 1/13/84 for keeping sign symmetry 1524568Szliu# error check by E LeBlanc, 8/18/82 1624568Szliu# Revised and tested by K.C. Ng, 5/2/85 1724568Szliu# Max error less than 0.667 ulps (unit in the last places) 1824568Szliu .globl _cbrt 1924568Szliu .globl _d_cbrt 2024568Szliu .globl _dcbrt_ 2124568Szliu .text 2224568Szliu .align 1 2324568Szliu 2424568Szliu_cbrt: 2524568Szliu_d_cbrt: 2624568Szliu .word 0x00fc # save r2 to r7 2724568Szliu movq 4(ap),r0 # r0 = argument x 2824568Szliu jmp dcbrt2 2924568Szliu_dcbrt_: 3024568Szliu .word 0x00fc # save r2 to r7 3124568Szliu movq *4(ap),r0 # r0 = argument x 3224568Szliu 3324568Szliudcbrt2: bicw3 $0x807f,r0,r2 # biased exponent of x 3424568Szliu jeql return # dcbrt(0)=0 dcbrt(res)=res. operand 3524568Szliu bicw3 $0x7fff,r0,ap # ap has sign(x) 3624568Szliu xorw2 ap,r0 # r0 is abs(x) 3724568Szliu movl r0,r2 # r2 has abs(x) 3824568Szliu rotl $16,r2,r2 # r2 = |x| with bits unscrambled 3924568Szliu divl2 $3,r2 # rough dcbrt with bias/3 4024568Szliu addl2 B,r2 # restore bias, diminish fraction 4124568Szliu rotl $16,r2,r2 # r2=|q|=|dcbrt| to 5 bits 4224568Szliu mulf3 r2,r2,r3 # r3 =qq 4324568Szliu divf2 r0,r3 # r3 = qq/x 4424568Szliu mulf2 r2,r3 4524568Szliu addf2 C,r3 # r3 = s = C + qqq/x 4624568Szliu divf3 r3,D,r4 # r4 = D/s 4724568Szliu addf2 E,r4 4824568Szliu addf2 r4,r3 # r3 = s + E + D/s 4924568Szliu divf3 r3,F,r3 # r3 = F / (s + E + D/s) 5024568Szliu addf2 G,r3 # r3 = G + F / (s + E + D/s) 5124568Szliu mulf2 r3,r2 # r2 = qr3 = new q to 23 bits 5224568Szliu clrl r3 # r2:r3 = q as double float 5324568Szliu muld3 r2,r2,r4 # r4:r5 = qq exactly 5424568Szliu divd2 r4,r0 # r0:r1 = x/(q*q) rounded 5524568Szliu subd3 r2,r0,r6 # r6:r7 = x/(q*q) - q exactly 5624568Szliu movq r2,r4 # r4:r5 = q 5724568Szliu addw2 $0x80,r4 # r4:r5 = 2 * q 5824568Szliu addd2 r0,r4 # r4:r5 = 2*q + x/(q*q) 5924568Szliu divd2 r4,r6 # r6:r7 = (x/(q*q)-q)/(2*q+x/(q*q)) 6024568Szliu muld2 r2,r6 # r6:r7 = q*(x/(q*q)-q)/(2*q+x/(q*q)) 6124568Szliu addd3 r6,r2,r0 # r0:r1 = q + r6:r7 6224568Szliu bisw2 ap,r0 # restore the sign bit 6324568Szliureturn: 6424568Szliu ret # error less than 0.667 ulps 6524568Szliu 6624568Szliu.data 6724568Szliu.align 2 6824568SzliuB : .long 721142941 # (86-0.03306235651)*(2^23) 6924568SzliuC : .float 0f0.5428571429 # 19/35 7024568SzliuD : .float 0f-0.7053061224 # -864/1225 7124568SzliuE : .float 0f1.414285714 # 99/70 7224568SzliuF : .float 0f1.607142857 # 45/28 7324568SzliuG : .float 0f0.3571428571 # 5/14 7424568Szliu 75