1 // This file is dual licensed under the MIT and the University of Illinois Open
2 // Source Licenses. See LICENSE.TXT for details.
4 #include "../assembly.h"
6 // di_int __ashrdi3(di_int input, int count);
13 DEFINE_COMPILERRT_FUNCTION(__ashrdi3)
14 movd 12(%esp), %xmm2 // Load count
16 #ifndef TRUST_CALLERS_USE_64_BIT_STORES
19 punpckldq %xmm1, %xmm0 // Load input
21 movq 4(%esp), %xmm0 // Load input
24 psrlq %xmm2, %xmm0 // unsigned shift input by count
26 testl %eax, %eax // check the sign-bit of the input
27 jns 1f // early out for positive inputs
29 // If the input is negative, we need to construct the shifted sign bit
30 // to or into the result, as xmm does not have a signed right shift.
31 pcmpeqb %xmm1, %xmm1 // -1ULL
32 psrlq $58, %xmm1 // 0x3f
33 pandn %xmm1, %xmm2 // 63 - count
34 pcmpeqb %xmm1, %xmm1 // -1ULL
35 psubq %xmm1, %xmm2 // 64 - count
36 psllq %xmm2, %xmm1 // -1 << (64 - count) = leading sign bits
39 // Move the result back to the general purpose registers and return
44 END_COMPILERRT_FUNCTION(__ashrdi3)
46 #else // Use GPRs instead of SSE2 instructions, if they aren't available.
50 DEFINE_COMPILERRT_FUNCTION(__ashrdi3)
51 movl 12(%esp), %ecx // Load count
52 movl 8(%esp), %edx // Load high
53 movl 4(%esp), %eax // Load low
55 testl $0x20, %ecx // If count >= 32
58 shrdl %cl, %edx, %eax // right shift low by count
59 sarl %cl, %edx // right shift high by count
62 1: movl %edx, %eax // Move high to low
63 sarl $31, %edx // clear high
64 sarl %cl, %eax // shift low by count - 32
66 END_COMPILERRT_FUNCTION(__ashrdi3)