]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /** @file\r |
2 | Integer Arithmetic Run-time support functions for GCC.\r | |
3 | The integer arithmetic routines are used on platforms that don't provide\r | |
4 | hardware support for arithmetic operations on some modes..\r | |
5 | \r | |
6 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
7 | This program and the accompanying materials are licensed and made available\r | |
8 | under the terms and conditions of the BSD License which accompanies this\r | |
9 | distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | #include <Uefi.h>\r | |
2aa62f2b | 17 | #include <Library/DebugLib.h>\r |
18 | #include <sys/EfiCdefs.h>\r | |
19 | \r | |
20 | #include <Library/BaseLib.h>\r | |
21 | \r | |
22 | // Shift Datum left by Count bits.\r | |
23 | // ===========================================================================\r | |
53e1e5c6 | 24 | int __ashlsi3(int Datum, int Count)\r |
25 | {\r | |
26 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
27 | return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r | |
28 | }\r | |
2aa62f2b | 29 | \r |
53e1e5c6 | 30 | long __ashldi3(long Datum, int Count)\r |
2aa62f2b | 31 | {\r |
53e1e5c6 | 32 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r |
33 | return (long) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r | |
2aa62f2b | 34 | }\r |
35 | \r | |
53e1e5c6 | 36 | long long __ashlti3(long long Datum, int Count)\r |
37 | {\r | |
38 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
39 | return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r | |
40 | }\r | |
2aa62f2b | 41 | \r |
42 | // Arithmetically shift Datum right by Count bits.\r | |
43 | // ===========================================================================\r | |
53e1e5c6 | 44 | int __ashrsi3(int Datum, int Count)\r |
45 | {\r | |
46 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
47 | return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r | |
48 | }\r | |
2aa62f2b | 49 | \r |
53e1e5c6 | 50 | long __ashrdi3(long Datum, int Count)\r |
2aa62f2b | 51 | {\r |
53e1e5c6 | 52 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r |
53 | return (long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r | |
2aa62f2b | 54 | }\r |
55 | \r | |
53e1e5c6 | 56 | long long __ashrti3(long long Datum, int Count)\r |
57 | {\r | |
58 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
59 | return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r | |
60 | }\r | |
2aa62f2b | 61 | \r |
62 | // Return the quotient of the signed division of Dividend and Divisor\r | |
63 | // ===========================================================================\r | |
53e1e5c6 | 64 | int __divsi3(int Dividend, int Divisor)\r |
65 | {\r | |
66 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
67 | return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r | |
68 | }\r | |
2aa62f2b | 69 | \r |
70 | INT64 __divdi3(INT64 Dividend, INT64 Divisor)\r | |
71 | {\r | |
72 | INT64 Quotient;\r | |
73 | \r | |
74 | Quotient = DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r | |
53e1e5c6 | 75 | DEBUG((DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient));\r |
2aa62f2b | 76 | \r |
77 | return Quotient;\r | |
78 | }\r | |
79 | \r | |
53e1e5c6 | 80 | long long __divti3(long long Dividend, long long Divisor)\r |
81 | {\r | |
82 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
83 | return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r | |
84 | }\r | |
2aa62f2b | 85 | \r |
86 | // Logically shift Datum right by Count bits\r | |
87 | // ===========================================================================\r | |
53e1e5c6 | 88 | int __lshrsi3(int Datum, int Count)\r |
89 | {\r | |
90 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
91 | return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r | |
92 | }\r | |
2aa62f2b | 93 | \r |
53e1e5c6 | 94 | long __lshrdi3(int Datum, int Count)\r |
2aa62f2b | 95 | {\r |
53e1e5c6 | 96 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r |
97 | return (long) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r | |
2aa62f2b | 98 | }\r |
99 | \r | |
53e1e5c6 | 100 | long long __lshrti3(int Datum, int Count)\r |
101 | {\r | |
102 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
103 | return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r | |
104 | }\r | |
2aa62f2b | 105 | \r |
106 | // Return the remainder of the signed division of Dividend and Divisor\r | |
107 | // ===========================================================================\r | |
53e1e5c6 | 108 | int __modsi3(int Dividend, int Divisor)\r |
109 | {\r | |
110 | INT64 Remainder;\r | |
2aa62f2b | 111 | \r |
53e1e5c6 | 112 | (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r |
113 | DEBUG((DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder));\r | |
2aa62f2b | 114 | \r |
53e1e5c6 | 115 | return (int) Remainder;\r |
116 | }\r | |
2aa62f2b | 117 | \r |
118 | INT64 __moddi3(INT64 Dividend, INT64 Divisor)\r | |
119 | {\r | |
120 | INT64 Remainder;\r | |
121 | \r | |
122 | (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r | |
53e1e5c6 | 123 | DEBUG((DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));\r |
2aa62f2b | 124 | \r |
125 | return Remainder;\r | |
126 | }\r | |
127 | \r | |
53e1e5c6 | 128 | long long __modti3(long long Dividend, long long Divisor)\r |
129 | {\r | |
130 | INT64 Remainder;\r | |
2aa62f2b | 131 | \r |
53e1e5c6 | 132 | (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r |
133 | DEBUG((DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));\r | |
2aa62f2b | 134 | \r |
53e1e5c6 | 135 | return (long long) Remainder;\r |
136 | }\r | |
2aa62f2b | 137 | \r |
138 | // These functions return the product of the Multiplicand and Multiplier.\r | |
139 | // ===========================================================================\r | |
53e1e5c6 | 140 | long long __multi3(long long Multiplicand, long long Multiplier)\r |
141 | {\r | |
142 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
143 | return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);\r | |
144 | }\r | |
2aa62f2b | 145 | \r |
146 | // Return the quotient of the unsigned division of a and b.\r | |
147 | // ===========================================================================\r | |
53e1e5c6 | 148 | unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)\r |
149 | {\r | |
150 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
151 | return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r | |
152 | }\r | |
2aa62f2b | 153 | \r |
53e1e5c6 | 154 | unsigned long __udivdi3(unsigned long Dividend, unsigned long Divisor)\r |
2aa62f2b | 155 | {\r |
53e1e5c6 | 156 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r |
157 | return (long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r | |
2aa62f2b | 158 | }\r |
159 | \r | |
53e1e5c6 | 160 | unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)\r |
161 | {\r | |
162 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r | |
163 | return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r | |
164 | }\r | |
2aa62f2b | 165 | \r |
166 | // ===========================================================================\r | |
53e1e5c6 | 167 | unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)\r |
168 | {\r | |
169 | UINT64 Remainder;\r | |
2aa62f2b | 170 | \r |
53e1e5c6 | 171 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r |
172 | (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r | |
2aa62f2b | 173 | \r |
53e1e5c6 | 174 | return (unsigned int) Remainder;\r |
175 | }\r | |
2aa62f2b | 176 | \r |
53e1e5c6 | 177 | unsigned long __umoddi3(unsigned long Dividend, unsigned long Divisor)\r |
2aa62f2b | 178 | {\r |
179 | UINT64 Remainder;\r | |
180 | \r | |
53e1e5c6 | 181 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r |
2aa62f2b | 182 | (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r |
183 | \r | |
53e1e5c6 | 184 | return (unsigned long) Remainder;\r |
2aa62f2b | 185 | }\r |
186 | \r | |
53e1e5c6 | 187 | unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)\r |
188 | {\r | |
189 | UINT64 Remainder;\r | |
2aa62f2b | 190 | \r |
53e1e5c6 | 191 | DEBUG((DEBUG_INFO, "%a:\n", __func__));\r |
192 | (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r | |
2aa62f2b | 193 | \r |
53e1e5c6 | 194 | return (unsigned long long) Remainder;\r |
195 | }\r |