Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame^] | 1 | // This file is distributed under the University of Illinois Open Source |
| 2 | // License. See LICENSE.TXT for details. |
| 3 | |
| 4 | // di_int __ashldi3(di_int input, int count); |
| 5 | |
| 6 | // This routine has some extra memory traffic, loading the 64-bit input via two |
| 7 | // 32-bit loads, then immediately storing it back to the stack via a single 64-bit |
| 8 | // store. This is to avoid a write-small, read-large stall. |
| 9 | // However, if callers of this routine can be safely assumed to store the argument |
| 10 | // via a 64-bt store, this is unnecessary memory traffic, and should be avoided. |
| 11 | // It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro. |
| 12 | |
| 13 | #ifdef __i386__ |
| 14 | #ifdef __SSE2__ |
| 15 | |
| 16 | .text |
| 17 | .align 4 |
| 18 | .globl ___ashldi3 |
| 19 | ___ashldi3: |
| 20 | movd 12(%esp), %xmm2 // Load count |
| 21 | #ifndef TRUST_CALLERS_USE_64_BIT_STORES |
| 22 | movd 4(%esp), %xmm0 |
| 23 | movd 8(%esp), %xmm1 |
| 24 | punpckldq %xmm1, %xmm0 // Load input |
| 25 | #else |
| 26 | movq 4(%esp), %xmm0 // Load input |
| 27 | #endif |
| 28 | psllq %xmm2, %xmm0 // shift input by count |
| 29 | movd %xmm0, %eax |
| 30 | psrlq $32, %xmm0 |
| 31 | movd %xmm0, %edx |
| 32 | ret |
| 33 | |
| 34 | #else // Use GPRs instead of SSE2 instructions, if they aren't available. |
| 35 | |
| 36 | .text |
| 37 | .align 4 |
| 38 | .globl ___ashldi3 |
| 39 | ___ashldi3: |
| 40 | movl 12(%esp), %ecx // Load count |
| 41 | movl 8(%esp), %edx // Load high |
| 42 | movl 4(%esp), %eax // Load low |
| 43 | |
| 44 | testl $0x20, %ecx // If count >= 32 |
| 45 | jnz 2f // goto 2 |
| 46 | testl $0x1f, %ecx // If count == 0 |
| 47 | jz 1f // goto 1 |
| 48 | |
| 49 | pushl %ebx |
| 50 | movl %eax, %ebx // copy low |
| 51 | shll %cl, %eax // left shift low by count |
| 52 | shll %cl, %edx // left shift high by count |
| 53 | neg %cl |
| 54 | shrl %cl, %ebx // right shift low by 32 - count |
| 55 | orl %ebx, %edx // or the result into the high word |
| 56 | popl %ebx |
| 57 | 1: ret |
| 58 | |
| 59 | 2: movl %eax, %edx // Move low to high |
| 60 | xorl %eax, %eax // clear low |
| 61 | shll %cl, %edx // shift high by count - 32 |
| 62 | ret |
| 63 | |
| 64 | #endif // __SSE2__ |
| 65 | #endif // __i386__ |