blob: 99258cee1083dc087fe10786d44c08a4acb9992c [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- 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
22ti_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