3 * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
4 * M68000 Hi-Performance Microprocessor Division
5 * M68040 Software Package
7 * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
10 * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
11 * To the maximum extent permitted by applicable law,
12 * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
13 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
14 * PARTICULAR PURPOSE and any warranty against infringement with
15 * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
16 * and any accompanying written materials.
18 * To the maximum extent permitted by applicable law,
19 * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
20 * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
21 * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
22 * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
23 * SOFTWARE. Motorola assumes no responsibility for the maintenance
24 * and support of the SOFTWARE.
26 * You are hereby granted a copyright license to use, modify, and
27 * distribute the SOFTWARE so long as this entire notice is retained
28 * without alteration in any modified and/or redistributed versions,
29 * and that such modified versions are clearly identified as such.
30 * No licenses are granted by implication, estoppel or otherwise
31 * under any patents or trademarks of Motorola, Inc.
34 * sacos.sa 3.3 12/19/90
36 * Description: The entry point sAcos computes the inverse cosine of
37 * an input argument; sAcosd does the same except for denormalized
40 * Input: Double-extended number X in location pointed to
41 * by address register a0.
43 * Output: The value arccos(X) returned in floating-point register Fp0.
45 * Accuracy and Monotonicity: The returned result is within 3 ulps in
46 * 64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
47 * result is subsequently rounded to double precision. The
48 * result is provably monotonic in double precision.
50 * Speed: The program sCOS takes approximately 310 cycles.
55 * 1. If |X| >= 1, go to 3.
57 * 2. (|X| < 1) Calculate acos(X) by
59 * acos(X) = 2 * atan( sqrt(z) ).
62 * 3. If |X| > 1, go to 5.
64 * 4. (|X| = 1) If X > 0, return 0. Otherwise, return Pi. Exit.
66 * 5. (|X| > 1) Generate an invalid operation by 0 * infinity.
70 SACOS IDNT 2,1 Motorola 040 Floating Point Software Package
74 PI DC.L $40000000,$C90FDAA2,$2168C235,$00000000
75 PIBY2 DC.L $3FFF0000,$C90FDAA2,$2168C235,$00000000
83 *--ACOS(X) = PI/2 FOR DENORMALIZED X
84 fmove.l d1,fpcr ...load user's rounding mode/precision
90 FMOVE.X (a0),FP0 ...LOAD INPUT
92 move.l (a0),d0 ...pack exponent with upper 16 fraction
98 *--THIS IS THE USUAL CASE, |X| < 1
99 *--ACOS(X) = 2 * ATAN( SQRT( (1-X)/(1+X) ) )
101 FMOVE.S #:3F800000,FP1
102 FADD.X FP0,FP1 ...1+X
104 FADD.S #:3F800000,FP0 ...1-X
105 FDIV.X FP1,FP0 ...(1-X)/(1+X)
106 FSQRT.X FP0 ...SQRT((1-X)/(1+X))
107 fmovem.x fp0,(a0) ...overwrite input
108 move.l d1,-(sp) ;save original users fpcr
110 bsr satan ...ATAN(SQRT([1-X]/[1+X]))
111 fMOVE.L (sp)+,fpcr ;restore users exceptions
112 FADD.X FP0,FP0 ...2 * ATAN( STUFF )
117 FCMP.S #:3F800000,FP0
118 fbgt t_operr ;cause an operr exception
120 *--|X| = 1, ACOS(X) = 0 OR PI
121 move.l (a0),d0 ...pack exponent with upper 16 fraction
123 TST.L D0 ;D0 has original exponent+fraction
127 *Returns PI and inexact exception
130 FADD.S #:00800000,FP0 ;cause an inexact exception to be put
131 * ;into the 040 - will not trap until next
137 FMOVE.S #:00000000,FP0
138 rts ;Facos of +1 is exact