Home | History | Annotate | Line # | Download | only in fpsp
      1  1.3      cgd *	$NetBSD: sacos.sa,v 1.3 1994/10/26 07:49:27 cgd Exp $
      2  1.3      cgd 
      3  1.1  mycroft *	MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
      4  1.1  mycroft *	M68000 Hi-Performance Microprocessor Division
      5  1.1  mycroft *	M68040 Software Package 
      6  1.1  mycroft *
      7  1.1  mycroft *	M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
      8  1.1  mycroft *	All rights reserved.
      9  1.1  mycroft *
     10  1.1  mycroft *	THE SOFTWARE is provided on an "AS IS" basis and without warranty.
     11  1.1  mycroft *	To the maximum extent permitted by applicable law,
     12  1.1  mycroft *	MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
     13  1.1  mycroft *	INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
     14  1.1  mycroft *	PARTICULAR PURPOSE and any warranty against infringement with
     15  1.1  mycroft *	regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
     16  1.1  mycroft *	and any accompanying written materials. 
     17  1.1  mycroft *
     18  1.1  mycroft *	To the maximum extent permitted by applicable law,
     19  1.1  mycroft *	IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
     20  1.1  mycroft *	(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
     21  1.1  mycroft *	PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
     22  1.1  mycroft *	OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
     23  1.1  mycroft *	SOFTWARE.  Motorola assumes no responsibility for the maintenance
     24  1.1  mycroft *	and support of the SOFTWARE.  
     25  1.1  mycroft *
     26  1.1  mycroft *	You are hereby granted a copyright license to use, modify, and
     27  1.1  mycroft *	distribute the SOFTWARE so long as this entire notice is retained
     28  1.1  mycroft *	without alteration in any modified and/or redistributed versions,
     29  1.1  mycroft *	and that such modified versions are clearly identified as such.
     30  1.1  mycroft *	No licenses are granted by implication, estoppel or otherwise
     31  1.1  mycroft *	under any patents or trademarks of Motorola, Inc.
     32  1.1  mycroft 
     33  1.1  mycroft *
     34  1.1  mycroft *	sacos.sa 3.3 12/19/90
     35  1.1  mycroft *
     36  1.1  mycroft *	Description: The entry point sAcos computes the inverse cosine of
     37  1.1  mycroft *		an input argument; sAcosd does the same except for denormalized
     38  1.1  mycroft *		input.
     39  1.1  mycroft *
     40  1.1  mycroft *	Input: Double-extended number X in location pointed to
     41  1.1  mycroft *		by address register a0.
     42  1.1  mycroft *
     43  1.1  mycroft *	Output: The value arccos(X) returned in floating-point register Fp0.
     44  1.1  mycroft *
     45  1.1  mycroft *	Accuracy and Monotonicity: The returned result is within 3 ulps in
     46  1.1  mycroft *		64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
     47  1.1  mycroft *		result is subsequently rounded to double precision. The 
     48  1.1  mycroft *		result is provably monotonic in double precision.
     49  1.1  mycroft *
     50  1.1  mycroft *	Speed: The program sCOS takes approximately 310 cycles.
     51  1.1  mycroft *
     52  1.1  mycroft *	Algorithm:
     53  1.1  mycroft *
     54  1.1  mycroft *	ACOS
     55  1.1  mycroft *	1. If |X| >= 1, go to 3.
     56  1.1  mycroft *
     57  1.1  mycroft *	2. (|X| < 1) Calculate acos(X) by
     58  1.1  mycroft *		z := (1-X) / (1+X)
     59  1.1  mycroft *		acos(X) = 2 * atan( sqrt(z) ).
     60  1.1  mycroft *		Exit.
     61  1.1  mycroft *
     62  1.1  mycroft *	3. If |X| > 1, go to 5.
     63  1.1  mycroft *
     64  1.1  mycroft *	4. (|X| = 1) If X > 0, return 0. Otherwise, return Pi. Exit.
     65  1.1  mycroft *
     66  1.1  mycroft *	5. (|X| > 1) Generate an invalid operation by 0 * infinity.
     67  1.1  mycroft *		Exit.
     68  1.1  mycroft *
     69  1.1  mycroft 
     70  1.1  mycroft SACOS	IDNT	2,1 Motorola 040 Floating Point Software Package
     71  1.1  mycroft 
     72  1.1  mycroft 	section	8
     73  1.1  mycroft 
     74  1.1  mycroft PI	DC.L $40000000,$C90FDAA2,$2168C235,$00000000
     75  1.1  mycroft PIBY2	DC.L $3FFF0000,$C90FDAA2,$2168C235,$00000000
     76  1.1  mycroft 
     77  1.1  mycroft 	xref	t_operr
     78  1.1  mycroft 	xref	t_frcinx
     79  1.1  mycroft 	xref	satan
     80  1.1  mycroft 
     81  1.1  mycroft 	xdef	sacosd
     82  1.1  mycroft sacosd:
     83  1.1  mycroft *--ACOS(X) = PI/2 FOR DENORMALIZED X
     84  1.1  mycroft 	fmove.l		d1,fpcr		...load user's rounding mode/precision
     85  1.1  mycroft 	FMOVE.X		PIBY2,FP0
     86  1.1  mycroft 	bra		t_frcinx
     87  1.1  mycroft 
     88  1.1  mycroft 	xdef	sacos
     89  1.1  mycroft sacos:
     90  1.1  mycroft 	FMOVE.X		(a0),FP0	...LOAD INPUT
     91  1.1  mycroft 
     92  1.1  mycroft 	move.l		(a0),d0		...pack exponent with upper 16 fraction
     93  1.1  mycroft 	move.w		4(a0),d0
     94  1.1  mycroft 	ANDI.L		#$7FFFFFFF,D0
     95  1.1  mycroft 	CMPI.L		#$3FFF8000,D0
     96  1.1  mycroft 	BGE.B		ACOSBIG
     97  1.1  mycroft 
     98  1.1  mycroft *--THIS IS THE USUAL CASE, |X| < 1
     99  1.1  mycroft *--ACOS(X) = 2 * ATAN(	SQRT( (1-X)/(1+X) )	)
    100  1.1  mycroft 
    101  1.1  mycroft 	FMOVE.S		#:3F800000,FP1
    102  1.1  mycroft 	FADD.X		FP0,FP1	 	...1+X
    103  1.1  mycroft 	FNEG.X		FP0	 	... -X
    104  1.1  mycroft 	FADD.S		#:3F800000,FP0	...1-X
    105  1.1  mycroft 	FDIV.X		FP1,FP0	 	...(1-X)/(1+X)
    106  1.1  mycroft 	FSQRT.X		FP0		...SQRT((1-X)/(1+X))
    107  1.1  mycroft 	fmovem.x	fp0,(a0)	...overwrite input
    108  1.1  mycroft 	move.l		d1,-(sp)	;save original users fpcr
    109  1.1  mycroft 	clr.l		d1
    110  1.1  mycroft 	bsr		satan		...ATAN(SQRT([1-X]/[1+X]))
    111  1.1  mycroft 	fMOVE.L		(sp)+,fpcr	;restore users exceptions
    112  1.1  mycroft 	FADD.X		FP0,FP0	 	...2 * ATAN( STUFF )
    113  1.1  mycroft 	bra		t_frcinx
    114  1.1  mycroft 
    115  1.1  mycroft ACOSBIG:
    116  1.1  mycroft 	FABS.X		FP0
    117  1.1  mycroft 	FCMP.S		#:3F800000,FP0
    118  1.1  mycroft 	fbgt		t_operr		;cause an operr exception
    119  1.1  mycroft 
    120  1.1  mycroft *--|X| = 1, ACOS(X) = 0 OR PI
    121  1.1  mycroft 	move.l		(a0),d0		...pack exponent with upper 16 fraction
    122  1.1  mycroft 	move.w		4(a0),d0
    123  1.2  mycroft 	TST.L		D0		;D0 has original exponent+fraction
    124  1.1  mycroft 	BGT.B		ACOSP1
    125  1.1  mycroft 
    126  1.1  mycroft *--X = -1
    127  1.1  mycroft *Returns PI and inexact exception
    128  1.1  mycroft 	FMOVE.X		PI,FP0
    129  1.1  mycroft 	FMOVE.L		d1,FPCR
    130  1.1  mycroft 	FADD.S		#:00800000,FP0	;cause an inexact exception to be put
    131  1.1  mycroft *					;into the 040 - will not trap until next
    132  1.1  mycroft *					;fp inst.
    133  1.1  mycroft 	bra		t_frcinx
    134  1.1  mycroft 
    135  1.1  mycroft ACOSP1:
    136  1.1  mycroft 	FMOVE.L		d1,FPCR
    137  1.1  mycroft 	FMOVE.S		#:00000000,FP0
    138  1.1  mycroft 	rts				;Facos of +1 is exact	
    139  1.1  mycroft 
    140  1.1  mycroft 	end
    141