Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | //===-- lshrti3.c - Implement __lshrti3 -----------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements __lshrti3 for the compiler_rt library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #if __x86_64 |
| 15 | |
| 16 | #include "int_lib.h" |
| 17 | |
| 18 | // Returns: logical a >> b |
| 19 | |
| 20 | // Precondition: 0 <= b < bits_in_tword |
| 21 | |
| 22 | ti_int |
| 23 | __lshrti3(ti_int a, si_int b) |
| 24 | { |
| 25 | const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT); |
| 26 | utwords input; |
| 27 | utwords result; |
| 28 | input.all = a; |
| 29 | if (b & bits_in_dword) // bits_in_dword <= b < bits_in_tword |
| 30 | { |
| 31 | result.high = 0; |
| 32 | result.low = input.high >> (b - bits_in_dword); |
| 33 | } |
| 34 | else // 0 <= b < bits_in_dword |
| 35 | { |
| 36 | if (b == 0) |
| 37 | return a; |
| 38 | result.high = input.high >> b; |
| 39 | result.low = (input.high << (bits_in_dword - b)) | (input.low >> b); |
| 40 | } |
| 41 | return result.all; |
| 42 | } |
| 43 | |
| 44 | #endif |