502 lines
16 KiB
Plaintext
502 lines
16 KiB
Plaintext
|
* MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
|
||
|
* M68000 Hi-Performance Microprocessor Division
|
||
|
* M68040 Software Package
|
||
|
*
|
||
|
* M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* THE SOFTWARE is provided on an "AS IS" basis and without warranty.
|
||
|
* To the maximum extent permitted by applicable law,
|
||
|
* MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
|
||
|
* INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
|
||
|
* PARTICULAR PURPOSE and any warranty against infringement with
|
||
|
* regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
|
||
|
* and any accompanying written materials.
|
||
|
*
|
||
|
* To the maximum extent permitted by applicable law,
|
||
|
* IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
|
||
|
* (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
|
||
|
* PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
|
||
|
* OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
|
||
|
* SOFTWARE. Motorola assumes no responsibility for the maintenance
|
||
|
* and support of the SOFTWARE.
|
||
|
*
|
||
|
* You are hereby granted a copyright license to use, modify, and
|
||
|
* distribute the SOFTWARE so long as this entire notice is retained
|
||
|
* without alteration in any modified and/or redistributed versions,
|
||
|
* and that such modified versions are clearly identified as such.
|
||
|
* No licenses are granted by implication, estoppel or otherwise
|
||
|
* under any patents or trademarks of Motorola, Inc.
|
||
|
|
||
|
*
|
||
|
* satan.sa 3.3 12/19/90
|
||
|
*
|
||
|
* The entry point satan computes the arctagent of an
|
||
|
* input value. satand does the same except the input value is a
|
||
|
* denormalized number.
|
||
|
*
|
||
|
* Input: Double-extended value in memory location pointed to by address
|
||
|
* register a0.
|
||
|
*
|
||
|
* Output: Arctan(X) returned in floating-point register Fp0.
|
||
|
*
|
||
|
* Accuracy and Monotonicity: The returned result is within 2 ulps in
|
||
|
* 64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
|
||
|
* result is subsequently rounded to double precision. The
|
||
|
* result is provably monotonic in double precision.
|
||
|
*
|
||
|
* Speed: The program satan takes approximately 160 cycles for input
|
||
|
* argument X such that 1/16 < |X| < 16. For the other arguments,
|
||
|
* the program will run no worse than 10% slower.
|
||
|
*
|
||
|
* Algorithm:
|
||
|
* Step 1. If |X| >= 16 or |X| < 1/16, go to Step 5.
|
||
|
*
|
||
|
* Step 2. Let X = sgn * 2**k * 1.xxxxxxxx...x. Note that k = -4, -3,..., or 3.
|
||
|
* Define F = sgn * 2**k * 1.xxxx1, i.e. the first 5 significant bits
|
||
|
* of X with a bit-1 attached at the 6-th bit position. Define u
|
||
|
* to be u = (X-F) / (1 + X*F).
|
||
|
*
|
||
|
* Step 3. Approximate arctan(u) by a polynomial poly.
|
||
|
*
|
||
|
* Step 4. Return arctan(F) + poly, arctan(F) is fetched from a table of values
|
||
|
* calculated beforehand. Exit.
|
||
|
*
|
||
|
* Step 5. If |X| >= 16, go to Step 7.
|
||
|
*
|
||
|
* Step 6. Approximate arctan(X) by an odd polynomial in X. Exit.
|
||
|
*
|
||
|
* Step 7. Define X' = -1/X. Approximate arctan(X') by an odd polynomial in X'.
|
||
|
* Arctan(X) = sign(X)*Pi/2 + arctan(X'). Exit.
|
||
|
*
|
||
|
|
||
|
satan IDNT 2,1 Motorola 040 Floating Point Software Package
|
||
|
|
||
|
section 8
|
||
|
|
||
|
include fpsp.h
|
||
|
|
||
|
BOUNDS1 DC.L $3FFB8000,$4002FFFF
|
||
|
|
||
|
ONE DC.L $3F800000
|
||
|
|
||
|
DC.L $00000000
|
||
|
|
||
|
ATANA3 DC.L $BFF6687E,$314987D8
|
||
|
ATANA2 DC.L $4002AC69,$34A26DB3
|
||
|
|
||
|
ATANA1 DC.L $BFC2476F,$4E1DA28E
|
||
|
ATANB6 DC.L $3FB34444,$7F876989
|
||
|
|
||
|
ATANB5 DC.L $BFB744EE,$7FAF45DB
|
||
|
ATANB4 DC.L $3FBC71C6,$46940220
|
||
|
|
||
|
ATANB3 DC.L $BFC24924,$921872F9
|
||
|
ATANB2 DC.L $3FC99999,$99998FA9
|
||
|
|
||
|
ATANB1 DC.L $BFD55555,$55555555
|
||
|
ATANC5 DC.L $BFB70BF3,$98539E6A
|
||
|
|
||
|
ATANC4 DC.L $3FBC7187,$962D1D7D
|
||
|
ATANC3 DC.L $BFC24924,$827107B8
|
||
|
|
||
|
ATANC2 DC.L $3FC99999,$9996263E
|
||
|
ATANC1 DC.L $BFD55555,$55555536
|
||
|
|
||
|
PPIBY2 DC.L $3FFF0000,$C90FDAA2,$2168C235,$00000000
|
||
|
NPIBY2 DC.L $BFFF0000,$C90FDAA2,$2168C235,$00000000
|
||
|
PTINY DC.L $00010000,$80000000,$00000000,$00000000
|
||
|
NTINY DC.L $80010000,$80000000,$00000000,$00000000
|
||
|
|
||
|
ATANTBL:
|
||
|
DC.L $3FFB0000,$83D152C5,$060B7A51,$00000000
|
||
|
DC.L $3FFB0000,$8BC85445,$65498B8B,$00000000
|
||
|
DC.L $3FFB0000,$93BE4060,$17626B0D,$00000000
|
||
|
DC.L $3FFB0000,$9BB3078D,$35AEC202,$00000000
|
||
|
DC.L $3FFB0000,$A3A69A52,$5DDCE7DE,$00000000
|
||
|
DC.L $3FFB0000,$AB98E943,$62765619,$00000000
|
||
|
DC.L $3FFB0000,$B389E502,$F9C59862,$00000000
|
||
|
DC.L $3FFB0000,$BB797E43,$6B09E6FB,$00000000
|
||
|
DC.L $3FFB0000,$C367A5C7,$39E5F446,$00000000
|
||
|
DC.L $3FFB0000,$CB544C61,$CFF7D5C6,$00000000
|
||
|
DC.L $3FFB0000,$D33F62F8,$2488533E,$00000000
|
||
|
DC.L $3FFB0000,$DB28DA81,$62404C77,$00000000
|
||
|
DC.L $3FFB0000,$E310A407,$8AD34F18,$00000000
|
||
|
DC.L $3FFB0000,$EAF6B0A8,$188EE1EB,$00000000
|
||
|
DC.L $3FFB0000,$F2DAF194,$9DBE79D5,$00000000
|
||
|
DC.L $3FFB0000,$FABD5813,$61D47E3E,$00000000
|
||
|
DC.L $3FFC0000,$8346AC21,$0959ECC4,$00000000
|
||
|
DC.L $3FFC0000,$8B232A08,$304282D8,$00000000
|
||
|
DC.L $3FFC0000,$92FB70B8,$D29AE2F9,$00000000
|
||
|
DC.L $3FFC0000,$9ACF476F,$5CCD1CB4,$00000000
|
||
|
DC.L $3FFC0000,$A29E7630,$4954F23F,$00000000
|
||
|
DC.L $3FFC0000,$AA68C5D0,$8AB85230,$00000000
|
||
|
DC.L $3FFC0000,$B22DFFFD,$9D539F83,$00000000
|
||
|
DC.L $3FFC0000,$B9EDEF45,$3E900EA5,$00000000
|
||
|
DC.L $3FFC0000,$C1A85F1C,$C75E3EA5,$00000000
|
||
|
DC.L $3FFC0000,$C95D1BE8,$28138DE6,$00000000
|
||
|
DC.L $3FFC0000,$D10BF300,$840D2DE4,$00000000
|
||
|
DC.L $3FFC0000,$D8B4B2BA,$6BC05E7A,$00000000
|
||
|
DC.L $3FFC0000,$E0572A6B,$B42335F6,$00000000
|
||
|
DC.L $3FFC0000,$E7F32A70,$EA9CAA8F,$00000000
|
||
|
DC.L $3FFC0000,$EF888432,$64ECEFAA,$00000000
|
||
|
DC.L $3FFC0000,$F7170A28,$ECC06666,$00000000
|
||
|
DC.L $3FFD0000,$812FD288,$332DAD32,$00000000
|
||
|
DC.L $3FFD0000,$88A8D1B1,$218E4D64,$00000000
|
||
|
DC.L $3FFD0000,$9012AB3F,$23E4AEE8,$00000000
|
||
|
DC.L $3FFD0000,$976CC3D4,$11E7F1B9,$00000000
|
||
|
DC.L $3FFD0000,$9EB68949,$3889A227,$00000000
|
||
|
DC.L $3FFD0000,$A5EF72C3,$4487361B,$00000000
|
||
|
DC.L $3FFD0000,$AD1700BA,$F07A7227,$00000000
|
||
|
DC.L $3FFD0000,$B42CBCFA,$FD37EFB7,$00000000
|
||
|
DC.L $3FFD0000,$BB303A94,$0BA80F89,$00000000
|
||
|
DC.L $3FFD0000,$C22115C6,$FCAEBBAF,$00000000
|
||
|
DC.L $3FFD0000,$C8FEF3E6,$86331221,$00000000
|
||
|
DC.L $3FFD0000,$CFC98330,$B4000C70,$00000000
|
||
|
DC.L $3FFD0000,$D6807AA1,$102C5BF9,$00000000
|
||
|
DC.L $3FFD0000,$DD2399BC,$31252AA3,$00000000
|
||
|
DC.L $3FFD0000,$E3B2A855,$6B8FC517,$00000000
|
||
|
DC.L $3FFD0000,$EA2D764F,$64315989,$00000000
|
||
|
DC.L $3FFD0000,$F3BF5BF8,$BAD1A21D,$00000000
|
||
|
DC.L $3FFE0000,$801CE39E,$0D205C9A,$00000000
|
||
|
DC.L $3FFE0000,$8630A2DA,$DA1ED066,$00000000
|
||
|
DC.L $3FFE0000,$8C1AD445,$F3E09B8C,$00000000
|
||
|
DC.L $3FFE0000,$91DB8F16,$64F350E2,$00000000
|
||
|
DC.L $3FFE0000,$97731420,$365E538C,$00000000
|
||
|
DC.L $3FFE0000,$9CE1C8E6,$A0B8CDBA,$00000000
|
||
|
DC.L $3FFE0000,$A22832DB,$CADAAE09,$00000000
|
||
|
DC.L $3FFE0000,$A746F2DD,$B7602294,$00000000
|
||
|
DC.L $3FFE0000,$AC3EC0FB,$997DD6A2,$00000000
|
||
|
DC.L $3FFE0000,$B110688A,$EBDC6F6A,$00000000
|
||
|
DC.L $3FFE0000,$B5BCC490,$59ECC4B0,$00000000
|
||
|
DC.L $3FFE0000,$BA44BC7D,$D470782F,$00000000
|
||
|
DC.L $3FFE0000,$BEA94144,$FD049AAC,$00000000
|
||
|
DC.L $3FFE0000,$C2EB4ABB,$661628B6,$00000000
|
||
|
DC.L $3FFE0000,$C70BD54C,$E602EE14,$00000000
|
||
|
DC.L $3FFE0000,$CD000549,$ADEC7159,$00000000
|
||
|
DC.L $3FFE0000,$D48457D2,$D8EA4EA3,$00000000
|
||
|
DC.L $3FFE0000,$DB948DA7,$12DECE3B,$00000000
|
||
|
DC.L $3FFE0000,$E23855F9,$69E8096A,$00000000
|
||
|
DC.L $3FFE0000,$E8771129,$C4353259,$00000000
|
||
|
DC.L $3FFE0000,$EE57C16E,$0D379C0D,$00000000
|
||
|
DC.L $3FFE0000,$F3E10211,$A87C3779,$00000000
|
||
|
DC.L $3FFE0000,$F919039D,$758B8D41,$00000000
|
||
|
DC.L $3FFE0000,$FE058B8F,$64935FB3,$00000000
|
||
|
DC.L $3FFF0000,$8155FB49,$7B685D04,$00000000
|
||
|
DC.L $3FFF0000,$83889E35,$49D108E1,$00000000
|
||
|
DC.L $3FFF0000,$859CFA76,$511D724B,$00000000
|
||
|
DC.L $3FFF0000,$87952ECF,$FF8131E7,$00000000
|
||
|
DC.L $3FFF0000,$89732FD1,$9557641B,$00000000
|
||
|
DC.L $3FFF0000,$8B38CAD1,$01932A35,$00000000
|
||
|
DC.L $3FFF0000,$8CE7A8D8,$301EE6B5,$00000000
|
||
|
DC.L $3FFF0000,$8F46A39E,$2EAE5281,$00000000
|
||
|
DC.L $3FFF0000,$922DA7D7,$91888487,$00000000
|
||
|
DC.L $3FFF0000,$94D19FCB,$DEDF5241,$00000000
|
||
|
DC.L $3FFF0000,$973AB944,$19D2A08B,$00000000
|
||
|
DC.L $3FFF0000,$996FF00E,$08E10B96,$00000000
|
||
|
DC.L $3FFF0000,$9B773F95,$12321DA7,$00000000
|
||
|
DC.L $3FFF0000,$9D55CC32,$0F935624,$00000000
|
||
|
DC.L $3FFF0000,$9F100575,$006CC571,$00000000
|
||
|
DC.L $3FFF0000,$A0A9C290,$D97CC06C,$00000000
|
||
|
DC.L $3FFF0000,$A22659EB,$EBC0630A,$00000000
|
||
|
DC.L $3FFF0000,$A388B4AF,$F6EF0EC9,$00000000
|
||
|
DC.L $3FFF0000,$A4D35F10,$61D292C4,$00000000
|
||
|
DC.L $3FFF0000,$A60895DC,$FBE3187E,$00000000
|
||
|
DC.L $3FFF0000,$A72A51DC,$7367BEAC,$00000000
|
||
|
DC.L $3FFF0000,$A83A5153,$0956168F,$00000000
|
||
|
DC.L $3FFF0000,$A93A2007,$7539546E,$00000000
|
||
|
DC.L $3FFF0000,$AA9E7245,$023B2605,$00000000
|
||
|
DC.L $3FFF0000,$AC4C84BA,$6FE4D58F,$00000000
|
||
|
DC.L $3FFF0000,$ADCE4A4A,$606B9712,$00000000
|
||
|
DC.L $3FFF0000,$AF2A2DCD,$8D263C9C,$00000000
|
||
|
DC.L $3FFF0000,$B0656F81,$F22265C7,$00000000
|
||
|
DC.L $3FFF0000,$B1846515,$0F71496A,$00000000
|
||
|
DC.L $3FFF0000,$B28AAA15,$6F9ADA35,$00000000
|
||
|
DC.L $3FFF0000,$B37B44FF,$3766B895,$00000000
|
||
|
DC.L $3FFF0000,$B458C3DC,$E9630433,$00000000
|
||
|
DC.L $3FFF0000,$B525529D,$562246BD,$00000000
|
||
|
DC.L $3FFF0000,$B5E2CCA9,$5F9D88CC,$00000000
|
||
|
DC.L $3FFF0000,$B692CADA,$7ACA1ADA,$00000000
|
||
|
DC.L $3FFF0000,$B736AEA7,$A6925838,$00000000
|
||
|
DC.L $3FFF0000,$B7CFAB28,$7E9F7B36,$00000000
|
||
|
DC.L $3FFF0000,$B85ECC66,$CB219835,$00000000
|
||
|
DC.L $3FFF0000,$B8E4FD5A,$20A593DA,$00000000
|
||
|
DC.L $3FFF0000,$B99F41F6,$4AFF9BB5,$00000000
|
||
|
DC.L $3FFF0000,$BA7F1E17,$842BBE7B,$00000000
|
||
|
DC.L $3FFF0000,$BB471285,$7637E17D,$00000000
|
||
|
DC.L $3FFF0000,$BBFABE8A,$4788DF6F,$00000000
|
||
|
DC.L $3FFF0000,$BC9D0FAD,$2B689D79,$00000000
|
||
|
DC.L $3FFF0000,$BD306A39,$471ECD86,$00000000
|
||
|
DC.L $3FFF0000,$BDB6C731,$856AF18A,$00000000
|
||
|
DC.L $3FFF0000,$BE31CAC5,$02E80D70,$00000000
|
||
|
DC.L $3FFF0000,$BEA2D55C,$E33194E2,$00000000
|
||
|
DC.L $3FFF0000,$BF0B10B7,$C03128F0,$00000000
|
||
|
DC.L $3FFF0000,$BF6B7A18,$DACB778D,$00000000
|
||
|
DC.L $3FFF0000,$BFC4EA46,$63FA18F6,$00000000
|
||
|
DC.L $3FFF0000,$C0181BDE,$8B89A454,$00000000
|
||
|
DC.L $3FFF0000,$C065B066,$CFBF6439,$00000000
|
||
|
DC.L $3FFF0000,$C0AE345F,$56340AE6,$00000000
|
||
|
DC.L $3FFF0000,$C0F22291,$9CB9E6A7,$00000000
|
||
|
|
||
|
X equ FP_SCR1
|
||
|
XDCARE equ X+2
|
||
|
XFRAC equ X+4
|
||
|
XFRACLO equ X+8
|
||
|
|
||
|
ATANF equ FP_SCR2
|
||
|
ATANFHI equ ATANF+4
|
||
|
ATANFLO equ ATANF+8
|
||
|
|
||
|
|
||
|
xref t_frcinx
|
||
|
xref t_extdnrm
|
||
|
|
||
|
xdef satand
|
||
|
satand:
|
||
|
*--ENTRY POINT FOR ATAN(X) FOR DENORMALIZED ARGUMENT
|
||
|
|
||
|
bra t_extdnrm
|
||
|
|
||
|
xdef satan
|
||
|
satan:
|
||
|
*--ENTRY POINT FOR ATAN(X), HERE X IS FINITE, NON-ZERO, AND NOT NAN'S
|
||
|
|
||
|
FMOVE.X (A0),FP0 ...LOAD INPUT
|
||
|
|
||
|
MOVE.L (A0),D0
|
||
|
MOVE.W 4(A0),D0
|
||
|
FMOVE.X FP0,X(a6)
|
||
|
ANDI.L #$7FFFFFFF,D0
|
||
|
|
||
|
CMPI.L #$3FFB8000,D0 ...|X| >= 1/16?
|
||
|
BGE.B ATANOK1
|
||
|
BRA.W ATANSM
|
||
|
|
||
|
ATANOK1:
|
||
|
CMPI.L #$4002FFFF,D0 ...|X| < 16 ?
|
||
|
BLE.B ATANMAIN
|
||
|
BRA.W ATANBIG
|
||
|
|
||
|
|
||
|
*--THE MOST LIKELY CASE, |X| IN [1/16, 16). WE USE TABLE TECHNIQUE
|
||
|
*--THE IDEA IS ATAN(X) = ATAN(F) + ATAN( [X-F] / [1+XF] ).
|
||
|
*--SO IF F IS CHOSEN TO BE CLOSE TO X AND ATAN(F) IS STORED IN
|
||
|
*--A TABLE, ALL WE NEED IS TO APPROXIMATE ATAN(U) WHERE
|
||
|
*--U = (X-F)/(1+XF) IS SMALL (REMEMBER F IS CLOSE TO X). IT IS
|
||
|
*--TRUE THAT A DIVIDE IS NOW NEEDED, BUT THE APPROXIMATION FOR
|
||
|
*--ATAN(U) IS A VERY SHORT POLYNOMIAL AND THE INDEXING TO
|
||
|
*--FETCH F AND SAVING OF REGISTERS CAN BE ALL HIDED UNDER THE
|
||
|
*--DIVIDE. IN THE END THIS METHOD IS MUCH FASTER THAN A TRADITIONAL
|
||
|
*--ONE. NOTE ALSO THAT THE TRADITIONAL SCHEME THAT APPROXIMATE
|
||
|
*--ATAN(X) DIRECTLY WILL NEED TO USE A RATIONAL APPROXIMATION
|
||
|
*--(DIVISION NEEDED) ANYWAY BECAUSE A POLYNOMIAL APPROXIMATION
|
||
|
*--WILL INVOLVE A VERY LONG POLYNOMIAL.
|
||
|
|
||
|
*--NOW WE SEE X AS +-2^K * 1.BBBBBBB....B <- 1. + 63 BITS
|
||
|
*--WE CHOSE F TO BE +-2^K * 1.BBBB1
|
||
|
*--THAT IS IT MATCHES THE EXPONENT AND FIRST 5 BITS OF X, THE
|
||
|
*--SIXTH BITS IS SET TO BE 1. SINCE K = -4, -3, ..., 3, THERE
|
||
|
*--ARE ONLY 8 TIMES 16 = 2^7 = 128 |F|'S. SINCE ATAN(-|F|) IS
|
||
|
*-- -ATAN(|F|), WE NEED TO STORE ONLY ATAN(|F|).
|
||
|
|
||
|
ATANMAIN:
|
||
|
|
||
|
MOVE.W #$0000,XDCARE(a6) ...CLEAN UP X JUST IN CASE
|
||
|
ANDI.L #$F8000000,XFRAC(a6) ...FIRST 5 BITS
|
||
|
ORI.L #$04000000,XFRAC(a6) ...SET 6-TH BIT TO 1
|
||
|
MOVE.L #$00000000,XFRACLO(a6) ...LOCATION OF X IS NOW F
|
||
|
|
||
|
FMOVE.X FP0,FP1 ...FP1 IS X
|
||
|
FMUL.X X(a6),FP1 ...FP1 IS X*F, NOTE THAT X*F > 0
|
||
|
FSUB.X X(a6),FP0 ...FP0 IS X-F
|
||
|
FADD.S #:3F800000,FP1 ...FP1 IS 1 + X*F
|
||
|
FDIV.X FP1,FP0 ...FP0 IS U = (X-F)/(1+X*F)
|
||
|
|
||
|
*--WHILE THE DIVISION IS TAKING ITS TIME, WE FETCH ATAN(|F|)
|
||
|
*--CREATE ATAN(F) AND STORE IT IN ATANF, AND
|
||
|
*--SAVE REGISTERS FP2.
|
||
|
|
||
|
MOVE.L d2,-(a7) ...SAVE d2 TEMPORARILY
|
||
|
MOVE.L d0,d2 ...THE EXPO AND 16 BITS OF X
|
||
|
ANDI.L #$00007800,d0 ...4 VARYING BITS OF F'S FRACTION
|
||
|
ANDI.L #$7FFF0000,d2 ...EXPONENT OF F
|
||
|
SUBI.L #$3FFB0000,d2 ...K+4
|
||
|
ASR.L #1,d2
|
||
|
ADD.L d2,d0 ...THE 7 BITS IDENTIFYING F
|
||
|
ASR.L #7,d0 ...INDEX INTO TBL OF ATAN(|F|)
|
||
|
LEA ATANTBL,a1
|
||
|
ADDA.L d0,a1 ...ADDRESS OF ATAN(|F|)
|
||
|
MOVE.L (a1)+,ATANF(a6)
|
||
|
MOVE.L (a1)+,ATANFHI(a6)
|
||
|
MOVE.L (a1)+,ATANFLO(a6) ...ATANF IS NOW ATAN(|F|)
|
||
|
MOVE.L X(a6),d0 ...LOAD SIGN AND EXPO. AGAIN
|
||
|
ANDI.L #$80000000,d0 ...SIGN(F)
|
||
|
OR.L d0,ATANF(a6) ...ATANF IS NOW SIGN(F)*ATAN(|F|)
|
||
|
MOVE.L (a7)+,d2 ...RESTORE d2
|
||
|
|
||
|
*--THAT'S ALL I HAVE TO DO FOR NOW,
|
||
|
*--BUT ALAS, THE DIVIDE IS STILL CRANKING!
|
||
|
|
||
|
*--U IN FP0, WE ARE NOW READY TO COMPUTE ATAN(U) AS
|
||
|
*--U + A1*U*V*(A2 + V*(A3 + V)), V = U*U
|
||
|
*--THE POLYNOMIAL MAY LOOK STRANGE, BUT IS NEVERTHELESS CORRECT.
|
||
|
*--THE NATURAL FORM IS U + U*V*(A1 + V*(A2 + V*A3))
|
||
|
*--WHAT WE HAVE HERE IS MERELY A1 = A3, A2 = A1/A3, A3 = A2/A3.
|
||
|
*--THE REASON FOR THIS REARRANGEMENT IS TO MAKE THE INDEPENDENT
|
||
|
*--PARTS A1*U*V AND (A2 + ... STUFF) MORE LOAD-BALANCED
|
||
|
|
||
|
|
||
|
FMOVE.X FP0,FP1
|
||
|
FMUL.X FP1,FP1
|
||
|
FMOVE.D ATANA3,FP2
|
||
|
FADD.X FP1,FP2 ...A3+V
|
||
|
FMUL.X FP1,FP2 ...V*(A3+V)
|
||
|
FMUL.X FP0,FP1 ...U*V
|
||
|
FADD.D ATANA2,FP2 ...A2+V*(A3+V)
|
||
|
FMUL.D ATANA1,FP1 ...A1*U*V
|
||
|
FMUL.X FP2,FP1 ...A1*U*V*(A2+V*(A3+V))
|
||
|
|
||
|
FADD.X FP1,FP0 ...ATAN(U), FP1 RELEASED
|
||
|
FMOVE.L d1,FPCR ;restore users exceptions
|
||
|
FADD.X ATANF(a6),FP0 ...ATAN(X)
|
||
|
bra t_frcinx
|
||
|
|
||
|
ATANBORS:
|
||
|
*--|X| IS IN d0 IN COMPACT FORM. FP1, d0 SAVED.
|
||
|
*--FP0 IS X AND |X| <= 1/16 OR |X| >= 16.
|
||
|
CMPI.L #$3FFF8000,d0
|
||
|
BGT.W ATANBIG ...I.E. |X| >= 16
|
||
|
|
||
|
ATANSM:
|
||
|
*--|X| <= 1/16
|
||
|
*--IF |X| < 2^(-40), RETURN X AS ANSWER. OTHERWISE, APPROXIMATE
|
||
|
*--ATAN(X) BY X + X*Y*(B1+Y*(B2+Y*(B3+Y*(B4+Y*(B5+Y*B6)))))
|
||
|
*--WHICH IS X + X*Y*( [B1+Z*(B3+Z*B5)] + [Y*(B2+Z*(B4+Z*B6)] )
|
||
|
*--WHERE Y = X*X, AND Z = Y*Y.
|
||
|
|
||
|
CMPI.L #$3FD78000,d0
|
||
|
BLT.W ATANTINY
|
||
|
*--COMPUTE POLYNOMIAL
|
||
|
FMUL.X FP0,FP0 ...FP0 IS Y = X*X
|
||
|
|
||
|
|
||
|
MOVE.W #$0000,XDCARE(a6)
|
||
|
|
||
|
FMOVE.X FP0,FP1
|
||
|
FMUL.X FP1,FP1 ...FP1 IS Z = Y*Y
|
||
|
|
||
|
FMOVE.D ATANB6,FP2
|
||
|
FMOVE.D ATANB5,FP3
|
||
|
|
||
|
FMUL.X FP1,FP2 ...Z*B6
|
||
|
FMUL.X FP1,FP3 ...Z*B5
|
||
|
|
||
|
FADD.D ATANB4,FP2 ...B4+Z*B6
|
||
|
FADD.D ATANB3,FP3 ...B3+Z*B5
|
||
|
|
||
|
FMUL.X FP1,FP2 ...Z*(B4+Z*B6)
|
||
|
FMUL.X FP3,FP1 ...Z*(B3+Z*B5)
|
||
|
|
||
|
FADD.D ATANB2,FP2 ...B2+Z*(B4+Z*B6)
|
||
|
FADD.D ATANB1,FP1 ...B1+Z*(B3+Z*B5)
|
||
|
|
||
|
FMUL.X FP0,FP2 ...Y*(B2+Z*(B4+Z*B6))
|
||
|
FMUL.X X(a6),FP0 ...X*Y
|
||
|
|
||
|
FADD.X FP2,FP1 ...[B1+Z*(B3+Z*B5)]+[Y*(B2+Z*(B4+Z*B6))]
|
||
|
|
||
|
|
||
|
FMUL.X FP1,FP0 ...X*Y*([B1+Z*(B3+Z*B5)]+[Y*(B2+Z*(B4+Z*B6))])
|
||
|
|
||
|
FMOVE.L d1,FPCR ;restore users exceptions
|
||
|
FADD.X X(a6),FP0
|
||
|
|
||
|
bra t_frcinx
|
||
|
|
||
|
ATANTINY:
|
||
|
*--|X| < 2^(-40), ATAN(X) = X
|
||
|
MOVE.W #$0000,XDCARE(a6)
|
||
|
|
||
|
FMOVE.L d1,FPCR ;restore users exceptions
|
||
|
FMOVE.X X(a6),FP0 ;last inst - possible exception set
|
||
|
|
||
|
bra t_frcinx
|
||
|
|
||
|
ATANBIG:
|
||
|
*--IF |X| > 2^(100), RETURN SIGN(X)*(PI/2 - TINY). OTHERWISE,
|
||
|
*--RETURN SIGN(X)*PI/2 + ATAN(-1/X).
|
||
|
CMPI.L #$40638000,d0
|
||
|
BGT.W ATANHUGE
|
||
|
|
||
|
*--APPROXIMATE ATAN(-1/X) BY
|
||
|
*--X'+X'*Y*(C1+Y*(C2+Y*(C3+Y*(C4+Y*C5)))), X' = -1/X, Y = X'*X'
|
||
|
*--THIS CAN BE RE-WRITTEN AS
|
||
|
*--X'+X'*Y*( [C1+Z*(C3+Z*C5)] + [Y*(C2+Z*C4)] ), Z = Y*Y.
|
||
|
|
||
|
FMOVE.S #:BF800000,FP1 ...LOAD -1
|
||
|
FDIV.X FP0,FP1 ...FP1 IS -1/X
|
||
|
|
||
|
|
||
|
*--DIVIDE IS STILL CRANKING
|
||
|
|
||
|
FMOVE.X FP1,FP0 ...FP0 IS X'
|
||
|
FMUL.X FP0,FP0 ...FP0 IS Y = X'*X'
|
||
|
FMOVE.X FP1,X(a6) ...X IS REALLY X'
|
||
|
|
||
|
FMOVE.X FP0,FP1
|
||
|
FMUL.X FP1,FP1 ...FP1 IS Z = Y*Y
|
||
|
|
||
|
FMOVE.D ATANC5,FP3
|
||
|
FMOVE.D ATANC4,FP2
|
||
|
|
||
|
FMUL.X FP1,FP3 ...Z*C5
|
||
|
FMUL.X FP1,FP2 ...Z*B4
|
||
|
|
||
|
FADD.D ATANC3,FP3 ...C3+Z*C5
|
||
|
FADD.D ATANC2,FP2 ...C2+Z*C4
|
||
|
|
||
|
FMUL.X FP3,FP1 ...Z*(C3+Z*C5), FP3 RELEASED
|
||
|
FMUL.X FP0,FP2 ...Y*(C2+Z*C4)
|
||
|
|
||
|
FADD.D ATANC1,FP1 ...C1+Z*(C3+Z*C5)
|
||
|
FMUL.X X(a6),FP0 ...X'*Y
|
||
|
|
||
|
FADD.X FP2,FP1 ...[Y*(C2+Z*C4)]+[C1+Z*(C3+Z*C5)]
|
||
|
|
||
|
|
||
|
FMUL.X FP1,FP0 ...X'*Y*([B1+Z*(B3+Z*B5)]
|
||
|
* ... +[Y*(B2+Z*(B4+Z*B6))])
|
||
|
FADD.X X(a6),FP0
|
||
|
|
||
|
FMOVE.L d1,FPCR ;restore users exceptions
|
||
|
|
||
|
btst.b #7,(a0)
|
||
|
beq.b pos_big
|
||
|
|
||
|
neg_big:
|
||
|
FADD.X NPIBY2,FP0
|
||
|
bra t_frcinx
|
||
|
|
||
|
pos_big:
|
||
|
FADD.X PPIBY2,FP0
|
||
|
bra t_frcinx
|
||
|
|
||
|
ATANHUGE:
|
||
|
*--RETURN SIGN(X)*(PIBY2 - TINY) = SIGN(X)*PIBY2 - SIGN(X)*TINY
|
||
|
btst.b #7,(a0)
|
||
|
beq.b pos_huge
|
||
|
|
||
|
neg_huge:
|
||
|
FMOVE.X NPIBY2,fp0
|
||
|
fmove.l d1,fpcr
|
||
|
fsub.x NTINY,fp0
|
||
|
bra t_frcinx
|
||
|
|
||
|
pos_huge:
|
||
|
FMOVE.X PPIBY2,fp0
|
||
|
fmove.l d1,fpcr
|
||
|
fsub.x PTINY,fp0
|
||
|
bra t_frcinx
|
||
|
|
||
|
end
|