1222656Sed// This file is dual licensed under the MIT and the University of Illinois Open
2222656Sed// Source Licenses. See LICENSE.TXT for details.
3214152Sed
4214152Sed#include "../assembly.h"
5214152Sed
6214152Sed// double __floatundidf(du_int a);
7214152Sed
8214152Sed#ifdef __i386__
9214152Sed
10214152Sed#ifndef __ELF__
11214152Sed.const
12214152Sed#endif
13214152Sed.align 4
14214152Sedtwop52: .quad 0x4330000000000000
15214152Sedtwop32: .quad 0x41f0000000000000
16214152Sed
17214152Sed#define REL_ADDR(_a)	(_a)-0b(%eax)
18214152Sed
19214152Sed.text
20214152Sed.align 4
21214152SedDEFINE_COMPILERRT_FUNCTION(__floatdidf)
22214152Sed	cvtsi2sd	8(%esp),			%xmm1
23214152Sed	movss		4(%esp),			%xmm0 // low 32 bits of a
24214152Sed	calll		0f
25214152Sed0:	popl		%eax
26214152Sed	mulsd		REL_ADDR(twop32),	%xmm1 // a_hi as a double (without rounding)
27214152Sed	movsd		REL_ADDR(twop52),	%xmm2 // 0x1.0p52
28214152Sed	subsd		%xmm2,				%xmm1 // a_hi - 0x1p52 (no rounding occurs)
29214152Sed	orpd		%xmm2,				%xmm0 // 0x1p52 + a_lo (no rounding occurs)
30214152Sed	addsd		%xmm1,				%xmm0 // a_hi + a_lo   (round happens here)
31214152Sed	movsd		%xmm0,			   4(%esp)
32214152Sed	fldl	   4(%esp)
33214152Sed	ret
34214152Sed
35214152Sed#endif // __i386__
36