1276789Sdim// This file is dual licensed under the MIT and the University of Illinois Open
2276789Sdim// Source Licenses. See LICENSE.TXT for details.
3276789Sdim
4276789Sdim#include "../assembly.h"
5276789Sdim
6276789Sdim// di_int __ashldi3(di_int input, int count);
7276789Sdim
8276789Sdim// This routine has some extra memory traffic, loading the 64-bit input via two
9276789Sdim// 32-bit loads, then immediately storing it back to the stack via a single 64-bit
10276789Sdim// store.  This is to avoid a write-small, read-large stall.
11276789Sdim// However, if callers of this routine can be safely assumed to store the argument
12276789Sdim// via a 64-bt store, this is unnecessary memory traffic, and should be avoided.
13276789Sdim// It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro.
14276789Sdim
15276789Sdim#ifdef __i386__
16276789Sdim#ifdef __SSE2__
17276789Sdim
18276789Sdim.text
19276789Sdim.balign 4
20276789SdimDEFINE_COMPILERRT_FUNCTION(__ashldi3)
21276789Sdim	movd	  12(%esp),		%xmm2	// Load count
22276789Sdim#ifndef TRUST_CALLERS_USE_64_BIT_STORES
23276789Sdim	movd	   4(%esp),		%xmm0
24276789Sdim	movd	   8(%esp),		%xmm1
25276789Sdim	punpckldq	%xmm1,		%xmm0	// Load input
26276789Sdim#else
27276789Sdim	movq	   4(%esp),		%xmm0	// Load input
28276789Sdim#endif
29276789Sdim	psllq		%xmm2,		%xmm0	// shift input by count
30276789Sdim	movd		%xmm0,		%eax
31276789Sdim	psrlq		$32,		%xmm0
32276789Sdim	movd		%xmm0,		%edx
33276789Sdim	ret
34276789SdimEND_COMPILERRT_FUNCTION(__ashldi3)
35276789Sdim
36276789Sdim#else // Use GPRs instead of SSE2 instructions, if they aren't available.
37276789Sdim
38276789Sdim.text
39276789Sdim.balign 4
40276789SdimDEFINE_COMPILERRT_FUNCTION(__ashldi3)
41276789Sdim	movl	  12(%esp),		%ecx	// Load count
42276789Sdim	movl	   8(%esp),		%edx	// Load high
43276789Sdim	movl	   4(%esp),		%eax	// Load low
44276789Sdim
45276789Sdim	testl		$0x20,		%ecx	// If count >= 32
46276789Sdim	jnz		1f			//    goto 1
47276789Sdim	shldl		%cl, %eax,	%edx	// left shift high by count
48276789Sdim	shll		%cl,		%eax	// left shift low by count
49276789Sdim	ret
50276789Sdim
51276789Sdim1:	movl		%eax,		%edx	// Move low to high
52276789Sdim	xorl		%eax,		%eax	// clear low
53276789Sdim	shll		%cl,		%edx	// shift high by count - 32
54276789Sdim	ret
55276789SdimEND_COMPILERRT_FUNCTION(__ashldi3)
56276789Sdim
57276789Sdim#endif // __SSE2__
58276789Sdim#endif // __i386__
59