lshrdi3.S revision 214152
138032Speter// This file is distributed under the University of Illinois Open Source
2182352Sgshapiro// License. See LICENSE.TXT for details.
364565Sgshapiro
438032Speter#include "../assembly.h"
538032Speter
638032Speter// di_int __lshrdi3(di_int input, int count);
738032Speter
838032Speter// This routine has some extra memory traffic, loading the 64-bit input via two
938032Speter// 32-bit loads, then immediately storing it back to the stack via a single 64-bit
1038032Speter// store.  This is to avoid a write-small, read-large stall.
1138032Speter// However, if callers of this routine can be safely assumed to store the argument
1238032Speter// via a 64-bt store, this is unnecessary memory traffic, and should be avoided.
1338032Speter// It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro.
1490795Sgshapiro
1590795Sgshapiro#ifdef __i386__
1690795Sgshapiro#ifdef __SSE2__
17141862Sgshapiro
1864565Sgshapiro.text
1964565Sgshapiro.align 4
2064565SgshapiroDEFINE_COMPILERRT_FUNCTION(__lshrdi3)
2190795Sgshapiro	movd	  12(%esp),		%xmm2	// Load count
2238032Speter#ifndef TRUST_CALLERS_USE_64_BIT_STORES
23249729Sgshapiro	movd	   4(%esp),		%xmm0
2464565Sgshapiro	movd	   8(%esp),		%xmm1
25111367Sgshapiro	punpckldq	%xmm1,		%xmm0	// Load input
2638032Speter#else
2738032Speter	movq	   4(%esp),		%xmm0	// Load input
2838032Speter#endif
2964565Sgshapiro	psrlq		%xmm2,		%xmm0	// shift input by count
3064565Sgshapiro	movd		%xmm0,		%eax
3164565Sgshapiro	psrlq		$32,		%xmm0
3264565Sgshapiro	movd		%xmm0,		%edx
3364565Sgshapiro	ret
3464565Sgshapiro
3564565Sgshapiro#else // Use GPRs instead of SSE2 instructions, if they aren't available.
3664565Sgshapiro
3764565Sgshapiro.text
3864565Sgshapiro.align 4
3964565SgshapiroDEFINE_COMPILERRT_FUNCTION(__lshrdi3)
4038032Speter	movl	  12(%esp),		%ecx	// Load count
4138032Speter	movl	   8(%esp),		%edx	// Load high
4238032Speter	movl	   4(%esp),		%eax	// Load low
4338032Speter
4438032Speter	testl		$0x20,		%ecx	// If count >= 32
45173343Sgshapiro	jnz			1f					//    goto 1
4638032Speter
4738032Speter	shrdl		%cl, %edx,	%eax	// right shift low by count
4890795Sgshapiro	shrl		%cl,		%edx	// right shift high by count
4942580Speter	ret
5064565Sgshapiro
5138032Speter1:	movl		%edx,		%eax	// Move high to low
5238032Speter	xorl		%edx,		%edx	// clear high
5390795Sgshapiro	shrl		%cl,		%eax	// shift low by count - 32
5438032Speter	ret
55141862Sgshapiro
56141862Sgshapiro#endif // __SSE2__
5764565Sgshapiro#endif // __i386__
5864565Sgshapiro