brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 3cca478 Raw
74 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// di_int __ashrdi3(di_int input, int count);8 9#ifdef __i386__10#ifdef __SSE2__11 12.text13.balign 414DEFINE_COMPILERRT_FUNCTION(__ashrdi3)15	movd	  12(%esp),		%xmm2	// Load count16	movl	   8(%esp),		%eax17#ifndef TRUST_CALLERS_USE_64_BIT_STORES18	movd	   4(%esp),		%xmm019	movd	   8(%esp),		%xmm120	punpckldq	%xmm1,		%xmm0	// Load input21#else22	movq	   4(%esp),		%xmm0	// Load input23#endif24 25	psrlq		%xmm2,		%xmm0	// unsigned shift input by count26 27	testl		%eax,		%eax	// check the sign-bit of the input28	jns			1f					// early out for positive inputs29 30	// If the input is negative, we need to construct the shifted sign bit31	// to or into the result, as xmm does not have a signed right shift.32	pcmpeqb		%xmm1,		%xmm1	// -1ULL33	psrlq		$58,		%xmm1	// 0x3f34	pandn		%xmm1,		%xmm2	// 63 - count35	pcmpeqb		%xmm1,		%xmm1	// -1ULL36	psubq		%xmm1,		%xmm2	// 64 - count37	psllq		%xmm2,		%xmm1	// -1 << (64 - count) = leading sign bits38	por			%xmm1,		%xmm039 40	// Move the result back to the general purpose registers and return411:	movd		%xmm0,		%eax42	psrlq		$32,		%xmm043	movd		%xmm0,		%edx44	ret45END_COMPILERRT_FUNCTION(__ashrdi3)46 47#else // Use GPRs instead of SSE2 instructions, if they aren't available.48 49.text50.balign 451DEFINE_COMPILERRT_FUNCTION(__ashrdi3)52	movl	  12(%esp),		%ecx	// Load count53	movl	   8(%esp),		%edx	// Load high54	movl	   4(%esp),		%eax	// Load low55 56	testl		$0x20,		%ecx	// If count >= 3257	jnz			1f					//    goto 158 59	shrdl		%cl, %edx,	%eax	// right shift low by count60	sarl		%cl,		%edx	// right shift high by count61	ret62 631:	movl		%edx,		%eax	// Move high to low64	sarl		$31,		%edx	// clear high65	sarl		%cl,		%eax	// shift low by count - 3266	ret67END_COMPILERRT_FUNCTION(__ashrdi3)68 69#endif // __SSE2__70#endif // __i386__71 72NO_EXEC_STACK_DIRECTIVE73 74