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