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