sacos.sa revision 1.3 1 * $NetBSD: sacos.sa,v 1.3 1994/10/26 07:49:27 cgd Exp $
2
3 * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
4 * M68000 Hi-Performance Microprocessor Division
5 * M68040 Software Package
6 *
7 * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
8 * All rights reserved.
9 *
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.
17 *
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.
25 *
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.
32
33 *
34 * sacos.sa 3.3 12/19/90
35 *
36 * Description: The entry point sAcos computes the inverse cosine of
37 * an input argument; sAcosd does the same except for denormalized
38 * input.
39 *
40 * Input: Double-extended number X in location pointed to
41 * by address register a0.
42 *
43 * Output: The value arccos(X) returned in floating-point register Fp0.
44 *
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.
49 *
50 * Speed: The program sCOS takes approximately 310 cycles.
51 *
52 * Algorithm:
53 *
54 * ACOS
55 * 1. If |X| >= 1, go to 3.
56 *
57 * 2. (|X| < 1) Calculate acos(X) by
58 * z := (1-X) / (1+X)
59 * acos(X) = 2 * atan( sqrt(z) ).
60 * Exit.
61 *
62 * 3. If |X| > 1, go to 5.
63 *
64 * 4. (|X| = 1) If X > 0, return 0. Otherwise, return Pi. Exit.
65 *
66 * 5. (|X| > 1) Generate an invalid operation by 0 * infinity.
67 * Exit.
68 *
69
70 SACOS IDNT 2,1 Motorola 040 Floating Point Software Package
71
72 section 8
73
74 PI DC.L $40000000,$C90FDAA2,$2168C235,$00000000
75 PIBY2 DC.L $3FFF0000,$C90FDAA2,$2168C235,$00000000
76
77 xref t_operr
78 xref t_frcinx
79 xref satan
80
81 xdef sacosd
82 sacosd:
83 *--ACOS(X) = PI/2 FOR DENORMALIZED X
84 fmove.l d1,fpcr ...load user's rounding mode/precision
85 FMOVE.X PIBY2,FP0
86 bra t_frcinx
87
88 xdef sacos
89 sacos:
90 FMOVE.X (a0),FP0 ...LOAD INPUT
91
92 move.l (a0),d0 ...pack exponent with upper 16 fraction
93 move.w 4(a0),d0
94 ANDI.L #$7FFFFFFF,D0
95 CMPI.L #$3FFF8000,D0
96 BGE.B ACOSBIG
97
98 *--THIS IS THE USUAL CASE, |X| < 1
99 *--ACOS(X) = 2 * ATAN( SQRT( (1-X)/(1+X) ) )
100
101 FMOVE.S #:3F800000,FP1
102 FADD.X FP0,FP1 ...1+X
103 FNEG.X FP0 ... -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
109 clr.l d1
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 )
113 bra t_frcinx
114
115 ACOSBIG:
116 FABS.X FP0
117 FCMP.S #:3F800000,FP0
118 fbgt t_operr ;cause an operr exception
119
120 *--|X| = 1, ACOS(X) = 0 OR PI
121 move.l (a0),d0 ...pack exponent with upper 16 fraction
122 move.w 4(a0),d0
123 TST.L D0 ;D0 has original exponent+fraction
124 BGT.B ACOSP1
125
126 *--X = -1
127 *Returns PI and inexact exception
128 FMOVE.X PI,FP0
129 FMOVE.L d1,FPCR
130 FADD.S #:00800000,FP0 ;cause an inexact exception to be put
131 * ;into the 040 - will not trap until next
132 * ;fp inst.
133 bra t_frcinx
134
135 ACOSP1:
136 FMOVE.L d1,FPCR
137 FMOVE.S #:00000000,FP0
138 rts ;Facos of +1 is exact
139
140 end
141