Home | History | Annotate | Line # | Download | only in fpsp
slog2.sa revision 1.1
      1  1.1  mycroft *	MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
      2  1.1  mycroft *	M68000 Hi-Performance Microprocessor Division
      3  1.1  mycroft *	M68040 Software Package 
      4  1.1  mycroft *
      5  1.1  mycroft *	M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
      6  1.1  mycroft *	All rights reserved.
      7  1.1  mycroft *
      8  1.1  mycroft *	THE SOFTWARE is provided on an "AS IS" basis and without warranty.
      9  1.1  mycroft *	To the maximum extent permitted by applicable law,
     10  1.1  mycroft *	MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
     11  1.1  mycroft *	INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
     12  1.1  mycroft *	PARTICULAR PURPOSE and any warranty against infringement with
     13  1.1  mycroft *	regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
     14  1.1  mycroft *	and any accompanying written materials. 
     15  1.1  mycroft *
     16  1.1  mycroft *	To the maximum extent permitted by applicable law,
     17  1.1  mycroft *	IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
     18  1.1  mycroft *	(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
     19  1.1  mycroft *	PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
     20  1.1  mycroft *	OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
     21  1.1  mycroft *	SOFTWARE.  Motorola assumes no responsibility for the maintenance
     22  1.1  mycroft *	and support of the SOFTWARE.  
     23  1.1  mycroft *
     24  1.1  mycroft *	You are hereby granted a copyright license to use, modify, and
     25  1.1  mycroft *	distribute the SOFTWARE so long as this entire notice is retained
     26  1.1  mycroft *	without alteration in any modified and/or redistributed versions,
     27  1.1  mycroft *	and that such modified versions are clearly identified as such.
     28  1.1  mycroft *	No licenses are granted by implication, estoppel or otherwise
     29  1.1  mycroft *	under any patents or trademarks of Motorola, Inc.
     30  1.1  mycroft 
     31  1.1  mycroft *
     32  1.1  mycroft *	slog2.sa 3.1 12/10/90
     33  1.1  mycroft *
     34  1.1  mycroft *       The entry point slog10 computes the base-10 
     35  1.1  mycroft *	logarithm of an input argument X.
     36  1.1  mycroft *	slog10d does the same except the input value is a 
     37  1.1  mycroft *	denormalized number.  
     38  1.1  mycroft *	sLog2 and sLog2d are the base-2 analogues.
     39  1.1  mycroft *
     40  1.1  mycroft *       INPUT:	Double-extended value in memory location pointed to 
     41  1.1  mycroft *		by address register a0.
     42  1.1  mycroft *
     43  1.1  mycroft *       OUTPUT: log_10(X) or log_2(X) returned in floating-point 
     44  1.1  mycroft *		register fp0.
     45  1.1  mycroft *
     46  1.1  mycroft *       ACCURACY and MONOTONICITY: The returned result is within 1.7 
     47  1.1  mycroft *		ulps in 64 significant bit, i.e. within 0.5003 ulp 
     48  1.1  mycroft *		to 53 bits if the result is subsequently rounded 
     49  1.1  mycroft *		to double precision. The result is provably monotonic 
     50  1.1  mycroft *		in double precision.
     51  1.1  mycroft *
     52  1.1  mycroft *       SPEED:	Two timings are measured, both in the copy-back mode. 
     53  1.1  mycroft *		The first one is measured when the function is invoked 
     54  1.1  mycroft *		the first time (so the instructions and data are not 
     55  1.1  mycroft *		in cache), and the second one is measured when the 
     56  1.1  mycroft *		function is reinvoked at the same input argument.
     57  1.1  mycroft *
     58  1.1  mycroft *       ALGORITHM and IMPLEMENTATION NOTES:
     59  1.1  mycroft *
     60  1.1  mycroft *       slog10d:
     61  1.1  mycroft *
     62  1.1  mycroft *       Step 0.   If X < 0, create a NaN and raise the invalid operation
     63  1.1  mycroft *                 flag. Otherwise, save FPCR in D1; set FpCR to default.
     64  1.1  mycroft *       Notes:    Default means round-to-nearest mode, no floating-point
     65  1.1  mycroft *                 traps, and precision control = double extended.
     66  1.1  mycroft *
     67  1.1  mycroft *       Step 1.   Call slognd to obtain Y = log(X), the natural log of X.
     68  1.1  mycroft *       Notes:    Even if X is denormalized, log(X) is always normalized.
     69  1.1  mycroft *
     70  1.1  mycroft *       Step 2.   Compute log_10(X) = log(X) * (1/log(10)).
     71  1.1  mycroft *            2.1  Restore the user FPCR
     72  1.1  mycroft *            2.2  Return ans := Y * INV_L10.
     73  1.1  mycroft *
     74  1.1  mycroft *
     75  1.1  mycroft *       slog10: 
     76  1.1  mycroft *
     77  1.1  mycroft *       Step 0.   If X < 0, create a NaN and raise the invalid operation
     78  1.1  mycroft *                 flag. Otherwise, save FPCR in D1; set FpCR to default.
     79  1.1  mycroft *       Notes:    Default means round-to-nearest mode, no floating-point
     80  1.1  mycroft *                 traps, and precision control = double extended.
     81  1.1  mycroft *
     82  1.1  mycroft *       Step 1.   Call sLogN to obtain Y = log(X), the natural log of X.
     83  1.1  mycroft *
     84  1.1  mycroft *       Step 2.   Compute log_10(X) = log(X) * (1/log(10)).
     85  1.1  mycroft *            2.1  Restore the user FPCR
     86  1.1  mycroft *            2.2  Return ans := Y * INV_L10.
     87  1.1  mycroft *
     88  1.1  mycroft *
     89  1.1  mycroft *       sLog2d:
     90  1.1  mycroft *
     91  1.1  mycroft *       Step 0.   If X < 0, create a NaN and raise the invalid operation
     92  1.1  mycroft *                 flag. Otherwise, save FPCR in D1; set FpCR to default.
     93  1.1  mycroft *       Notes:    Default means round-to-nearest mode, no floating-point
     94  1.1  mycroft *                 traps, and precision control = double extended.
     95  1.1  mycroft *
     96  1.1  mycroft *       Step 1.   Call slognd to obtain Y = log(X), the natural log of X.
     97  1.1  mycroft *       Notes:    Even if X is denormalized, log(X) is always normalized.
     98  1.1  mycroft *
     99  1.1  mycroft *       Step 2.   Compute log_10(X) = log(X) * (1/log(2)).
    100  1.1  mycroft *            2.1  Restore the user FPCR
    101  1.1  mycroft *            2.2  Return ans := Y * INV_L2.
    102  1.1  mycroft *
    103  1.1  mycroft *
    104  1.1  mycroft *       sLog2:
    105  1.1  mycroft *
    106  1.1  mycroft *       Step 0.   If X < 0, create a NaN and raise the invalid operation
    107  1.1  mycroft *                 flag. Otherwise, save FPCR in D1; set FpCR to default.
    108  1.1  mycroft *       Notes:    Default means round-to-nearest mode, no floating-point
    109  1.1  mycroft *                 traps, and precision control = double extended.
    110  1.1  mycroft *
    111  1.1  mycroft *       Step 1.   If X is not an integer power of two, i.e., X != 2^k,
    112  1.1  mycroft *                 go to Step 3.
    113  1.1  mycroft *
    114  1.1  mycroft *       Step 2.   Return k.
    115  1.1  mycroft *            2.1  Get integer k, X = 2^k.
    116  1.1  mycroft *            2.2  Restore the user FPCR.
    117  1.1  mycroft *            2.3  Return ans := convert-to-double-extended(k).
    118  1.1  mycroft *
    119  1.1  mycroft *       Step 3.   Call sLogN to obtain Y = log(X), the natural log of X.
    120  1.1  mycroft *
    121  1.1  mycroft *       Step 4.   Compute log_2(X) = log(X) * (1/log(2)).
    122  1.1  mycroft *            4.1  Restore the user FPCR
    123  1.1  mycroft *            4.2  Return ans := Y * INV_L2.
    124  1.1  mycroft *
    125  1.1  mycroft 
    126  1.1  mycroft SLOG2    IDNT    2,1 Motorola 040 Floating Point Software Package
    127  1.1  mycroft 
    128  1.1  mycroft 	section	8
    129  1.1  mycroft 
    130  1.1  mycroft 	xref	t_frcinx	
    131  1.1  mycroft 	xref	t_operr
    132  1.1  mycroft 	xref	slogn
    133  1.1  mycroft 	xref	slognd
    134  1.1  mycroft 
    135  1.1  mycroft INV_L10  DC.L $3FFD0000,$DE5BD8A9,$37287195,$00000000
    136  1.1  mycroft 
    137  1.1  mycroft INV_L2   DC.L $3FFF0000,$B8AA3B29,$5C17F0BC,$00000000
    138  1.1  mycroft 
    139  1.1  mycroft 	xdef	slog10d
    140  1.1  mycroft slog10d:
    141  1.1  mycroft *--entry point for Log10(X), X is denormalized
    142  1.1  mycroft 	move.l		(a0),d0
    143  1.1  mycroft 	blt.w		invalid
    144  1.1  mycroft 	move.l		d1,-(sp)
    145  1.1  mycroft 	clr.l		d1
    146  1.1  mycroft 	bsr		slognd			...log(X), X denorm.
    147  1.1  mycroft 	fmove.l		(sp)+,fpcr
    148  1.1  mycroft 	fmul.x		INV_L10,fp0
    149  1.1  mycroft 	bra		t_frcinx
    150  1.1  mycroft 
    151  1.1  mycroft 	xdef	slog10
    152  1.1  mycroft slog10:
    153  1.1  mycroft *--entry point for Log10(X), X is normalized
    154  1.1  mycroft 
    155  1.1  mycroft 	move.l		(a0),d0
    156  1.1  mycroft 	blt.w		invalid
    157  1.1  mycroft 	move.l		d1,-(sp)
    158  1.1  mycroft 	clr.l		d1
    159  1.1  mycroft 	bsr		slogn			...log(X), X normal.
    160  1.1  mycroft 	fmove.l		(sp)+,fpcr
    161  1.1  mycroft 	fmul.x		INV_L10,fp0
    162  1.1  mycroft 	bra		t_frcinx
    163  1.1  mycroft 
    164  1.1  mycroft 
    165  1.1  mycroft 	xdef	slog2d
    166  1.1  mycroft slog2d:
    167  1.1  mycroft *--entry point for Log2(X), X is denormalized
    168  1.1  mycroft 
    169  1.1  mycroft 	move.l		(a0),d0
    170  1.1  mycroft 	blt.w		invalid
    171  1.1  mycroft 	move.l		d1,-(sp)
    172  1.1  mycroft 	clr.l		d1
    173  1.1  mycroft 	bsr		slognd			...log(X), X denorm.
    174  1.1  mycroft 	fmove.l		(sp)+,fpcr
    175  1.1  mycroft 	fmul.x		INV_L2,fp0
    176  1.1  mycroft 	bra		t_frcinx
    177  1.1  mycroft 
    178  1.1  mycroft 	xdef	slog2
    179  1.1  mycroft slog2:
    180  1.1  mycroft *--entry point for Log2(X), X is normalized
    181  1.1  mycroft 	move.l		(a0),d0
    182  1.1  mycroft 	blt.w		invalid
    183  1.1  mycroft 
    184  1.1  mycroft 	move.l		8(a0),d0
    185  1.1  mycroft 	bne.b		continue		...X is not 2^k
    186  1.1  mycroft 
    187  1.1  mycroft 	move.l		4(a0),d0
    188  1.1  mycroft 	and.l		#$7FFFFFFF,d0
    189  1.1  mycroft 	tst.l		d0
    190  1.1  mycroft 	bne.b		continue
    191  1.1  mycroft 
    192  1.1  mycroft *--X = 2^k.
    193  1.1  mycroft 	move.w		(a0),d0
    194  1.1  mycroft 	and.l		#$00007FFF,d0
    195  1.1  mycroft 	sub.l		#$3FFF,d0
    196  1.1  mycroft 	fmove.l		d1,fpcr
    197  1.1  mycroft 	fmove.l		d0,fp0
    198  1.1  mycroft 	bra		t_frcinx
    199  1.1  mycroft 
    200  1.1  mycroft continue:
    201  1.1  mycroft 	move.l		d1,-(sp)
    202  1.1  mycroft 	clr.l		d1
    203  1.1  mycroft 	bsr		slogn			...log(X), X normal.
    204  1.1  mycroft 	fmove.l		(sp)+,fpcr
    205  1.1  mycroft 	fmul.x		INV_L2,fp0
    206  1.1  mycroft 	bra		t_frcinx
    207  1.1  mycroft 
    208  1.1  mycroft invalid:
    209  1.1  mycroft 	bra		t_operr
    210  1.1  mycroft 
    211  1.1  mycroft 	end
    212