blob: e9e24c31d7a0e37408e561e21e8c793b6fc33892 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- ashldi3.c - Implement __ashldi3 -----------------------------------===//
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 __ashldi3 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15
16// Returns: a << b
17
18// Precondition: 0 <= b < bits_in_dword
19
20di_int
21__ashldi3(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.low = 0;
30 result.high = input.low << (b - bits_in_word);
31 }
32 else // 0 <= b < bits_in_word
33 {
34 if (b == 0)
35 return a;
36 result.low = input.low << b;
37 result.high = (input.high << b) | (input.low >> (bits_in_word - b));
38 }
39 return result.all;
40}