2009-08-07 20:30:09 +00:00
|
|
|
//===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===//
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
// This file implements __ashrdi3 for the compiler_rt library.
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
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
|
|
|
|
2020-04-22 20:25:22 +02:00
|
|
|
COMPILER_RT_ABI di_int __ashrdi3(di_int a, int b) {
|
2009-06-26 16:47:03 +00:00
|
|
|
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-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-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;
|
2023-08-26 20:35:30 +02:00
|
|
|
result.s.low =
|
|
|
|
((su_int)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__)
|
2017-10-03 21:25:07 +00:00
|
|
|
COMPILER_RT_ALIAS(__ashrdi3, __aeabi_lasr)
|
2017-05-16 16:41:37 +00:00
|
|
|
#endif
|