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
 
9
	.file	"log2l.S"
10
	.text
11
	.align 4
12
one:	.double 1.0
13
	/* It is not important that this constant is precise.  It is only
14
	   a value which is known to be on the safe side for using the
15
	   fyl2xp1 instruction.  */
16
limit:	.double 0.29
17
 
18
	.text
19
	.align 4
20
.globl _log2l
21
	.def	_log2l;	.scl	2;	.type	32;	.endef
22
_log2l:
23
	fldl	one
24
	fldt	4(%esp)		/* x : 1 */
25
	fxam
26
	fnstsw
27
	fld	%st		/* x : x : 1 */
28
	sahf
29
	jc	3f		/* in case x is NaN or ħInf */
30
4:	fsub	%st(2), %st	/* x-1 : x : 1 */
31
	fld	%st		/* x-1 : x-1 : x : 1 */
32
	fabs			/* |x-1| : x-1 : x : 1 */
33
	fcompl	limit		/* x-1 : x : 1 */
34
	fnstsw			/* x-1 : x : 1 */
35
	andb	$0x45, %ah
36
	jz	2f
37
	fstp	%st(1)		/* x-1 : 1 */
38
	fyl2xp1			/* log(x) */
39
	ret
40
 
41
2:	fstp	%st(0)		/* x : 1 */
42
	fyl2x			/* log(x) */
43
	ret
44
 
45
3:	jp	4b		/* in case x is ħInf */
46
	fstp	%st(1)
47
	fstp	%st(1)
48
	ret