xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/lib/builtins/i386/floatdidf.S (revision ef84fd3bd8895f4e6be1e38baf19e6dc3255bc64)
1156cd587Sjoerg// This file is dual licensed under the MIT and the University of Illinois Open
2156cd587Sjoerg// Source Licenses. See LICENSE.TXT for details.
3156cd587Sjoerg
4156cd587Sjoerg#include "../assembly.h"
5156cd587Sjoerg
6156cd587Sjoerg// double __floatundidf(du_int a);
7156cd587Sjoerg
8156cd587Sjoerg#ifdef __i386__
9156cd587Sjoerg
10*ef84fd3bSjoergCONST_SECTION
11190e92d8Sjoerg
12190e92d8Sjoerg	.balign 16
13190e92d8Sjoergtwop52:
14190e92d8Sjoerg	.quad 0x4330000000000000
15190e92d8Sjoerg
16190e92d8Sjoerg	.balign 16
17190e92d8Sjoergtwop32:
18190e92d8Sjoerg	.quad 0x41f0000000000000
19156cd587Sjoerg
20156cd587Sjoerg#define REL_ADDR(_a)	(_a)-0b(%eax)
21156cd587Sjoerg
22156cd587Sjoerg.text
2361f2f256Sjoerg.balign 4
24156cd587SjoergDEFINE_COMPILERRT_FUNCTION(__floatdidf)
25156cd587Sjoerg	cvtsi2sd	8(%esp),			%xmm1
26156cd587Sjoerg	movss		4(%esp),			%xmm0 // low 32 bits of a
27156cd587Sjoerg	calll		0f
28156cd587Sjoerg0:	popl		%eax
29156cd587Sjoerg	mulsd		REL_ADDR(twop32),	%xmm1 // a_hi as a double (without rounding)
30156cd587Sjoerg	movsd		REL_ADDR(twop52),	%xmm2 // 0x1.0p52
31156cd587Sjoerg	subsd		%xmm2,				%xmm1 // a_hi - 0x1p52 (no rounding occurs)
32156cd587Sjoerg	orpd		%xmm2,				%xmm0 // 0x1p52 + a_lo (no rounding occurs)
33156cd587Sjoerg	addsd		%xmm1,				%xmm0 // a_hi + a_lo   (round happens here)
34156cd587Sjoerg	movsd		%xmm0,			   4(%esp)
35156cd587Sjoerg	fldl	   4(%esp)
36156cd587Sjoerg	ret
37156cd587SjoergEND_COMPILERRT_FUNCTION(__floatdidf)
38156cd587Sjoerg
39156cd587Sjoerg#endif // __i386__
40