1/** @file
2
3  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4
5  This program and the accompanying materials
6  are licensed and made available under the terms and conditions of the BSD License
7  which accompanies this distribution.  The full text of the license may be found at
8  http://opensource.org/licenses/bsd-license.php
9
10  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14/**
15  University of Illinois/NCSA
16  Open Source License
17
18  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
19  All rights reserved.
20
21  Developed by:
22
23      LLVM Team
24
25      University of Illinois at Urbana-Champaign
26
27      http://llvm.org
28
29  Permission is hereby granted, free of charge, to any person obtaining a copy of
30  this software and associated documentation files (the "Software"), to deal with
31  the Software without restriction, including without limitation the rights to
32  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
33  of the Software, and to permit persons to whom the Software is furnished to do
34  so, subject to the following conditions:
35
36      * Redistributions of source code must retain the above copyright notice,
37        this list of conditions and the following disclaimers.
38
39      * Redistributions in binary form must reproduce the above copyright notice,
40        this list of conditions and the following disclaimers in the
41        documentation and/or other materials provided with the distribution.
42
43      * Neither the names of the LLVM Team, University of Illinois at
44        Urbana-Champaign, nor the names of its contributors may be used to
45        endorse or promote products derived from this Software without specific
46        prior written permission.
47
48  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
50  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
51  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
53  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
54  SOFTWARE.
55**/
56
57#include "Llvm_int_lib.h"
58
59// Returns: a << b
60
61// Precondition:  0 <= b < bits_in_dword
62
63INT64
64__ashldi3(INT64 a, INT32 b)
65{
66    const int bits_in_word = (int)(sizeof(INT32) * CHAR_BIT);
67    dwords input;
68    dwords result;
69    input.all = a;
70    if (b & bits_in_word)  // bits_in_word <= b < bits_in_dword
71    {
72        result.low = 0;
73        result.high = input.low << (b - bits_in_word);
74    }
75    else  // 0 <= b < bits_in_word
76    {
77        if (b == 0)
78            return a;
79        result.low  = input.low << b;
80        result.high = (input.high << b) | (input.low >> (bits_in_word - b));
81    }
82    return result.all;
83}
84