162306a36Sopenharmony_ci|
262306a36Sopenharmony_ci|	slogn.sa 3.1 12/10/90
362306a36Sopenharmony_ci|
462306a36Sopenharmony_ci|	slogn computes the natural logarithm of an
562306a36Sopenharmony_ci|	input value. slognd does the same except the input value is a
662306a36Sopenharmony_ci|	denormalized number. slognp1 computes log(1+X), and slognp1d
762306a36Sopenharmony_ci|	computes log(1+X) for denormalized X.
862306a36Sopenharmony_ci|
962306a36Sopenharmony_ci|	Input: Double-extended value in memory location pointed to by address
1062306a36Sopenharmony_ci|		register a0.
1162306a36Sopenharmony_ci|
1262306a36Sopenharmony_ci|	Output:	log(X) or log(1+X) returned in floating-point register Fp0.
1362306a36Sopenharmony_ci|
1462306a36Sopenharmony_ci|	Accuracy and Monotonicity: The returned result is within 2 ulps in
1562306a36Sopenharmony_ci|		64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
1662306a36Sopenharmony_ci|		result is subsequently rounded to double precision. The
1762306a36Sopenharmony_ci|		result is provably monotonic in double precision.
1862306a36Sopenharmony_ci|
1962306a36Sopenharmony_ci|	Speed: The program slogn takes approximately 190 cycles for input
2062306a36Sopenharmony_ci|		argument X such that |X-1| >= 1/16, which is the usual
2162306a36Sopenharmony_ci|		situation. For those arguments, slognp1 takes approximately
2262306a36Sopenharmony_ci|		 210 cycles. For the less common arguments, the program will
2362306a36Sopenharmony_ci|		 run no worse than 10% slower.
2462306a36Sopenharmony_ci|
2562306a36Sopenharmony_ci|	Algorithm:
2662306a36Sopenharmony_ci|	LOGN:
2762306a36Sopenharmony_ci|	Step 1. If |X-1| < 1/16, approximate log(X) by an odd polynomial in
2862306a36Sopenharmony_ci|		u, where u = 2(X-1)/(X+1). Otherwise, move on to Step 2.
2962306a36Sopenharmony_ci|
3062306a36Sopenharmony_ci|	Step 2. X = 2**k * Y where 1 <= Y < 2. Define F to be the first seven
3162306a36Sopenharmony_ci|		significant bits of Y plus 2**(-7), i.e. F = 1.xxxxxx1 in base
3262306a36Sopenharmony_ci|		2 where the six "x" match those of Y. Note that |Y-F| <= 2**(-7).
3362306a36Sopenharmony_ci|
3462306a36Sopenharmony_ci|	Step 3. Define u = (Y-F)/F. Approximate log(1+u) by a polynomial in u,
3562306a36Sopenharmony_ci|		log(1+u) = poly.
3662306a36Sopenharmony_ci|
3762306a36Sopenharmony_ci|	Step 4. Reconstruct log(X) = log( 2**k * Y ) = k*log(2) + log(F) + log(1+u)
3862306a36Sopenharmony_ci|		by k*log(2) + (log(F) + poly). The values of log(F) are calculated
3962306a36Sopenharmony_ci|		beforehand and stored in the program.
4062306a36Sopenharmony_ci|
4162306a36Sopenharmony_ci|	lognp1:
4262306a36Sopenharmony_ci|	Step 1: If |X| < 1/16, approximate log(1+X) by an odd polynomial in
4362306a36Sopenharmony_ci|		u where u = 2X/(2+X). Otherwise, move on to Step 2.
4462306a36Sopenharmony_ci|
4562306a36Sopenharmony_ci|	Step 2: Let 1+X = 2**k * Y, where 1 <= Y < 2. Define F as done in Step 2
4662306a36Sopenharmony_ci|		of the algorithm for LOGN and compute log(1+X) as
4762306a36Sopenharmony_ci|		k*log(2) + log(F) + poly where poly approximates log(1+u),
4862306a36Sopenharmony_ci|		u = (Y-F)/F.
4962306a36Sopenharmony_ci|
5062306a36Sopenharmony_ci|	Implementation Notes:
5162306a36Sopenharmony_ci|	Note 1. There are 64 different possible values for F, thus 64 log(F)'s
5262306a36Sopenharmony_ci|		need to be tabulated. Moreover, the values of 1/F are also
5362306a36Sopenharmony_ci|		tabulated so that the division in (Y-F)/F can be performed by a
5462306a36Sopenharmony_ci|		multiplication.
5562306a36Sopenharmony_ci|
5662306a36Sopenharmony_ci|	Note 2. In Step 2 of lognp1, in order to preserved accuracy, the value
5762306a36Sopenharmony_ci|		Y-F has to be calculated carefully when 1/2 <= X < 3/2.
5862306a36Sopenharmony_ci|
5962306a36Sopenharmony_ci|	Note 3. To fully exploit the pipeline, polynomials are usually separated
6062306a36Sopenharmony_ci|		into two parts evaluated independently before being added up.
6162306a36Sopenharmony_ci|
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci|		Copyright (C) Motorola, Inc. 1990
6462306a36Sopenharmony_ci|			All Rights Reserved
6562306a36Sopenharmony_ci|
6662306a36Sopenharmony_ci|       For details on the license for this file, please see the
6762306a36Sopenharmony_ci|       file, README, in this same directory.
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci|slogn	idnt	2,1 | Motorola 040 Floating Point Software Package
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	|section	8
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#include "fpsp.h"
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ciBOUNDS1:  .long 0x3FFEF07D,0x3FFF8841
7662306a36Sopenharmony_ciBOUNDS2:  .long 0x3FFE8000,0x3FFFC000
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ciLOGOF2:	.long 0x3FFE0000,0xB17217F7,0xD1CF79AC,0x00000000
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_cione:	.long 0x3F800000
8162306a36Sopenharmony_cizero:	.long 0x00000000
8262306a36Sopenharmony_ciinfty:	.long 0x7F800000
8362306a36Sopenharmony_cinegone:	.long 0xBF800000
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciLOGA6:	.long 0x3FC2499A,0xB5E4040B
8662306a36Sopenharmony_ciLOGA5:	.long 0xBFC555B5,0x848CB7DB
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ciLOGA4:	.long 0x3FC99999,0x987D8730
8962306a36Sopenharmony_ciLOGA3:	.long 0xBFCFFFFF,0xFF6F7E97
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ciLOGA2:	.long 0x3FD55555,0x555555a4
9262306a36Sopenharmony_ciLOGA1:	.long 0xBFE00000,0x00000008
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ciLOGB5:	.long 0x3F175496,0xADD7DAD6
9562306a36Sopenharmony_ciLOGB4:	.long 0x3F3C71C2,0xFE80C7E0
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciLOGB3:	.long 0x3F624924,0x928BCCFF
9862306a36Sopenharmony_ciLOGB2:	.long 0x3F899999,0x999995EC
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ciLOGB1:	.long 0x3FB55555,0x55555555
10162306a36Sopenharmony_ciTWO:	.long 0x40000000,0x00000000
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ciLTHOLD:	.long 0x3f990000,0x80000000,0x00000000,0x00000000
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ciLOGTBL:
10662306a36Sopenharmony_ci	.long  0x3FFE0000,0xFE03F80F,0xE03F80FE,0x00000000
10762306a36Sopenharmony_ci	.long  0x3FF70000,0xFF015358,0x833C47E2,0x00000000
10862306a36Sopenharmony_ci	.long  0x3FFE0000,0xFA232CF2,0x52138AC0,0x00000000
10962306a36Sopenharmony_ci	.long  0x3FF90000,0xBDC8D83E,0xAD88D549,0x00000000
11062306a36Sopenharmony_ci	.long  0x3FFE0000,0xF6603D98,0x0F6603DA,0x00000000
11162306a36Sopenharmony_ci	.long  0x3FFA0000,0x9CF43DCF,0xF5EAFD48,0x00000000
11262306a36Sopenharmony_ci	.long  0x3FFE0000,0xF2B9D648,0x0F2B9D65,0x00000000
11362306a36Sopenharmony_ci	.long  0x3FFA0000,0xDA16EB88,0xCB8DF614,0x00000000
11462306a36Sopenharmony_ci	.long  0x3FFE0000,0xEF2EB71F,0xC4345238,0x00000000
11562306a36Sopenharmony_ci	.long  0x3FFB0000,0x8B29B775,0x1BD70743,0x00000000
11662306a36Sopenharmony_ci	.long  0x3FFE0000,0xEBBDB2A5,0xC1619C8C,0x00000000
11762306a36Sopenharmony_ci	.long  0x3FFB0000,0xA8D839F8,0x30C1FB49,0x00000000
11862306a36Sopenharmony_ci	.long  0x3FFE0000,0xE865AC7B,0x7603A197,0x00000000
11962306a36Sopenharmony_ci	.long  0x3FFB0000,0xC61A2EB1,0x8CD907AD,0x00000000
12062306a36Sopenharmony_ci	.long  0x3FFE0000,0xE525982A,0xF70C880E,0x00000000
12162306a36Sopenharmony_ci	.long  0x3FFB0000,0xE2F2A47A,0xDE3A18AF,0x00000000
12262306a36Sopenharmony_ci	.long  0x3FFE0000,0xE1FC780E,0x1FC780E2,0x00000000
12362306a36Sopenharmony_ci	.long  0x3FFB0000,0xFF64898E,0xDF55D551,0x00000000
12462306a36Sopenharmony_ci	.long  0x3FFE0000,0xDEE95C4C,0xA037BA57,0x00000000
12562306a36Sopenharmony_ci	.long  0x3FFC0000,0x8DB956A9,0x7B3D0148,0x00000000
12662306a36Sopenharmony_ci	.long  0x3FFE0000,0xDBEB61EE,0xD19C5958,0x00000000
12762306a36Sopenharmony_ci	.long  0x3FFC0000,0x9B8FE100,0xF47BA1DE,0x00000000
12862306a36Sopenharmony_ci	.long  0x3FFE0000,0xD901B203,0x6406C80E,0x00000000
12962306a36Sopenharmony_ci	.long  0x3FFC0000,0xA9372F1D,0x0DA1BD17,0x00000000
13062306a36Sopenharmony_ci	.long  0x3FFE0000,0xD62B80D6,0x2B80D62C,0x00000000
13162306a36Sopenharmony_ci	.long  0x3FFC0000,0xB6B07F38,0xCE90E46B,0x00000000
13262306a36Sopenharmony_ci	.long  0x3FFE0000,0xD3680D36,0x80D3680D,0x00000000
13362306a36Sopenharmony_ci	.long  0x3FFC0000,0xC3FD0329,0x06488481,0x00000000
13462306a36Sopenharmony_ci	.long  0x3FFE0000,0xD0B69FCB,0xD2580D0B,0x00000000
13562306a36Sopenharmony_ci	.long  0x3FFC0000,0xD11DE0FF,0x15AB18CA,0x00000000
13662306a36Sopenharmony_ci	.long  0x3FFE0000,0xCE168A77,0x25080CE1,0x00000000
13762306a36Sopenharmony_ci	.long  0x3FFC0000,0xDE1433A1,0x6C66B150,0x00000000
13862306a36Sopenharmony_ci	.long  0x3FFE0000,0xCB8727C0,0x65C393E0,0x00000000
13962306a36Sopenharmony_ci	.long  0x3FFC0000,0xEAE10B5A,0x7DDC8ADD,0x00000000
14062306a36Sopenharmony_ci	.long  0x3FFE0000,0xC907DA4E,0x871146AD,0x00000000
14162306a36Sopenharmony_ci	.long  0x3FFC0000,0xF7856E5E,0xE2C9B291,0x00000000
14262306a36Sopenharmony_ci	.long  0x3FFE0000,0xC6980C69,0x80C6980C,0x00000000
14362306a36Sopenharmony_ci	.long  0x3FFD0000,0x82012CA5,0xA68206D7,0x00000000
14462306a36Sopenharmony_ci	.long  0x3FFE0000,0xC4372F85,0x5D824CA6,0x00000000
14562306a36Sopenharmony_ci	.long  0x3FFD0000,0x882C5FCD,0x7256A8C5,0x00000000
14662306a36Sopenharmony_ci	.long  0x3FFE0000,0xC1E4BBD5,0x95F6E947,0x00000000
14762306a36Sopenharmony_ci	.long  0x3FFD0000,0x8E44C60B,0x4CCFD7DE,0x00000000
14862306a36Sopenharmony_ci	.long  0x3FFE0000,0xBFA02FE8,0x0BFA02FF,0x00000000
14962306a36Sopenharmony_ci	.long  0x3FFD0000,0x944AD09E,0xF4351AF6,0x00000000
15062306a36Sopenharmony_ci	.long  0x3FFE0000,0xBD691047,0x07661AA3,0x00000000
15162306a36Sopenharmony_ci	.long  0x3FFD0000,0x9A3EECD4,0xC3EAA6B2,0x00000000
15262306a36Sopenharmony_ci	.long  0x3FFE0000,0xBB3EE721,0xA54D880C,0x00000000
15362306a36Sopenharmony_ci	.long  0x3FFD0000,0xA0218434,0x353F1DE8,0x00000000
15462306a36Sopenharmony_ci	.long  0x3FFE0000,0xB92143FA,0x36F5E02E,0x00000000
15562306a36Sopenharmony_ci	.long  0x3FFD0000,0xA5F2FCAB,0xBBC506DA,0x00000000
15662306a36Sopenharmony_ci	.long  0x3FFE0000,0xB70FBB5A,0x19BE3659,0x00000000
15762306a36Sopenharmony_ci	.long  0x3FFD0000,0xABB3B8BA,0x2AD362A5,0x00000000
15862306a36Sopenharmony_ci	.long  0x3FFE0000,0xB509E68A,0x9B94821F,0x00000000
15962306a36Sopenharmony_ci	.long  0x3FFD0000,0xB1641795,0xCE3CA97B,0x00000000
16062306a36Sopenharmony_ci	.long  0x3FFE0000,0xB30F6352,0x8917C80B,0x00000000
16162306a36Sopenharmony_ci	.long  0x3FFD0000,0xB7047551,0x5D0F1C61,0x00000000
16262306a36Sopenharmony_ci	.long  0x3FFE0000,0xB11FD3B8,0x0B11FD3C,0x00000000
16362306a36Sopenharmony_ci	.long  0x3FFD0000,0xBC952AFE,0xEA3D13E1,0x00000000
16462306a36Sopenharmony_ci	.long  0x3FFE0000,0xAF3ADDC6,0x80AF3ADE,0x00000000
16562306a36Sopenharmony_ci	.long  0x3FFD0000,0xC2168ED0,0xF458BA4A,0x00000000
16662306a36Sopenharmony_ci	.long  0x3FFE0000,0xAD602B58,0x0AD602B6,0x00000000
16762306a36Sopenharmony_ci	.long  0x3FFD0000,0xC788F439,0xB3163BF1,0x00000000
16862306a36Sopenharmony_ci	.long  0x3FFE0000,0xAB8F69E2,0x8359CD11,0x00000000
16962306a36Sopenharmony_ci	.long  0x3FFD0000,0xCCECAC08,0xBF04565D,0x00000000
17062306a36Sopenharmony_ci	.long  0x3FFE0000,0xA9C84A47,0xA07F5638,0x00000000
17162306a36Sopenharmony_ci	.long  0x3FFD0000,0xD2420487,0x2DD85160,0x00000000
17262306a36Sopenharmony_ci	.long  0x3FFE0000,0xA80A80A8,0x0A80A80B,0x00000000
17362306a36Sopenharmony_ci	.long  0x3FFD0000,0xD7894992,0x3BC3588A,0x00000000
17462306a36Sopenharmony_ci	.long  0x3FFE0000,0xA655C439,0x2D7B73A8,0x00000000
17562306a36Sopenharmony_ci	.long  0x3FFD0000,0xDCC2C4B4,0x9887DACC,0x00000000
17662306a36Sopenharmony_ci	.long  0x3FFE0000,0xA4A9CF1D,0x96833751,0x00000000
17762306a36Sopenharmony_ci	.long  0x3FFD0000,0xE1EEBD3E,0x6D6A6B9E,0x00000000
17862306a36Sopenharmony_ci	.long  0x3FFE0000,0xA3065E3F,0xAE7CD0E0,0x00000000
17962306a36Sopenharmony_ci	.long  0x3FFD0000,0xE70D785C,0x2F9F5BDC,0x00000000
18062306a36Sopenharmony_ci	.long  0x3FFE0000,0xA16B312E,0xA8FC377D,0x00000000
18162306a36Sopenharmony_ci	.long  0x3FFD0000,0xEC1F392C,0x5179F283,0x00000000
18262306a36Sopenharmony_ci	.long  0x3FFE0000,0x9FD809FD,0x809FD80A,0x00000000
18362306a36Sopenharmony_ci	.long  0x3FFD0000,0xF12440D3,0xE36130E6,0x00000000
18462306a36Sopenharmony_ci	.long  0x3FFE0000,0x9E4CAD23,0xDD5F3A20,0x00000000
18562306a36Sopenharmony_ci	.long  0x3FFD0000,0xF61CCE92,0x346600BB,0x00000000
18662306a36Sopenharmony_ci	.long  0x3FFE0000,0x9CC8E160,0xC3FB19B9,0x00000000
18762306a36Sopenharmony_ci	.long  0x3FFD0000,0xFB091FD3,0x8145630A,0x00000000
18862306a36Sopenharmony_ci	.long  0x3FFE0000,0x9B4C6F9E,0xF03A3CAA,0x00000000
18962306a36Sopenharmony_ci	.long  0x3FFD0000,0xFFE97042,0xBFA4C2AD,0x00000000
19062306a36Sopenharmony_ci	.long  0x3FFE0000,0x99D722DA,0xBDE58F06,0x00000000
19162306a36Sopenharmony_ci	.long  0x3FFE0000,0x825EFCED,0x49369330,0x00000000
19262306a36Sopenharmony_ci	.long  0x3FFE0000,0x9868C809,0x868C8098,0x00000000
19362306a36Sopenharmony_ci	.long  0x3FFE0000,0x84C37A7A,0xB9A905C9,0x00000000
19462306a36Sopenharmony_ci	.long  0x3FFE0000,0x97012E02,0x5C04B809,0x00000000
19562306a36Sopenharmony_ci	.long  0x3FFE0000,0x87224C2E,0x8E645FB7,0x00000000
19662306a36Sopenharmony_ci	.long  0x3FFE0000,0x95A02568,0x095A0257,0x00000000
19762306a36Sopenharmony_ci	.long  0x3FFE0000,0x897B8CAC,0x9F7DE298,0x00000000
19862306a36Sopenharmony_ci	.long  0x3FFE0000,0x94458094,0x45809446,0x00000000
19962306a36Sopenharmony_ci	.long  0x3FFE0000,0x8BCF55DE,0xC4CD05FE,0x00000000
20062306a36Sopenharmony_ci	.long  0x3FFE0000,0x92F11384,0x0497889C,0x00000000
20162306a36Sopenharmony_ci	.long  0x3FFE0000,0x8E1DC0FB,0x89E125E5,0x00000000
20262306a36Sopenharmony_ci	.long  0x3FFE0000,0x91A2B3C4,0xD5E6F809,0x00000000
20362306a36Sopenharmony_ci	.long  0x3FFE0000,0x9066E68C,0x955B6C9B,0x00000000
20462306a36Sopenharmony_ci	.long  0x3FFE0000,0x905A3863,0x3E06C43B,0x00000000
20562306a36Sopenharmony_ci	.long  0x3FFE0000,0x92AADE74,0xC7BE59E0,0x00000000
20662306a36Sopenharmony_ci	.long  0x3FFE0000,0x8F1779D9,0xFDC3A219,0x00000000
20762306a36Sopenharmony_ci	.long  0x3FFE0000,0x94E9BFF6,0x15845643,0x00000000
20862306a36Sopenharmony_ci	.long  0x3FFE0000,0x8DDA5202,0x37694809,0x00000000
20962306a36Sopenharmony_ci	.long  0x3FFE0000,0x9723A1B7,0x20134203,0x00000000
21062306a36Sopenharmony_ci	.long  0x3FFE0000,0x8CA29C04,0x6514E023,0x00000000
21162306a36Sopenharmony_ci	.long  0x3FFE0000,0x995899C8,0x90EB8990,0x00000000
21262306a36Sopenharmony_ci	.long  0x3FFE0000,0x8B70344A,0x139BC75A,0x00000000
21362306a36Sopenharmony_ci	.long  0x3FFE0000,0x9B88BDAA,0x3A3DAE2F,0x00000000
21462306a36Sopenharmony_ci	.long  0x3FFE0000,0x8A42F870,0x5669DB46,0x00000000
21562306a36Sopenharmony_ci	.long  0x3FFE0000,0x9DB4224F,0xFFE1157C,0x00000000
21662306a36Sopenharmony_ci	.long  0x3FFE0000,0x891AC73A,0xE9819B50,0x00000000
21762306a36Sopenharmony_ci	.long  0x3FFE0000,0x9FDADC26,0x8B7A12DA,0x00000000
21862306a36Sopenharmony_ci	.long  0x3FFE0000,0x87F78087,0xF78087F8,0x00000000
21962306a36Sopenharmony_ci	.long  0x3FFE0000,0xA1FCFF17,0xCE733BD4,0x00000000
22062306a36Sopenharmony_ci	.long  0x3FFE0000,0x86D90544,0x7A34ACC6,0x00000000
22162306a36Sopenharmony_ci	.long  0x3FFE0000,0xA41A9E8F,0x5446FB9F,0x00000000
22262306a36Sopenharmony_ci	.long  0x3FFE0000,0x85BF3761,0x2CEE3C9B,0x00000000
22362306a36Sopenharmony_ci	.long  0x3FFE0000,0xA633CD7E,0x6771CD8B,0x00000000
22462306a36Sopenharmony_ci	.long  0x3FFE0000,0x84A9F9C8,0x084A9F9D,0x00000000
22562306a36Sopenharmony_ci	.long  0x3FFE0000,0xA8489E60,0x0B435A5E,0x00000000
22662306a36Sopenharmony_ci	.long  0x3FFE0000,0x83993052,0x3FBE3368,0x00000000
22762306a36Sopenharmony_ci	.long  0x3FFE0000,0xAA59233C,0xCCA4BD49,0x00000000
22862306a36Sopenharmony_ci	.long  0x3FFE0000,0x828CBFBE,0xB9A020A3,0x00000000
22962306a36Sopenharmony_ci	.long  0x3FFE0000,0xAC656DAE,0x6BCC4985,0x00000000
23062306a36Sopenharmony_ci	.long  0x3FFE0000,0x81848DA8,0xFAF0D277,0x00000000
23162306a36Sopenharmony_ci	.long  0x3FFE0000,0xAE6D8EE3,0x60BB2468,0x00000000
23262306a36Sopenharmony_ci	.long  0x3FFE0000,0x80808080,0x80808081,0x00000000
23362306a36Sopenharmony_ci	.long  0x3FFE0000,0xB07197A2,0x3C46C654,0x00000000
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci	.set	ADJK,L_SCR1
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci	.set	X,FP_SCR1
23862306a36Sopenharmony_ci	.set	XDCARE,X+2
23962306a36Sopenharmony_ci	.set	XFRAC,X+4
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci	.set	F,FP_SCR2
24262306a36Sopenharmony_ci	.set	FFRAC,F+4
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci	.set	KLOG2,FP_SCR3
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci	.set	SAVEU,FP_SCR4
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci	| xref	t_frcinx
24962306a36Sopenharmony_ci	|xref	t_extdnrm
25062306a36Sopenharmony_ci	|xref	t_operr
25162306a36Sopenharmony_ci	|xref	t_dz
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci	.global	slognd
25462306a36Sopenharmony_cislognd:
25562306a36Sopenharmony_ci|--ENTRY POINT FOR LOG(X) FOR DENORMALIZED INPUT
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci	movel		#-100,ADJK(%a6)	| ...INPUT = 2^(ADJK) * FP0
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci|----normalize the input value by left shifting k bits (k to be determined
26062306a36Sopenharmony_ci|----below), adjusting exponent and storing -k to  ADJK
26162306a36Sopenharmony_ci|----the value TWOTO100 is no longer needed.
26262306a36Sopenharmony_ci|----Note that this code assumes the denormalized input is NON-ZERO.
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci     moveml	%d2-%d7,-(%a7)		| ...save some registers
26562306a36Sopenharmony_ci     movel	#0x00000000,%d3		| ...D3 is exponent of smallest norm. #
26662306a36Sopenharmony_ci     movel	4(%a0),%d4
26762306a36Sopenharmony_ci     movel	8(%a0),%d5		| ...(D4,D5) is (Hi_X,Lo_X)
26862306a36Sopenharmony_ci     clrl	%d2			| ...D2 used for holding K
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci     tstl	%d4
27162306a36Sopenharmony_ci     bnes	HiX_not0
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ciHiX_0:
27462306a36Sopenharmony_ci     movel	%d5,%d4
27562306a36Sopenharmony_ci     clrl	%d5
27662306a36Sopenharmony_ci     movel	#32,%d2
27762306a36Sopenharmony_ci     clrl	%d6
27862306a36Sopenharmony_ci     bfffo      %d4{#0:#32},%d6
27962306a36Sopenharmony_ci     lsll      %d6,%d4
28062306a36Sopenharmony_ci     addl	%d6,%d2			| ...(D3,D4,D5) is normalized
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci     movel	%d3,X(%a6)
28362306a36Sopenharmony_ci     movel	%d4,XFRAC(%a6)
28462306a36Sopenharmony_ci     movel	%d5,XFRAC+4(%a6)
28562306a36Sopenharmony_ci     negl	%d2
28662306a36Sopenharmony_ci     movel	%d2,ADJK(%a6)
28762306a36Sopenharmony_ci     fmovex	X(%a6),%fp0
28862306a36Sopenharmony_ci     moveml	(%a7)+,%d2-%d7		| ...restore registers
28962306a36Sopenharmony_ci     lea	X(%a6),%a0
29062306a36Sopenharmony_ci     bras	LOGBGN			| ...begin regular log(X)
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ciHiX_not0:
29462306a36Sopenharmony_ci     clrl	%d6
29562306a36Sopenharmony_ci     bfffo	%d4{#0:#32},%d6		| ...find first 1
29662306a36Sopenharmony_ci     movel	%d6,%d2			| ...get k
29762306a36Sopenharmony_ci     lsll	%d6,%d4
29862306a36Sopenharmony_ci     movel	%d5,%d7			| ...a copy of D5
29962306a36Sopenharmony_ci     lsll	%d6,%d5
30062306a36Sopenharmony_ci     negl	%d6
30162306a36Sopenharmony_ci     addil	#32,%d6
30262306a36Sopenharmony_ci     lsrl	%d6,%d7
30362306a36Sopenharmony_ci     orl	%d7,%d4			| ...(D3,D4,D5) normalized
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci     movel	%d3,X(%a6)
30662306a36Sopenharmony_ci     movel	%d4,XFRAC(%a6)
30762306a36Sopenharmony_ci     movel	%d5,XFRAC+4(%a6)
30862306a36Sopenharmony_ci     negl	%d2
30962306a36Sopenharmony_ci     movel	%d2,ADJK(%a6)
31062306a36Sopenharmony_ci     fmovex	X(%a6),%fp0
31162306a36Sopenharmony_ci     moveml	(%a7)+,%d2-%d7		| ...restore registers
31262306a36Sopenharmony_ci     lea	X(%a6),%a0
31362306a36Sopenharmony_ci     bras	LOGBGN			| ...begin regular log(X)
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci	.global	slogn
31762306a36Sopenharmony_cislogn:
31862306a36Sopenharmony_ci|--ENTRY POINT FOR LOG(X) FOR X FINITE, NON-ZERO, NOT NAN'S
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci	fmovex		(%a0),%fp0	| ...LOAD INPUT
32162306a36Sopenharmony_ci	movel		#0x00000000,ADJK(%a6)
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ciLOGBGN:
32462306a36Sopenharmony_ci|--FPCR SAVED AND CLEARED, INPUT IS 2^(ADJK)*FP0, FP0 CONTAINS
32562306a36Sopenharmony_ci|--A FINITE, NON-ZERO, NORMALIZED NUMBER.
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci	movel	(%a0),%d0
32862306a36Sopenharmony_ci	movew	4(%a0),%d0
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci	movel	(%a0),X(%a6)
33162306a36Sopenharmony_ci	movel	4(%a0),X+4(%a6)
33262306a36Sopenharmony_ci	movel	8(%a0),X+8(%a6)
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci	cmpil	#0,%d0		| ...CHECK IF X IS NEGATIVE
33562306a36Sopenharmony_ci	blt	LOGNEG		| ...LOG OF NEGATIVE ARGUMENT IS INVALID
33662306a36Sopenharmony_ci	cmp2l	BOUNDS1,%d0	| ...X IS POSITIVE, CHECK IF X IS NEAR 1
33762306a36Sopenharmony_ci	bcc	LOGNEAR1	| ...BOUNDS IS ROUGHLY [15/16, 17/16]
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ciLOGMAIN:
34062306a36Sopenharmony_ci|--THIS SHOULD BE THE USUAL CASE, X NOT VERY CLOSE TO 1
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci|--X = 2^(K) * Y, 1 <= Y < 2. THUS, Y = 1.XXXXXXXX....XX IN BINARY.
34362306a36Sopenharmony_ci|--WE DEFINE F = 1.XXXXXX1, I.E. FIRST 7 BITS OF Y AND ATTACH A 1.
34462306a36Sopenharmony_ci|--THE IDEA IS THAT LOG(X) = K*LOG2 + LOG(Y)
34562306a36Sopenharmony_ci|--			 = K*LOG2 + LOG(F) + LOG(1 + (Y-F)/F).
34662306a36Sopenharmony_ci|--NOTE THAT U = (Y-F)/F IS VERY SMALL AND THUS APPROXIMATING
34762306a36Sopenharmony_ci|--LOG(1+U) CAN BE VERY EFFICIENT.
34862306a36Sopenharmony_ci|--ALSO NOTE THAT THE VALUE 1/F IS STORED IN A TABLE SO THAT NO
34962306a36Sopenharmony_ci|--DIVISION IS NEEDED TO CALCULATE (Y-F)/F.
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci|--GET K, Y, F, AND ADDRESS OF 1/F.
35262306a36Sopenharmony_ci	asrl	#8,%d0
35362306a36Sopenharmony_ci	asrl	#8,%d0		| ...SHIFTED 16 BITS, BIASED EXPO. OF X
35462306a36Sopenharmony_ci	subil	#0x3FFF,%d0	| ...THIS IS K
35562306a36Sopenharmony_ci	addl	ADJK(%a6),%d0	| ...ADJUST K, ORIGINAL INPUT MAY BE  DENORM.
35662306a36Sopenharmony_ci	lea	LOGTBL,%a0	| ...BASE ADDRESS OF 1/F AND LOG(F)
35762306a36Sopenharmony_ci	fmovel	%d0,%fp1		| ...CONVERT K TO FLOATING-POINT FORMAT
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci|--WHILE THE CONVERSION IS GOING ON, WE GET F AND ADDRESS OF 1/F
36062306a36Sopenharmony_ci	movel	#0x3FFF0000,X(%a6)	| ...X IS NOW Y, I.E. 2^(-K)*X
36162306a36Sopenharmony_ci	movel	XFRAC(%a6),FFRAC(%a6)
36262306a36Sopenharmony_ci	andil	#0xFE000000,FFRAC(%a6) | ...FIRST 7 BITS OF Y
36362306a36Sopenharmony_ci	oril	#0x01000000,FFRAC(%a6) | ...GET F: ATTACH A 1 AT THE EIGHTH BIT
36462306a36Sopenharmony_ci	movel	FFRAC(%a6),%d0	| ...READY TO GET ADDRESS OF 1/F
36562306a36Sopenharmony_ci	andil	#0x7E000000,%d0
36662306a36Sopenharmony_ci	asrl	#8,%d0
36762306a36Sopenharmony_ci	asrl	#8,%d0
36862306a36Sopenharmony_ci	asrl	#4,%d0		| ...SHIFTED 20, D0 IS THE DISPLACEMENT
36962306a36Sopenharmony_ci	addal	%d0,%a0		| ...A0 IS THE ADDRESS FOR 1/F
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci	fmovex	X(%a6),%fp0
37262306a36Sopenharmony_ci	movel	#0x3fff0000,F(%a6)
37362306a36Sopenharmony_ci	clrl	F+8(%a6)
37462306a36Sopenharmony_ci	fsubx	F(%a6),%fp0		| ...Y-F
37562306a36Sopenharmony_ci	fmovemx %fp2-%fp2/%fp3,-(%sp)	| ...SAVE FP2 WHILE FP0 IS NOT READY
37662306a36Sopenharmony_ci|--SUMMARY: FP0 IS Y-F, A0 IS ADDRESS OF 1/F, FP1 IS K
37762306a36Sopenharmony_ci|--REGISTERS SAVED: FPCR, FP1, FP2
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ciLP1CONT1:
38062306a36Sopenharmony_ci|--AN RE-ENTRY POINT FOR LOGNP1
38162306a36Sopenharmony_ci	fmulx	(%a0),%fp0	| ...FP0 IS U = (Y-F)/F
38262306a36Sopenharmony_ci	fmulx	LOGOF2,%fp1	| ...GET K*LOG2 WHILE FP0 IS NOT READY
38362306a36Sopenharmony_ci	fmovex	%fp0,%fp2
38462306a36Sopenharmony_ci	fmulx	%fp2,%fp2		| ...FP2 IS V=U*U
38562306a36Sopenharmony_ci	fmovex	%fp1,KLOG2(%a6)	| ...PUT K*LOG2 IN MEMORY, FREE FP1
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci|--LOG(1+U) IS APPROXIMATED BY
38862306a36Sopenharmony_ci|--U + V*(A1+U*(A2+U*(A3+U*(A4+U*(A5+U*A6))))) WHICH IS
38962306a36Sopenharmony_ci|--[U + V*(A1+V*(A3+V*A5))]  +  [U*V*(A2+V*(A4+V*A6))]
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci	fmovex	%fp2,%fp3
39262306a36Sopenharmony_ci	fmovex	%fp2,%fp1
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci	fmuld	LOGA6,%fp1	| ...V*A6
39562306a36Sopenharmony_ci	fmuld	LOGA5,%fp2	| ...V*A5
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_ci	faddd	LOGA4,%fp1	| ...A4+V*A6
39862306a36Sopenharmony_ci	faddd	LOGA3,%fp2	| ...A3+V*A5
39962306a36Sopenharmony_ci
40062306a36Sopenharmony_ci	fmulx	%fp3,%fp1		| ...V*(A4+V*A6)
40162306a36Sopenharmony_ci	fmulx	%fp3,%fp2		| ...V*(A3+V*A5)
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci	faddd	LOGA2,%fp1	| ...A2+V*(A4+V*A6)
40462306a36Sopenharmony_ci	faddd	LOGA1,%fp2	| ...A1+V*(A3+V*A5)
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci	fmulx	%fp3,%fp1		| ...V*(A2+V*(A4+V*A6))
40762306a36Sopenharmony_ci	addal	#16,%a0		| ...ADDRESS OF LOG(F)
40862306a36Sopenharmony_ci	fmulx	%fp3,%fp2		| ...V*(A1+V*(A3+V*A5)), FP3 RELEASED
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci	fmulx	%fp0,%fp1		| ...U*V*(A2+V*(A4+V*A6))
41162306a36Sopenharmony_ci	faddx	%fp2,%fp0		| ...U+V*(A1+V*(A3+V*A5)), FP2 RELEASED
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_ci	faddx	(%a0),%fp1	| ...LOG(F)+U*V*(A2+V*(A4+V*A6))
41462306a36Sopenharmony_ci	fmovemx  (%sp)+,%fp2-%fp2/%fp3	| ...RESTORE FP2
41562306a36Sopenharmony_ci	faddx	%fp1,%fp0		| ...FP0 IS LOG(F) + LOG(1+U)
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci	fmovel	%d1,%fpcr
41862306a36Sopenharmony_ci	faddx	KLOG2(%a6),%fp0	| ...FINAL ADD
41962306a36Sopenharmony_ci	bra	t_frcinx
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ciLOGNEAR1:
42362306a36Sopenharmony_ci|--REGISTERS SAVED: FPCR, FP1. FP0 CONTAINS THE INPUT.
42462306a36Sopenharmony_ci	fmovex	%fp0,%fp1
42562306a36Sopenharmony_ci	fsubs	one,%fp1		| ...FP1 IS X-1
42662306a36Sopenharmony_ci	fadds	one,%fp0		| ...FP0 IS X+1
42762306a36Sopenharmony_ci	faddx	%fp1,%fp1		| ...FP1 IS 2(X-1)
42862306a36Sopenharmony_ci|--LOG(X) = LOG(1+U/2)-LOG(1-U/2) WHICH IS AN ODD POLYNOMIAL
42962306a36Sopenharmony_ci|--IN U, U = 2(X-1)/(X+1) = FP1/FP0
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ciLP1CONT2:
43262306a36Sopenharmony_ci|--THIS IS AN RE-ENTRY POINT FOR LOGNP1
43362306a36Sopenharmony_ci	fdivx	%fp0,%fp1		| ...FP1 IS U
43462306a36Sopenharmony_ci	fmovemx %fp2-%fp2/%fp3,-(%sp)	 | ...SAVE FP2
43562306a36Sopenharmony_ci|--REGISTERS SAVED ARE NOW FPCR,FP1,FP2,FP3
43662306a36Sopenharmony_ci|--LET V=U*U, W=V*V, CALCULATE
43762306a36Sopenharmony_ci|--U + U*V*(B1 + V*(B2 + V*(B3 + V*(B4 + V*B5)))) BY
43862306a36Sopenharmony_ci|--U + U*V*(  [B1 + W*(B3 + W*B5)]  +  [V*(B2 + W*B4)]  )
43962306a36Sopenharmony_ci	fmovex	%fp1,%fp0
44062306a36Sopenharmony_ci	fmulx	%fp0,%fp0	| ...FP0 IS V
44162306a36Sopenharmony_ci	fmovex	%fp1,SAVEU(%a6) | ...STORE U IN MEMORY, FREE FP1
44262306a36Sopenharmony_ci	fmovex	%fp0,%fp1
44362306a36Sopenharmony_ci	fmulx	%fp1,%fp1	| ...FP1 IS W
44462306a36Sopenharmony_ci
44562306a36Sopenharmony_ci	fmoved	LOGB5,%fp3
44662306a36Sopenharmony_ci	fmoved	LOGB4,%fp2
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci	fmulx	%fp1,%fp3	| ...W*B5
44962306a36Sopenharmony_ci	fmulx	%fp1,%fp2	| ...W*B4
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci	faddd	LOGB3,%fp3 | ...B3+W*B5
45262306a36Sopenharmony_ci	faddd	LOGB2,%fp2 | ...B2+W*B4
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ci	fmulx	%fp3,%fp1	| ...W*(B3+W*B5), FP3 RELEASED
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci	fmulx	%fp0,%fp2	| ...V*(B2+W*B4)
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ci	faddd	LOGB1,%fp1 | ...B1+W*(B3+W*B5)
45962306a36Sopenharmony_ci	fmulx	SAVEU(%a6),%fp0 | ...FP0 IS U*V
46062306a36Sopenharmony_ci
46162306a36Sopenharmony_ci	faddx	%fp2,%fp1	| ...B1+W*(B3+W*B5) + V*(B2+W*B4), FP2 RELEASED
46262306a36Sopenharmony_ci	fmovemx (%sp)+,%fp2-%fp2/%fp3 | ...FP2 RESTORED
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_ci	fmulx	%fp1,%fp0	| ...U*V*( [B1+W*(B3+W*B5)] + [V*(B2+W*B4)] )
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci	fmovel	%d1,%fpcr
46762306a36Sopenharmony_ci	faddx	SAVEU(%a6),%fp0
46862306a36Sopenharmony_ci	bra	t_frcinx
46962306a36Sopenharmony_ci	rts
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ciLOGNEG:
47262306a36Sopenharmony_ci|--REGISTERS SAVED FPCR. LOG(-VE) IS INVALID
47362306a36Sopenharmony_ci	bra	t_operr
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ci	.global	slognp1d
47662306a36Sopenharmony_cislognp1d:
47762306a36Sopenharmony_ci|--ENTRY POINT FOR LOG(1+Z) FOR DENORMALIZED INPUT
47862306a36Sopenharmony_ci| Simply return the denorm
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci	bra	t_extdnrm
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ci	.global	slognp1
48362306a36Sopenharmony_cislognp1:
48462306a36Sopenharmony_ci|--ENTRY POINT FOR LOG(1+X) FOR X FINITE, NON-ZERO, NOT NAN'S
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci	fmovex	(%a0),%fp0	| ...LOAD INPUT
48762306a36Sopenharmony_ci	fabsx	%fp0		|test magnitude
48862306a36Sopenharmony_ci	fcmpx	LTHOLD,%fp0	|compare with min threshold
48962306a36Sopenharmony_ci	fbgt	LP1REAL		|if greater, continue
49062306a36Sopenharmony_ci	fmovel	#0,%fpsr		|clr N flag from compare
49162306a36Sopenharmony_ci	fmovel	%d1,%fpcr
49262306a36Sopenharmony_ci	fmovex	(%a0),%fp0	|return signed argument
49362306a36Sopenharmony_ci	bra	t_frcinx
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_ciLP1REAL:
49662306a36Sopenharmony_ci	fmovex	(%a0),%fp0	| ...LOAD INPUT
49762306a36Sopenharmony_ci	movel	#0x00000000,ADJK(%a6)
49862306a36Sopenharmony_ci	fmovex	%fp0,%fp1	| ...FP1 IS INPUT Z
49962306a36Sopenharmony_ci	fadds	one,%fp0	| ...X := ROUND(1+Z)
50062306a36Sopenharmony_ci	fmovex	%fp0,X(%a6)
50162306a36Sopenharmony_ci	movew	XFRAC(%a6),XDCARE(%a6)
50262306a36Sopenharmony_ci	movel	X(%a6),%d0
50362306a36Sopenharmony_ci	cmpil	#0,%d0
50462306a36Sopenharmony_ci	ble	LP1NEG0	| ...LOG OF ZERO OR -VE
50562306a36Sopenharmony_ci	cmp2l	BOUNDS2,%d0
50662306a36Sopenharmony_ci	bcs	LOGMAIN	| ...BOUNDS2 IS [1/2,3/2]
50762306a36Sopenharmony_ci|--IF 1+Z > 3/2 OR 1+Z < 1/2, THEN X, WHICH IS ROUNDING 1+Z,
50862306a36Sopenharmony_ci|--CONTAINS AT LEAST 63 BITS OF INFORMATION OF Z. IN THAT CASE,
50962306a36Sopenharmony_ci|--SIMPLY INVOKE LOG(X) FOR LOG(1+Z).
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ciLP1NEAR1:
51262306a36Sopenharmony_ci|--NEXT SEE IF EXP(-1/16) < X < EXP(1/16)
51362306a36Sopenharmony_ci	cmp2l	BOUNDS1,%d0
51462306a36Sopenharmony_ci	bcss	LP1CARE
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ciLP1ONE16:
51762306a36Sopenharmony_ci|--EXP(-1/16) < X < EXP(1/16). LOG(1+Z) = LOG(1+U/2) - LOG(1-U/2)
51862306a36Sopenharmony_ci|--WHERE U = 2Z/(2+Z) = 2Z/(1+X).
51962306a36Sopenharmony_ci	faddx	%fp1,%fp1	| ...FP1 IS 2Z
52062306a36Sopenharmony_ci	fadds	one,%fp0	| ...FP0 IS 1+X
52162306a36Sopenharmony_ci|--U = FP1/FP0
52262306a36Sopenharmony_ci	bra	LP1CONT2
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_ciLP1CARE:
52562306a36Sopenharmony_ci|--HERE WE USE THE USUAL TABLE DRIVEN APPROACH. CARE HAS TO BE
52662306a36Sopenharmony_ci|--TAKEN BECAUSE 1+Z CAN HAVE 67 BITS OF INFORMATION AND WE MUST
52762306a36Sopenharmony_ci|--PRESERVE ALL THE INFORMATION. BECAUSE 1+Z IS IN [1/2,3/2],
52862306a36Sopenharmony_ci|--THERE ARE ONLY TWO CASES.
52962306a36Sopenharmony_ci|--CASE 1: 1+Z < 1, THEN K = -1 AND Y-F = (2-F) + 2Z
53062306a36Sopenharmony_ci|--CASE 2: 1+Z > 1, THEN K = 0  AND Y-F = (1-F) + Z
53162306a36Sopenharmony_ci|--ON RETURNING TO LP1CONT1, WE MUST HAVE K IN FP1, ADDRESS OF
53262306a36Sopenharmony_ci|--(1/F) IN A0, Y-F IN FP0, AND FP2 SAVED.
53362306a36Sopenharmony_ci
53462306a36Sopenharmony_ci	movel	XFRAC(%a6),FFRAC(%a6)
53562306a36Sopenharmony_ci	andil	#0xFE000000,FFRAC(%a6)
53662306a36Sopenharmony_ci	oril	#0x01000000,FFRAC(%a6)	| ...F OBTAINED
53762306a36Sopenharmony_ci	cmpil	#0x3FFF8000,%d0	| ...SEE IF 1+Z > 1
53862306a36Sopenharmony_ci	bges	KISZERO
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ciKISNEG1:
54162306a36Sopenharmony_ci	fmoves	TWO,%fp0
54262306a36Sopenharmony_ci	movel	#0x3fff0000,F(%a6)
54362306a36Sopenharmony_ci	clrl	F+8(%a6)
54462306a36Sopenharmony_ci	fsubx	F(%a6),%fp0	| ...2-F
54562306a36Sopenharmony_ci	movel	FFRAC(%a6),%d0
54662306a36Sopenharmony_ci	andil	#0x7E000000,%d0
54762306a36Sopenharmony_ci	asrl	#8,%d0
54862306a36Sopenharmony_ci	asrl	#8,%d0
54962306a36Sopenharmony_ci	asrl	#4,%d0		| ...D0 CONTAINS DISPLACEMENT FOR 1/F
55062306a36Sopenharmony_ci	faddx	%fp1,%fp1		| ...GET 2Z
55162306a36Sopenharmony_ci	fmovemx %fp2-%fp2/%fp3,-(%sp)	| ...SAVE FP2
55262306a36Sopenharmony_ci	faddx	%fp1,%fp0		| ...FP0 IS Y-F = (2-F)+2Z
55362306a36Sopenharmony_ci	lea	LOGTBL,%a0	| ...A0 IS ADDRESS OF 1/F
55462306a36Sopenharmony_ci	addal	%d0,%a0
55562306a36Sopenharmony_ci	fmoves	negone,%fp1	| ...FP1 IS K = -1
55662306a36Sopenharmony_ci	bra	LP1CONT1
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ciKISZERO:
55962306a36Sopenharmony_ci	fmoves	one,%fp0
56062306a36Sopenharmony_ci	movel	#0x3fff0000,F(%a6)
56162306a36Sopenharmony_ci	clrl	F+8(%a6)
56262306a36Sopenharmony_ci	fsubx	F(%a6),%fp0		| ...1-F
56362306a36Sopenharmony_ci	movel	FFRAC(%a6),%d0
56462306a36Sopenharmony_ci	andil	#0x7E000000,%d0
56562306a36Sopenharmony_ci	asrl	#8,%d0
56662306a36Sopenharmony_ci	asrl	#8,%d0
56762306a36Sopenharmony_ci	asrl	#4,%d0
56862306a36Sopenharmony_ci	faddx	%fp1,%fp0		| ...FP0 IS Y-F
56962306a36Sopenharmony_ci	fmovemx %fp2-%fp2/%fp3,-(%sp)	| ...FP2 SAVED
57062306a36Sopenharmony_ci	lea	LOGTBL,%a0
57162306a36Sopenharmony_ci	addal	%d0,%a0		| ...A0 IS ADDRESS OF 1/F
57262306a36Sopenharmony_ci	fmoves	zero,%fp1	| ...FP1 IS K = 0
57362306a36Sopenharmony_ci	bra	LP1CONT1
57462306a36Sopenharmony_ci
57562306a36Sopenharmony_ciLP1NEG0:
57662306a36Sopenharmony_ci|--FPCR SAVED. D0 IS X IN COMPACT FORM.
57762306a36Sopenharmony_ci	cmpil	#0,%d0
57862306a36Sopenharmony_ci	blts	LP1NEG
57962306a36Sopenharmony_ciLP1ZERO:
58062306a36Sopenharmony_ci	fmoves	negone,%fp0
58162306a36Sopenharmony_ci
58262306a36Sopenharmony_ci	fmovel	%d1,%fpcr
58362306a36Sopenharmony_ci	bra t_dz
58462306a36Sopenharmony_ci
58562306a36Sopenharmony_ciLP1NEG:
58662306a36Sopenharmony_ci	fmoves	zero,%fp0
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ci	fmovel	%d1,%fpcr
58962306a36Sopenharmony_ci	bra	t_operr
59062306a36Sopenharmony_ci
59162306a36Sopenharmony_ci	|end
592