1214152Sed/*===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===
2214152Sed *
3214152Sed *                     The LLVM Compiler Infrastructure
4214152Sed *
5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open
6222656Sed * Source Licenses. See LICENSE.TXT for details.
7214152Sed *
8214152Sed * ===----------------------------------------------------------------------===
9214152Sed *
10214152Sed * This file implements __ashrdi3 for the compiler_rt library.
11214152Sed *
12214152Sed * ===----------------------------------------------------------------------===
13214152Sed */
14214152Sed
15214152Sed#include "int_lib.h"
16214152Sed
17214152Sed/* Returns: arithmetic a >> b */
18214152Sed
19214152Sed/* Precondition:  0 <= b < bits_in_dword */
20214152Sed
21239138SandrewARM_EABI_FNALIAS(lasr, ashrdi3)
22222656Sed
23222656SedCOMPILER_RT_ABI di_int
24214152Sed__ashrdi3(di_int a, si_int b)
25214152Sed{
26214152Sed    const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
27214152Sed    dwords input;
28214152Sed    dwords result;
29214152Sed    input.all = a;
30214152Sed    if (b & bits_in_word)  /* bits_in_word <= b < bits_in_dword */
31214152Sed    {
32214152Sed        /* result.s.high = input.s.high < 0 ? -1 : 0 */
33214152Sed        result.s.high = input.s.high >> (bits_in_word - 1);
34214152Sed        result.s.low = input.s.high >> (b - bits_in_word);
35214152Sed    }
36214152Sed    else  /* 0 <= b < bits_in_word */
37214152Sed    {
38214152Sed        if (b == 0)
39214152Sed            return a;
40214152Sed        result.s.high  = input.s.high >> b;
41214152Sed        result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
42214152Sed    }
43214152Sed    return result.all;
44214152Sed}
45