brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 4430171 Raw
110 lines · plain
1// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.2// See https://llvm.org/LICENSE.txt for license information.3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception4 5#include "../assembly.h"6 7// float __floatundisf(du_int a);8 9// Note that there is a hardware instruction, fildll, that does most of what10// this function needs to do.  However, because of our ia32 ABI, it will take11// a write-small read-large stall, so the software implementation here is12// actually several cycles faster.13 14// This is a branch-free implementation.  A branchy implementation might be15// faster for the common case if you know something a priori about the input16// distribution.17 18/* branch-free x87 implementation - one cycle slower than without x87.19 20#ifdef __i386__21 22CONST_SECTION23.balign 324 25		.quad	0x43f000000000000026twop64:	.quad	0x000000000000000027 28#define			TWOp64			twop64-0b(%ecx,%eax,8)29 30.text31.balign 432DEFINE_COMPILERRT_FUNCTION(__floatundisf)33	movl		8(%esp),		%eax34	movd		8(%esp),		%xmm135	movd		4(%esp),		%xmm036	punpckldq	%xmm1,			%xmm037	calll		0f380:	popl		%ecx39	sarl		$31,			%eax40	movq		%xmm0,			4(%esp)41	fildll		4(%esp)42	faddl		TWOp6443	fstps		4(%esp)44	flds		4(%esp)45	ret46END_COMPILERRT_FUNCTION(__floatundisf)47 48#endif // __i386__49 50*/51 52// branch-free, x87-free implementation - faster at the expense of code size53 54#ifdef __i386__55 56CONST_SECTION57 58	.balign 1659twop52:60	.quad 0x433000000000000061	.quad 0x0000000000000fff62 63	.balign 1664sticky:65	.quad 0x000000000000000066	.long 0x0000001267 68	.balign 1669twelve:70	.long 0x0000000071 72#define			TWOp52			twop52-0b(%ecx)73#define			STICKY			sticky-0b(%ecx,%eax,8)74 75.text76.balign 477DEFINE_COMPILERRT_FUNCTION(__floatundisf)78	movl		8(%esp),		%eax79	movd		8(%esp),		%xmm180	movd		4(%esp),		%xmm081	punpckldq	%xmm1,			%xmm082 83	calll		0f840:	popl		%ecx85	shrl		%eax					// high 31 bits of input as sint3286	addl		$0x7ff80000,	%eax87	sarl		$31,			%eax	// (big input) ? -1 : 088	movsd		STICKY,			%xmm1	// (big input) ? 0xfff : 089	movl		$12,			%edx90	andl		%eax,			%edx	// (big input) ? 12 : 091	movd		%edx,			%xmm392	andpd		%xmm0,			%xmm1	// (big input) ? input & 0xfff : 093	movsd		TWOp52,			%xmm2	// 0x1.0p5294	psrlq		%xmm3,			%xmm0	// (big input) ? input >> 12 : input95	orpd		%xmm2,			%xmm1	// 0x1.0p52 + ((big input) ? input & 0xfff : input)96	orpd		%xmm1,			%xmm0	// 0x1.0p52 + ((big input) ? (input >> 12 | input & 0xfff) : input)97	subsd		%xmm2,			%xmm0	// (double)((big input) ? (input >> 12 | input & 0xfff) : input)98	cvtsd2ss	%xmm0,			%xmm0	// (float)((big input) ? (input >> 12 | input & 0xfff) : input)99	pslld		$23,			%xmm3100	paddd		%xmm3,			%xmm0	// (float)input101	movd		%xmm0,			4(%esp)102	flds		4(%esp)103	ret104END_COMPILERRT_FUNCTION(__floatundisf)105 106#endif // __i386__107 108NO_EXEC_STACK_DIRECTIVE109 110