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