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