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