11.1Sjoerg/*===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===
21.1Sjoerg *
31.1Sjoerg *                     The LLVM Compiler Infrastructure
41.1Sjoerg *
51.1Sjoerg * This file is dual licensed under the MIT and the University of Illinois Open
61.1Sjoerg * Source Licenses. See LICENSE.TXT for details.
71.1Sjoerg *
81.1Sjoerg * ===----------------------------------------------------------------------===
91.1Sjoerg *
101.1Sjoerg * This file implements __ashrdi3 for the compiler_rt library.
111.1Sjoerg *
121.1Sjoerg * ===----------------------------------------------------------------------===
131.1Sjoerg */
141.1Sjoerg
151.1Sjoerg#include "int_lib.h"
161.1Sjoerg
171.1Sjoerg/* Returns: arithmetic a >> b */
181.1Sjoerg
191.1Sjoerg/* Precondition:  0 <= b < bits_in_dword */
201.1Sjoerg
211.1SjoergCOMPILER_RT_ABI di_int
221.1Sjoerg__ashrdi3(di_int a, si_int b)
231.1Sjoerg{
241.1Sjoerg    const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
251.1Sjoerg    dwords input;
261.1Sjoerg    dwords result;
271.1Sjoerg    input.all = a;
281.1Sjoerg    if (b & bits_in_word)  /* bits_in_word <= b < bits_in_dword */
291.1Sjoerg    {
301.1Sjoerg        /* result.s.high = input.s.high < 0 ? -1 : 0 */
311.1Sjoerg        result.s.high = input.s.high >> (bits_in_word - 1);
321.1Sjoerg        result.s.low = input.s.high >> (b - bits_in_word);
331.1Sjoerg    }
341.1Sjoerg    else  /* 0 <= b < bits_in_word */
351.1Sjoerg    {
361.1Sjoerg        if (b == 0)
371.1Sjoerg            return a;
381.1Sjoerg        result.s.high  = input.s.high >> b;
391.1Sjoerg        result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
401.1Sjoerg    }
411.1Sjoerg    return result.all;
421.1Sjoerg}
431.2Srin
441.2Srin#if defined(__ARM_EABI__)
451.3SrinAEABI_RTABI di_int __aeabi_lasr(di_int a, si_int b) COMPILER_RT_ALIAS(__ashrdi3);
461.2Srin#endif
47