Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1906 serge 1
/*
2
 * Written by J.T. Conklin .
3
 * Adapted for use as log2 by Ulrich Drepper .
4
 * Public domain.
5
 *
6
 * Changed to use fyl2xp1 for values near 1, .
7
 *
8
 * Removed header file dependency for use in libmingwex.a by
9
 *   Danny Smith 
10
 */
11
 
12
	.file	"log2.S"
13
	.text
14
	.align 4
15
one:	.double 1.0
16
	/* It is not important that this constant is precise.  It is only
17
	   a value which is known to be on the safe side for using the
18
	   fyl2xp1 instruction.  */
19
limit:	.double 0.29
20
 
21
	.text
22
	.align 4
23
.globl _log2
24
	.def	_log2;	.scl	2;	.type	32;	.endef
25
_log2:
26
	fldl	one
27
	fldl	4(%esp)		/* x : 1 */
28
	fxam
29
	fnstsw
30
	fld	%st		/* x : x : 1 */
31
	sahf
32
	jc	3f		/* in case x is NaN or ħInf */
33
4:	fsub	%st(2), %st	/* x-1 : x : 1 */
34
	fld	%st		/* x-1 : x-1 : x : 1 */
35
	fabs			/* |x-1| : x-1 : x : 1 */
36
	fcompl	limit		/* x-1 : x : 1 */
37
	fnstsw			/* x-1 : x : 1 */
38
	andb	$0x45, %ah
39
	jz	2f
40
	fstp	%st(1)		/* x-1 : 1 */
41
	fyl2xp1			/* log(x) */
42
	ret
43
 
44
2:	fstp	%st(0)		/* x : 1 */
45
	fyl2x			/* log(x) */
46
	ret
47
 
48
3:	jp	4b		/* in case x is ħInf */
49
	fstp	%st(1)
50
	fstp	%st(1)
51
	ret