xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/lshrdi3.c (revision e25152834cdf3b353892835a4f3b157e066a8ed4)
10b57cec5SDimitry Andric //===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements __lshrdi3 for the compiler_rt library.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "int_lib.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric // Returns: logical a >> b
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric // Precondition:  0 <= b < bits_in_dword
180b57cec5SDimitry Andric 
__lshrdi3(di_int a,int b)19*5ffd83dbSDimitry Andric COMPILER_RT_ABI di_int __lshrdi3(di_int a, int b) {
200b57cec5SDimitry Andric   const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
210b57cec5SDimitry Andric   udwords input;
220b57cec5SDimitry Andric   udwords result;
230b57cec5SDimitry Andric   input.all = a;
240b57cec5SDimitry Andric   if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ {
250b57cec5SDimitry Andric     result.s.high = 0;
260b57cec5SDimitry Andric     result.s.low = input.s.high >> (b - bits_in_word);
270b57cec5SDimitry Andric   } else /* 0 <= b < bits_in_word */ {
280b57cec5SDimitry Andric     if (b == 0)
290b57cec5SDimitry Andric       return a;
300b57cec5SDimitry Andric     result.s.high = input.s.high >> b;
310b57cec5SDimitry Andric     result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
320b57cec5SDimitry Andric   }
330b57cec5SDimitry Andric   return result.all;
340b57cec5SDimitry Andric }
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric #if defined(__ARM_EABI__)
370b57cec5SDimitry Andric COMPILER_RT_ALIAS(__lshrdi3, __aeabi_llsr)
380b57cec5SDimitry Andric #endif
39