1/*
2 * Public domain.
3 */
4
5#include <machine/asm.h>
6#include <libm-alias-finite.h>
7
8	.section .rodata
9
10	.align ALIGNARG(4)
11	.type zero_nan,@object
12zero_nan:
13	.double 0.0
14nan:	.byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
15	.byte 0, 0, 0, 0, 0, 0, 0, 0x80
16	.byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
17	ASM_SIZE_DIRECTIVE(zero_nan)
18
19
20#ifdef PIC
21# define MO(op) op##(%rip)
22#else
23# define MO(op) op
24#endif
25
26	.text
27ENTRY(__ieee754_scalbl)
28	fldt	24(%rsp)
29	fxam
30	fnstsw
31	fldt	8(%rsp)
32	andl	$0x4700, %eax
33	cmpl	$0x0700, %eax
34	je	1f
35	andl	$0x4500, %eax
36	cmpl	$0x0100, %eax
37	je	2f
38	fxam
39	fnstsw
40	andl	$0x4500, %eax
41	cmpl	$0x0100, %eax
42	je	2f
43	fld	%st(1)
44	frndint
45	fcomip	%st(2), %st
46	jne	4f
47	fscale
48	fstp	%st(1)
49	ret
50
51	/* y is -inf */
521:	fxam
53	fnstsw
54	movl	16(%rsp), %edx
55	shrl	$5, %eax
56	fstp	%st
57	fstp	%st
58	andl	$0x8000, %edx
59	andl	$0x0228, %eax
60	cmpl	$0x0028, %eax
61	je	4f
62	andl	$8, %eax
63	shrl	$11, %edx
64	addl	%edx, %eax
65#ifdef PIC
66	lea	zero_nan(%rip),%rdx
67	fldl	(%rdx,%rax,1)
68#else
69	fldl	zero_nan(%rax, 1)
70#endif
71	ret
72
73	/* The result is NaN; raise an exception for sNaN arguments.  */
742:	faddp
75	ret
76
77	/* Return NaN and raise the invalid exception.  */
784:	fstp	%st
79	fstp	%st
80	fldz
81	fdiv	%st
82	ret
83END(__ieee754_scalbl)
84libm_alias_finite (__ieee754_scalbl, __scalbl)
85