2009-08-07 20:30:09 +00:00
|
|
|
/*===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-16 22:13:33 +00:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-08-07 20:30:09 +00:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __ashrdi3 for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-26 16:47:03 +00:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
/* Returns: arithmetic a >> b */
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
/* Precondition: 0 <= b < bits_in_dword */
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2011-04-19 17:52:09 +00:00
|
|
|
COMPILER_RT_ABI di_int
|
2009-06-26 16:47:03 +00:00
|
|
|
__ashrdi3(di_int a, si_int b)
|
|
|
|
{
|
|
|
|
const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
|
|
|
|
dwords input;
|
|
|
|
dwords result;
|
|
|
|
input.all = a;
|
2009-08-07 20:30:09 +00:00
|
|
|
if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
|
2009-06-26 16:47:03 +00:00
|
|
|
{
|
2009-08-09 18:41:02 +00:00
|
|
|
/* result.s.high = input.s.high < 0 ? -1 : 0 */
|
|
|
|
result.s.high = input.s.high >> (bits_in_word - 1);
|
|
|
|
result.s.low = input.s.high >> (b - bits_in_word);
|
2009-06-26 16:47:03 +00:00
|
|
|
}
|
2009-08-07 20:30:09 +00:00
|
|
|
else /* 0 <= b < bits_in_word */
|
2009-06-26 16:47:03 +00:00
|
|
|
{
|
|
|
|
if (b == 0)
|
|
|
|
return a;
|
2009-08-09 18:41:02 +00:00
|
|
|
result.s.high = input.s.high >> b;
|
|
|
|
result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
|
2009-06-26 16:47:03 +00:00
|
|
|
}
|
|
|
|
return result.all;
|
|
|
|
}
|
2017-05-16 16:41:37 +00:00
|
|
|
|
|
|
|
#if defined(__ARM_EABI__)
|
|
|
|
AEABI_RTABI di_int __aeabi_lasr(di_int a, si_int b) {
|
|
|
|
return __ashrdi3(a, b);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|