| Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | // This file is distributed under the University of Illinois Open Source |
| 2 | // License. See LICENSE.TXT for details. |
| 3 | |
| Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 4 | #include "../assembly.h" |
| 5 | |
| Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 6 | // double __floatundidf(du_int a); |
| 7 | |
| 8 | #ifdef __i386__ |
| 9 | |
| 10 | .const |
| 11 | .align 4 |
| 12 | twop52: .quad 0x4330000000000000 |
| 13 | twop32: .quad 0x41f0000000000000 |
| 14 | |
| 15 | #define REL_ADDR(_a) (_a)-0b(%eax) |
| 16 | |
| 17 | .text |
| 18 | .align 4 |
| Daniel Dunbar | b4b1e8c | 2009-10-27 17:50:21 +0000 | [diff] [blame^] | 19 | DEFINE_COMPILERRT_FUNCTION(__floatdidf) |
| Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 20 | cvtsi2sd 8(%esp), %xmm1 |
| 21 | movss 4(%esp), %xmm0 // low 32 bits of a |
| 22 | calll 0f |
| 23 | 0: popl %eax |
| 24 | mulsd REL_ADDR(twop32), %xmm1 // a_hi as a double (without rounding) |
| 25 | movsd REL_ADDR(twop52), %xmm2 // 0x1.0p52 |
| 26 | subsd %xmm2, %xmm1 // a_hi - 0x1p52 (no rounding occurs) |
| 27 | orpd %xmm2, %xmm0 // 0x1p52 + a_lo (no rounding occurs) |
| 28 | addsd %xmm1, %xmm0 // a_hi + a_lo (round happens here) |
| 29 | movsd %xmm0, 4(%esp) |
| 30 | fldl 4(%esp) |
| 31 | ret |
| 32 | |
| 33 | #endif // __i386__ |