n_cbrt.S revision 1.5
11.5Smatt/*	$NetBSD: n_cbrt.S,v 1.5 2002/02/24 01:06:21 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.4Smatt#include <machine/asm.h>
381.4Smatt
391.1Sragge/*
401.1Sragge * double cbrt(double arg)
411.1Sragge * W. Kahan, 10/13/80. revised 1/13/84 for keeping sign symmetry
421.1Sragge * error check by E LeBlanc, 8/18/82
431.3Ssimonb * Revised and tested by K.C. Ng, 5/2/85
441.1Sragge * Max error less than 0.667 ulps (unit in the last places)
451.1Sragge */
461.1Sragge
471.4SmattALTENTRY(cbrt)
481.5SmattENTRY(d_cbrt, 0x00c0)		# save %r6 & %r7
491.5Smatt	movq	4(%ap),%r0	# %r0 = argument x
501.4Smatt	jbr 	dcbrt2
511.4Smatt
521.5SmattENTRY(dcbrt_, 0x00c0)		# save %r6 & %r7
531.5Smatt	movq	*4(%ap),%r0	# %r0 = argument x
541.1Sragge
551.5Smattdcbrt2:	bicw3	$0x807f,%r0,%r2	# biased exponent of x
561.1Sragge	jeql	return		# dcbrt(0)=0  dcbrt(res)=res. operand
571.5Smatt	bicw3	$0x7fff,%r0,%ap	# ap has sign(x)
581.5Smatt	xorw2	%ap,%r0		# %r0 is abs(x)
591.5Smatt	movl	%r0,%r2		# %r2 has abs(x)
601.5Smatt	rotl	$16,%r2,%r2	# %r2 = |x| with bits unscrambled
611.5Smatt	divl2	$3,%r2		# rough dcbrt with bias/3
621.5Smatt	addl2	B,%r2		# restore bias, diminish fraction
631.5Smatt	rotl	$16,%r2,%r2	# %r2=|q|=|dcbrt| to 5 bits
641.5Smatt	mulf3	%r2,%r2,%r3	# %r3 =qq
651.5Smatt	divf2	%r0,%r3		# %r3 = qq/x
661.5Smatt	mulf2	%r2,%r3
671.5Smatt	addf2	C,%r3		# %r3 = s = C + qqq/x
681.5Smatt	divf3	%r3,D,%r4		# %r4 = D/s
691.5Smatt	addf2	E,%r4
701.5Smatt	addf2	%r4,%r3		# %r3 = s + E + D/s
711.5Smatt	divf3	%r3,F,%r3		# %r3 = F / (s + E + D/s)
721.5Smatt	addf2	G,%r3		# %r3 = G + F / (s + E + D/s)
731.5Smatt	mulf2	%r3,%r2		# %r2 = q%r3 = new q to 23 bits
741.5Smatt	clrl	%r3		# %r2:%r3 = q as double float
751.5Smatt	muld3	%r2,%r2,%r4	# %r4:%r5 = qq exactly
761.5Smatt	divd2	%r4,%r0		# %r0:%r1 = x/(q*q) rounded
771.5Smatt	subd3	%r2,%r0,%r6	# %r6:%r7 = x/(q*q) - q exactly
781.5Smatt	movq    %r2,%r4		# %r4:%r5 = q
791.5Smatt	addw2	$0x80,%r4	# %r4:%r5 = 2 * q
801.5Smatt	addd2	%r0,%r4		# %r4:%r5 = 2*q + x/(q*q)
811.5Smatt	divd2	%r4,%r6		# %r6:%r7 = (x/(q*q)-q)/(2*q+x/(q*q))
821.5Smatt	muld2	%r2,%r6		# %r6:%r7 = q*(x/(q*q)-q)/(2*q+x/(q*q))
831.5Smatt	addd3	%r6,%r2,%r0	# %r0:%r1 = q + %r6:%r7
841.5Smatt	bisw2	%ap,%r0		# restore the sign bit
851.1Sraggereturn:
861.1Sragge	ret			# error less than 0.667 ulps
871.1Sragge
881.4Smatt	_ALIGN_TEXT
891.1SraggeB :	.long		 721142941		# (86-0.03306235651)*(2^23)
901.1SraggeC :	.float		0f0.5428571429		# 19/35
911.1SraggeD :	.float		0f-0.7053061224		# -864/1225
921.1SraggeE :	.float		0f1.414285714		# 99/70
931.1SraggeF :	.float		0f1.607142857		# 45/28
941.1SraggeG :	.float		0f0.3571428571		# 5/14
95