2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2009-10-28 01:49:50 +08:00
|
|
|
#include "../assembly.h"
|
|
|
|
|
2009-06-27 00:47:03 +08:00
|
|
|
// float __floatundisf(du_int a);
|
|
|
|
|
|
|
|
// Note that there is a hardware instruction, fildll, that does most of what
|
|
|
|
// this function needs to do. However, because of our ia32 ABI, it will take
|
|
|
|
// a write-small read-large stall, so the software implementation here is
|
|
|
|
// actually several cycles faster.
|
|
|
|
|
|
|
|
// This is a branch-free implementation. A branchy implementation might be
|
|
|
|
// faster for the common case if you know something a priori about the input
|
|
|
|
// distribution.
|
|
|
|
|
|
|
|
/* branch-free x87 implementation - one cycle slower than without x87.
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
|
2014-12-10 10:36:22 +08:00
|
|
|
CONST_SECTION
|
2014-05-12 23:23:37 +08:00
|
|
|
.balign 3
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
.quad 0x43f0000000000000
|
|
|
|
twop64: .quad 0x0000000000000000
|
|
|
|
|
|
|
|
#define TWOp64 twop64-0b(%ecx,%eax,8)
|
|
|
|
|
|
|
|
.text
|
2014-05-12 23:23:37 +08:00
|
|
|
.balign 4
|
2009-10-28 01:50:21 +08:00
|
|
|
DEFINE_COMPILERRT_FUNCTION(__floatundisf)
|
2009-06-27 00:47:03 +08:00
|
|
|
movl 8(%esp), %eax
|
|
|
|
movd 8(%esp), %xmm1
|
|
|
|
movd 4(%esp), %xmm0
|
|
|
|
punpckldq %xmm1, %xmm0
|
|
|
|
calll 0f
|
|
|
|
0: popl %ecx
|
|
|
|
sarl $31, %eax
|
|
|
|
movq %xmm0, 4(%esp)
|
|
|
|
fildll 4(%esp)
|
|
|
|
faddl TWOp64
|
|
|
|
fstps 4(%esp)
|
|
|
|
flds 4(%esp)
|
|
|
|
ret
|
2014-01-24 22:40:53 +08:00
|
|
|
END_COMPILERRT_FUNCTION(__floatundisf)
|
|
|
|
|
2009-06-27 00:47:03 +08:00
|
|
|
#endif // __i386__
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-04-29 06:47:49 +08:00
|
|
|
// branch-free, x87-free implementation - faster at the expense of code size
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
|
2014-12-10 10:36:22 +08:00
|
|
|
CONST_SECTION
|
2014-07-27 05:08:41 +08:00
|
|
|
|
2014-07-27 05:08:34 +08:00
|
|
|
.balign 16
|
|
|
|
twop52:
|
|
|
|
.quad 0x4330000000000000
|
|
|
|
.quad 0x0000000000000fff
|
|
|
|
|
|
|
|
.balign 16
|
|
|
|
sticky:
|
|
|
|
.quad 0x0000000000000000
|
|
|
|
.long 0x00000012
|
|
|
|
|
|
|
|
.balign 16
|
|
|
|
twelve:
|
|
|
|
.long 0x00000000
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#define TWOp52 twop52-0b(%ecx)
|
|
|
|
#define STICKY sticky-0b(%ecx,%eax,8)
|
|
|
|
|
|
|
|
.text
|
2014-05-12 23:23:37 +08:00
|
|
|
.balign 4
|
2009-10-28 01:50:21 +08:00
|
|
|
DEFINE_COMPILERRT_FUNCTION(__floatundisf)
|
2009-06-27 00:47:03 +08:00
|
|
|
movl 8(%esp), %eax
|
|
|
|
movd 8(%esp), %xmm1
|
|
|
|
movd 4(%esp), %xmm0
|
|
|
|
punpckldq %xmm1, %xmm0
|
2019-04-29 06:47:49 +08:00
|
|
|
|
2009-06-27 00:47:03 +08:00
|
|
|
calll 0f
|
|
|
|
0: popl %ecx
|
|
|
|
shrl %eax // high 31 bits of input as sint32
|
|
|
|
addl $0x7ff80000, %eax
|
|
|
|
sarl $31, %eax // (big input) ? -1 : 0
|
|
|
|
movsd STICKY, %xmm1 // (big input) ? 0xfff : 0
|
|
|
|
movl $12, %edx
|
|
|
|
andl %eax, %edx // (big input) ? 12 : 0
|
|
|
|
movd %edx, %xmm3
|
|
|
|
andpd %xmm0, %xmm1 // (big input) ? input & 0xfff : 0
|
|
|
|
movsd TWOp52, %xmm2 // 0x1.0p52
|
|
|
|
psrlq %xmm3, %xmm0 // (big input) ? input >> 12 : input
|
|
|
|
orpd %xmm2, %xmm1 // 0x1.0p52 + ((big input) ? input & 0xfff : input)
|
|
|
|
orpd %xmm1, %xmm0 // 0x1.0p52 + ((big input) ? (input >> 12 | input & 0xfff) : input)
|
|
|
|
subsd %xmm2, %xmm0 // (double)((big input) ? (input >> 12 | input & 0xfff) : input)
|
|
|
|
cvtsd2ss %xmm0, %xmm0 // (float)((big input) ? (input >> 12 | input & 0xfff) : input)
|
|
|
|
pslld $23, %xmm3
|
|
|
|
paddd %xmm3, %xmm0 // (float)input
|
|
|
|
movd %xmm0, 4(%esp)
|
|
|
|
flds 4(%esp)
|
|
|
|
ret
|
2014-01-24 22:40:53 +08:00
|
|
|
END_COMPILERRT_FUNCTION(__floatundisf)
|
|
|
|
|
2009-06-27 00:47:03 +08:00
|
|
|
#endif // __i386__
|
2016-06-23 06:09:42 +08:00
|
|
|
|
|
|
|
NO_EXEC_STACK_DIRECTIVE
|
|
|
|
|