n_cbrt.S revision 1.1
11.1Sragge/*	$NetBSD: n_cbrt.S,v 1.1 1995/10/10 23:40:26 ragge 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.1Sragge	.globl	_d_cbrt
471.1Sragge	.globl  _dcbrt_
481.1Sragge	.text
491.1Sragge	.align	1
501.1Sragge
511.1Sragge_cbrt:
521.1Sragge_d_cbrt:
531.1Sragge	.word	0x00fc		# save r2 to r7
541.1Sragge	movq	4(ap),r0	# r0 = argument x
551.1Sragge	jmp 	dcbrt2
561.1Sragge_dcbrt_:
571.1Sragge	.word	0x00fc		# save r2 to r7
581.1Sragge	movq	*4(ap),r0	# r0 = argument x
591.1Sragge
601.1Sraggedcbrt2:	bicw3	$0x807f,r0,r2	# biased exponent of x
611.1Sragge	jeql	return		# dcbrt(0)=0  dcbrt(res)=res. operand
621.1Sragge	bicw3	$0x7fff,r0,ap	# ap has sign(x)
631.1Sragge	xorw2	ap,r0		# r0 is abs(x)
641.1Sragge	movl	r0,r2		# r2 has abs(x)
651.1Sragge	rotl	$16,r2,r2	# r2 = |x| with bits unscrambled
661.1Sragge	divl2	$3,r2		# rough dcbrt with bias/3
671.1Sragge	addl2	B,r2		# restore bias, diminish fraction
681.1Sragge	rotl	$16,r2,r2	# r2=|q|=|dcbrt| to 5 bits
691.1Sragge	mulf3	r2,r2,r3	# r3 =qq
701.1Sragge	divf2	r0,r3		# r3 = qq/x
711.1Sragge	mulf2	r2,r3
721.1Sragge	addf2	C,r3		# r3 = s = C + qqq/x
731.1Sragge	divf3	r3,D,r4		# r4 = D/s
741.1Sragge	addf2	E,r4
751.1Sragge	addf2	r4,r3		# r3 = s + E + D/s
761.1Sragge	divf3	r3,F,r3		# r3 = F / (s + E + D/s)
771.1Sragge	addf2	G,r3		# r3 = G + F / (s + E + D/s)
781.1Sragge	mulf2	r3,r2		# r2 = qr3 = new q to 23 bits
791.1Sragge	clrl	r3		# r2:r3 = q as double float
801.1Sragge	muld3	r2,r2,r4	# r4:r5 = qq exactly
811.1Sragge	divd2	r4,r0		# r0:r1 = x/(q*q) rounded
821.1Sragge	subd3	r2,r0,r6	# r6:r7 = x/(q*q) - q exactly
831.1Sragge	movq    r2,r4		# r4:r5 = q
841.1Sragge	addw2	$0x80,r4	# r4:r5 = 2 * q
851.1Sragge	addd2	r0,r4		# r4:r5 = 2*q + x/(q*q)
861.1Sragge	divd2	r4,r6		# r6:r7 = (x/(q*q)-q)/(2*q+x/(q*q))
871.1Sragge	muld2	r2,r6		# r6:r7 = q*(x/(q*q)-q)/(2*q+x/(q*q))
881.1Sragge	addd3	r6,r2,r0	# r0:r1 = q + r6:r7
891.1Sragge	bisw2	ap,r0		# restore the sign bit
901.1Sraggereturn:
911.1Sragge	ret			# error less than 0.667 ulps
921.1Sragge
931.1Sragge.data
941.1Sragge.align	2
951.1SraggeB :	.long		 721142941		# (86-0.03306235651)*(2^23)
961.1SraggeC :	.float		0f0.5428571429		# 19/35
971.1SraggeD :	.float		0f-0.7053061224		# -864/1225
981.1SraggeE :	.float		0f1.414285714		# 99/70
991.1SraggeF :	.float		0f1.607142857		# 45/28
1001.1SraggeG :	.float		0f0.3571428571		# 5/14
1011.1Sragge
102