blob: 62eb1a4a02f4c5e777aa9170b19efda6fb122ee5 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===//
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 __lshrdi3 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15
16// Returns: logical a >> b
17
18// Precondition: 0 <= b < bits_in_dword
19
20di_int
21__lshrdi3(di_int a, si_int b)
22{
23 const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
24 udwords input;
25 udwords result;
26 input.all = a;
27 if (b & bits_in_word) // bits_in_word <= b < bits_in_dword
28 {
29 result.high = 0;
30 result.low = input.high >> (b - bits_in_word);
31 }
32 else // 0 <= b < bits_in_word
33 {
34 if (b == 0)
35 return a;
36 result.high = input.high >> b;
37 result.low = (input.high << (bits_in_word - b)) | (input.low >> b);
38 }
39 return result.all;
40}