blob: d0a4c4289ef5fc9ba5d329ea00448246fbda0ee1 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001// This file is distributed under the University of Illinois Open Source
2// License. See LICENSE.TXT for details.
3
Daniel Dunbar7d504782009-10-27 17:49:50 +00004#include "../assembly.h"
5
Daniel Dunbarfd089992009-06-26 16:47:03 +00006// di_int __ashrdi3(di_int input, int count);
7
8#ifdef __i386__
9#ifdef __SSE2__
10
11.text
12.align 4
13.globl ___ashrdi3
14___ashrdi3:
15 movd 12(%esp), %xmm2 // Load count
16 movl 8(%esp), %eax
17#ifndef TRUST_CALLERS_USE_64_BIT_STORES
18 movd 4(%esp), %xmm0
19 movd 8(%esp), %xmm1
20 punpckldq %xmm1, %xmm0 // Load input
21#else
22 movq 4(%esp), %xmm0 // Load input
23#endif
24
25 psrlq %xmm2, %xmm0 // unsigned shift input by count
26
27 testl %eax, %eax // check the sign-bit of the input
28 jns 1f // early out for positive inputs
29
30 // If the input is negative, we need to construct the shifted sign bit
31 // to or into the result, as xmm does not have a signed right shift.
32 pcmpeqb %xmm1, %xmm1 // -1ULL
33 psrlq $58, %xmm1 // 0x3f
34 pandn %xmm1, %xmm2 // 63 - count
35 pcmpeqb %xmm1, %xmm1 // -1ULL
36 psubq %xmm1, %xmm2 // 64 - count
37 psllq %xmm2, %xmm1 // -1 << (64 - count) = leading sign bits
38 por %xmm1, %xmm0
39
40 // Move the result back to the general purpose registers and return
411: movd %xmm0, %eax
42 psrlq $32, %xmm0
43 movd %xmm0, %edx
44 ret
45
46#else // Use GPRs instead of SSE2 instructions, if they aren't available.
47
48.text
49.align 4
50.globl ___ashrdi3
51___ashrdi3:
52 movl 12(%esp), %ecx // Load count
53 movl 8(%esp), %edx // Load high
54 movl 4(%esp), %eax // Load low
55
56 testl $0x20, %ecx // If count >= 32
Eli Friedman30bd27b2009-07-03 02:26:38 +000057 jnz 1f // goto 1
58
59 shrdl %cl, %edx, %eax // right shift low by count
Daniel Dunbarfd089992009-06-26 16:47:03 +000060 sarl %cl, %edx // right shift high by count
Eli Friedman30bd27b2009-07-03 02:26:38 +000061 ret
Daniel Dunbarfd089992009-06-26 16:47:03 +000062
Eli Friedman30bd27b2009-07-03 02:26:38 +0000631: movl %edx, %eax // Move high to low
Daniel Dunbarfd089992009-06-26 16:47:03 +000064 sarl $31, %edx // clear high
65 sarl %cl, %eax // shift low by count - 32
66 ret
67
68#endif // __SSE2__
69#endif // __i386__