Daniel Boulby | 318e7a5 | 2022-10-21 20:20:52 +0100 | [diff] [blame] | 1 | //===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements __lshrdi3 for the compiler_rt library. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
Sandrine Bailleux | b5c129e | 2018-10-31 13:37:42 +0100 | [diff] [blame] | 12 | |
| 13 | #include "int_lib.h" |
| 14 | |
Daniel Boulby | 318e7a5 | 2022-10-21 20:20:52 +0100 | [diff] [blame] | 15 | // Returns: logical a >> b |
Sandrine Bailleux | b5c129e | 2018-10-31 13:37:42 +0100 | [diff] [blame] | 16 | |
Daniel Boulby | 318e7a5 | 2022-10-21 20:20:52 +0100 | [diff] [blame] | 17 | // Precondition: 0 <= b < bits_in_dword |
Sandrine Bailleux | b5c129e | 2018-10-31 13:37:42 +0100 | [diff] [blame] | 18 | |
Daniel Boulby | 318e7a5 | 2022-10-21 20:20:52 +0100 | [diff] [blame] | 19 | COMPILER_RT_ABI di_int __lshrdi3(di_int a, int b) { |
| 20 | const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT); |
| 21 | udwords input; |
| 22 | udwords result; |
| 23 | input.all = a; |
| 24 | if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ { |
| 25 | result.s.high = 0; |
| 26 | result.s.low = input.s.high >> (b - bits_in_word); |
| 27 | } else /* 0 <= b < bits_in_word */ { |
| 28 | if (b == 0) |
| 29 | return a; |
| 30 | result.s.high = input.s.high >> b; |
| 31 | result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b); |
| 32 | } |
| 33 | return result.all; |
Sandrine Bailleux | b5c129e | 2018-10-31 13:37:42 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | #if defined(__ARM_EABI__) |
Daniel Boulby | 318e7a5 | 2022-10-21 20:20:52 +0100 | [diff] [blame] | 37 | COMPILER_RT_ALIAS(__lshrdi3, __aeabi_llsr) |
Sandrine Bailleux | b5c129e | 2018-10-31 13:37:42 +0100 | [diff] [blame] | 38 | #endif |