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