]>
Commit | Line | Data |
---|---|---|
2ef2b01e A |
1 | /** @file |
2 | ||
3 | Copyright (c) 2008-2009, Apple Inc. All rights reserved. | |
4 | ||
5 | All rights reserved. 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 <Base.h> | |
58 | #include "Llvm_int_lib.h" | |
59 | ||
60 | ||
61 | // Returns: a * b | |
62 | ||
63 | static | |
64 | INT64 | |
65 | __muldsi3(UINT32 a, UINT32 b) | |
66 | { | |
67 | dwords r; | |
68 | const int bits_in_word_2 = (int)(sizeof(INT32) * CHAR_BIT) / 2; | |
69 | const UINT32 lower_mask = (UINT32)~0 >> bits_in_word_2; | |
70 | r.low = (a & lower_mask) * (b & lower_mask); | |
71 | UINT32 t = r.low >> bits_in_word_2; | |
72 | r.low &= lower_mask; | |
73 | t += (a >> bits_in_word_2) * (b & lower_mask); | |
74 | r.low += (t & lower_mask) << bits_in_word_2; | |
75 | r.high = t >> bits_in_word_2; | |
76 | t = r.low >> bits_in_word_2; | |
77 | r.low &= lower_mask; | |
78 | t += (b >> bits_in_word_2) * (a & lower_mask); | |
79 | r.low += (t & lower_mask) << bits_in_word_2; | |
80 | r.high += t >> bits_in_word_2; | |
81 | r.high += (a >> bits_in_word_2) * (b >> bits_in_word_2); | |
82 | return r.all; | |
83 | } | |
84 | ||
85 | // Returns: a * b | |
86 | ||
87 | INT64 | |
88 | __muldi3(INT64 a, INT64 b) | |
89 | { | |
90 | dwords x; | |
91 | x.all = a; | |
92 | dwords y; | |
93 | y.all = b; | |
94 | dwords r; | |
95 | r.all = __muldsi3(x.low, y.low); | |
96 | r.high += x.high * y.low + x.low * y.high; | |
97 | return r.all; | |
98 | } |