Home | History | Annotate | Line # | Download | only in builtins
      1  1.1  joerg /* ===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===
      2  1.1  joerg  *
      3  1.1  joerg  *                     The LLVM Compiler Infrastructure
      4  1.1  joerg  *
      5  1.1  joerg  * This file is dual licensed under the MIT and the University of Illinois Open
      6  1.1  joerg  * Source Licenses. See LICENSE.TXT for details.
      7  1.1  joerg  *
      8  1.1  joerg  * ===----------------------------------------------------------------------===
      9  1.1  joerg  *
     10  1.1  joerg  * This file implements __lshrdi3 for the compiler_rt library.
     11  1.1  joerg  *
     12  1.1  joerg  * ===----------------------------------------------------------------------===
     13  1.1  joerg  */
     14  1.1  joerg 
     15  1.1  joerg #include "int_lib.h"
     16  1.1  joerg 
     17  1.1  joerg /* Returns: logical a >> b */
     18  1.1  joerg 
     19  1.1  joerg /* Precondition:  0 <= b < bits_in_dword */
     20  1.1  joerg 
     21  1.1  joerg COMPILER_RT_ABI di_int
     22  1.1  joerg __lshrdi3(di_int a, si_int b)
     23  1.1  joerg {
     24  1.1  joerg     const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
     25  1.1  joerg     udwords input;
     26  1.1  joerg     udwords result;
     27  1.1  joerg     input.all = a;
     28  1.1  joerg     if (b & bits_in_word)  /* bits_in_word <= b < bits_in_dword */
     29  1.1  joerg     {
     30  1.1  joerg         result.s.high = 0;
     31  1.1  joerg         result.s.low = input.s.high >> (b - bits_in_word);
     32  1.1  joerg     }
     33  1.1  joerg     else  /* 0 <= b < bits_in_word */
     34  1.1  joerg     {
     35  1.1  joerg         if (b == 0)
     36  1.1  joerg             return a;
     37  1.1  joerg         result.s.high  = input.s.high >> b;
     38  1.1  joerg         result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
     39  1.1  joerg     }
     40  1.1  joerg     return result.all;
     41  1.1  joerg }
     42  1.2    rin 
     43  1.2    rin #if defined(__ARM_EABI__)
     44  1.3    rin AEABI_RTABI di_int __aeabi_llsr(di_int a, si_int b) COMPILER_RT_ALIAS(__lshrdi3);
     45  1.2    rin #endif
     46