1 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open 2 1.1 joerg // Source Licenses. See LICENSE.TXT for details. 3 1.1 joerg 4 1.1 joerg #include "../assembly.h" 5 1.1 joerg 6 1.1 joerg // di_int __ashrdi3(di_int input, int count); 7 1.1 joerg 8 1.1 joerg #ifdef __i386__ 9 1.1 joerg #ifdef __SSE2__ 10 1.1 joerg 11 1.1 joerg .text 12 1.1.1.2 joerg .balign 4 13 1.1 joerg DEFINE_COMPILERRT_FUNCTION(__ashrdi3) 14 1.1 joerg movd 12(%esp), %xmm2 // Load count 15 1.1 joerg movl 8(%esp), %eax 16 1.1 joerg #ifndef TRUST_CALLERS_USE_64_BIT_STORES 17 1.1 joerg movd 4(%esp), %xmm0 18 1.1 joerg movd 8(%esp), %xmm1 19 1.1 joerg punpckldq %xmm1, %xmm0 // Load input 20 1.1 joerg #else 21 1.1 joerg movq 4(%esp), %xmm0 // Load input 22 1.1 joerg #endif 23 1.1 joerg 24 1.1 joerg psrlq %xmm2, %xmm0 // unsigned shift input by count 25 1.1 joerg 26 1.1 joerg testl %eax, %eax // check the sign-bit of the input 27 1.1 joerg jns 1f // early out for positive inputs 28 1.1 joerg 29 1.1 joerg // If the input is negative, we need to construct the shifted sign bit 30 1.1 joerg // to or into the result, as xmm does not have a signed right shift. 31 1.1 joerg pcmpeqb %xmm1, %xmm1 // -1ULL 32 1.1 joerg psrlq $58, %xmm1 // 0x3f 33 1.1 joerg pandn %xmm1, %xmm2 // 63 - count 34 1.1 joerg pcmpeqb %xmm1, %xmm1 // -1ULL 35 1.1 joerg psubq %xmm1, %xmm2 // 64 - count 36 1.1 joerg psllq %xmm2, %xmm1 // -1 << (64 - count) = leading sign bits 37 1.1 joerg por %xmm1, %xmm0 38 1.1 joerg 39 1.1 joerg // Move the result back to the general purpose registers and return 40 1.1 joerg 1: movd %xmm0, %eax 41 1.1 joerg psrlq $32, %xmm0 42 1.1 joerg movd %xmm0, %edx 43 1.1 joerg ret 44 1.1 joerg END_COMPILERRT_FUNCTION(__ashrdi3) 45 1.1 joerg 46 1.1 joerg #else // Use GPRs instead of SSE2 instructions, if they aren't available. 47 1.1 joerg 48 1.1 joerg .text 49 1.1.1.2 joerg .balign 4 50 1.1 joerg DEFINE_COMPILERRT_FUNCTION(__ashrdi3) 51 1.1 joerg movl 12(%esp), %ecx // Load count 52 1.1 joerg movl 8(%esp), %edx // Load high 53 1.1 joerg movl 4(%esp), %eax // Load low 54 1.1 joerg 55 1.1 joerg testl $0x20, %ecx // If count >= 32 56 1.1 joerg jnz 1f // goto 1 57 1.1 joerg 58 1.1 joerg shrdl %cl, %edx, %eax // right shift low by count 59 1.1 joerg sarl %cl, %edx // right shift high by count 60 1.1 joerg ret 61 1.1 joerg 62 1.1 joerg 1: movl %edx, %eax // Move high to low 63 1.1 joerg sarl $31, %edx // clear high 64 1.1 joerg sarl %cl, %eax // shift low by count - 32 65 1.1 joerg ret 66 1.1 joerg END_COMPILERRT_FUNCTION(__ashrdi3) 67 1.1 joerg 68 1.1 joerg #endif // __SSE2__ 69 1.1 joerg #endif // __i386__ 70