1276789Sdim// This file is dual licensed under the MIT and the University of Illinois Open
2276789Sdim// Source Licenses. See LICENSE.TXT for details.
3276789Sdim
4276789Sdim#include "../assembly.h"
5276789Sdim
6276789Sdim// long double __floatundixf(du_int a);
7276789Sdim
8276789Sdim#ifdef __x86_64__
9276789Sdim
10276789SdimCONST_SECTION
11276789Sdim
12276789Sdim	.balign 16
13276789Sdimtwop64:
14276789Sdim	.quad 0x43f0000000000000
15276789Sdim
16276789Sdim#define REL_ADDR(_a)	(_a)(%rip)
17276789Sdim
18276789Sdim	.text
19276789Sdim
20276789Sdim	.balign 4
21276789SdimDEFINE_COMPILERRT_FUNCTION(__floatundixf)
22276789Sdim	movq	%rdi,	 -8(%rsp)
23276789Sdim	fildq	-8(%rsp)
24276789Sdim	test	%rdi,		%rdi
25276789Sdim	js		1f
26276789Sdim	ret
27276789Sdim1:	faddl	REL_ADDR(twop64)
28276789Sdim	ret
29276789SdimEND_COMPILERRT_FUNCTION(__floatundixf)
30276789Sdim
31276789Sdim#endif // __x86_64__
32276789Sdim
33276789Sdim
34276789Sdim/* Branch-free implementation is ever so slightly slower, but more beautiful.
35276789Sdim   It is likely superior for inlining, so I kept it around for future reference.
36276789Sdim
37276789Sdim#ifdef __x86_64__
38276789Sdim
39276789SdimCONST_SECTION
40276789Sdim
41276789Sdim	.balign 4
42276789Sdimtwop52:
43276789Sdim	.quad 0x4330000000000000
44276789Sdimtwop84_plus_twop52_neg:
45276789Sdim	.quad 0xc530000000100000
46276789Sdimtwop84:
47276789Sdim	.quad 0x4530000000000000
48276789Sdim
49276789Sdim#define REL_ADDR(_a)	(_a)(%rip)
50276789Sdim
51276789Sdim.text
52276789Sdim.balign 4
53276789SdimDEFINE_COMPILERRT_FUNCTION(__floatundixf)
54276789Sdim	movl	%edi,				%esi			// low 32 bits of input
55276789Sdim	shrq	$32,				%rdi			// hi 32 bits of input
56276789Sdim	orq		REL_ADDR(twop84),	%rdi			// 2^84 + hi (as a double)
57276789Sdim	orq		REL_ADDR(twop52),	%rsi			// 2^52 + lo (as a double)
58276789Sdim	movq	%rdi,			 -8(%rsp)
59276789Sdim	movq	%rsi,			-16(%rsp)
60276789Sdim	fldl	REL_ADDR(twop84_plus_twop52_neg)
61276789Sdim	faddl	-8(%rsp)	// hi - 2^52 (as double extended, no rounding occurs)
62276789Sdim	faddl	-16(%rsp)	// hi + lo (as double extended)
63276789Sdim	ret
64276789SdimEND_COMPILERRT_FUNCTION(__floatundixf)
65276789Sdim
66276789Sdim#endif // __x86_64__
67276789Sdim
68276789Sdim*/
69