]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Leaf math worker functions that require 64-bit arithmetic support from the\r | |
3 | compiler.\r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation<BR>\r | |
6 | All rights reserved. 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 | Module Name: Math64.c\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | UINT64\r | |
19 | EFIAPI\r | |
20 | InternalMathLShiftU64 (\r | |
21 | IN UINT64 Operand,\r | |
22 | IN UINTN Count\r | |
23 | )\r | |
24 | {\r | |
25 | return Operand << Count;\r | |
26 | }\r | |
27 | \r | |
28 | UINT64\r | |
29 | EFIAPI\r | |
30 | InternalMathRShiftU64 (\r | |
31 | IN UINT64 Operand,\r | |
32 | IN UINTN Count\r | |
33 | )\r | |
34 | {\r | |
35 | return Operand >> Count;\r | |
36 | }\r | |
37 | \r | |
38 | UINT64\r | |
39 | EFIAPI\r | |
40 | InternalMathARShiftU64 (\r | |
41 | IN UINT64 Operand,\r | |
42 | IN UINTN Count\r | |
43 | )\r | |
44 | {\r | |
45 | //\r | |
46 | // Test if this compiler supports arithmetic shift\r | |
47 | //\r | |
48 | if ((((-1) << (sizeof (-1) * 8 - 1)) >> (sizeof (-1) * 8 - 1)) == -1) {\r | |
49 | //\r | |
50 | // Arithmetic shift is supported\r | |
51 | //\r | |
52 | return (UINT64)((INT64)Operand >> Count);\r | |
53 | }\r | |
54 | \r | |
55 | //\r | |
56 | // Arithmetic is not supported\r | |
57 | //\r | |
58 | return (Operand >> Count) |\r | |
59 | ((INTN)Operand < 0 ? ~((UINTN)-1 >> Count) : 0);\r | |
60 | }\r | |
61 | \r | |
62 | UINT64\r | |
63 | EFIAPI\r | |
64 | InternalMathLRotU64 (\r | |
65 | IN UINT64 Operand,\r | |
66 | IN UINTN Count\r | |
67 | )\r | |
68 | {\r | |
69 | return (Operand << Count) | (Operand >> (64 - Count));\r | |
70 | }\r | |
71 | \r | |
72 | UINT64\r | |
73 | EFIAPI\r | |
74 | InternalMathRRotU64 (\r | |
75 | IN UINT64 Operand,\r | |
76 | IN UINTN Count\r | |
77 | )\r | |
78 | {\r | |
79 | return (Operand >> Count) | (Operand << (64 - Count));\r | |
80 | }\r | |
81 | \r | |
82 | UINT64\r | |
83 | EFIAPI\r | |
84 | InternalMathSwapBytes64 (\r | |
85 | IN UINT64 Operand\r | |
86 | )\r | |
87 | {\r | |
88 | return (UINT64)(\r | |
89 | ((UINT64)SwapBytes32 ((UINT32)Operand) << 32) |\r | |
90 | ((UINT64)SwapBytes32 ((UINT32)(Operand >> 32)))\r | |
91 | );\r | |
92 | }\r | |
93 | \r | |
94 | UINT64\r | |
95 | EFIAPI\r | |
96 | InternalMathMultU64x32 (\r | |
97 | IN UINT64 Multiplicand,\r | |
98 | IN UINT32 Multiplier\r | |
99 | )\r | |
100 | {\r | |
101 | return Multiplicand * Multiplier;\r | |
102 | }\r | |
103 | \r | |
104 | UINT64\r | |
105 | EFIAPI\r | |
106 | InternalMathMultU64x64 (\r | |
107 | IN UINT64 Multiplicand,\r | |
108 | IN UINT64 Multiplier\r | |
109 | )\r | |
110 | {\r | |
111 | return Multiplicand * Multiplier;\r | |
112 | }\r | |
113 | \r | |
114 | UINT64\r | |
115 | EFIAPI\r | |
116 | InternalMathDivU64x32 (\r | |
117 | IN UINT64 Dividend,\r | |
118 | IN UINT32 Divisor\r | |
119 | )\r | |
120 | {\r | |
121 | return Dividend / Divisor;\r | |
122 | }\r | |
123 | \r | |
124 | UINT64\r | |
125 | EFIAPI\r | |
126 | InternalMathModU64x32 (\r | |
127 | IN UINT64 Dividend,\r | |
128 | IN UINT32 Divisor\r | |
129 | )\r | |
130 | {\r | |
131 | return Dividend % Divisor;\r | |
132 | }\r | |
133 | \r | |
134 | UINT64\r | |
135 | EFIAPI\r | |
136 | InternalMathDivRemU64x32 (\r | |
137 | IN UINT64 Dividend,\r | |
138 | IN UINT32 Divisor,\r | |
139 | OUT UINT32 *Remainder\r | |
140 | )\r | |
141 | {\r | |
142 | if (Remainder != NULL) {\r | |
143 | *Remainder = (UINT32)(Dividend % Divisor);\r | |
144 | }\r | |
145 | return Dividend / Divisor;\r | |
146 | }\r | |
147 | \r | |
148 | UINT64\r | |
149 | EFIAPI\r | |
150 | InternalMathDivRemU64x64 (\r | |
151 | IN UINT64 Dividend,\r | |
152 | IN UINT64 Divisor,\r | |
153 | OUT UINT64 *Remainder\r | |
154 | )\r | |
155 | {\r | |
156 | if (Remainder != NULL) {\r | |
157 | *Remainder = Dividend % Divisor;\r | |
158 | }\r | |
159 | return Dividend / Divisor;\r | |
160 | }\r | |
161 | \r | |
162 | INT64\r | |
163 | EFIAPI\r | |
164 | InternalMathDivRemS64x64 (\r | |
165 | IN INT64 Dividend,\r | |
166 | IN INT64 Divisor,\r | |
167 | OUT INT64 *Remainder\r | |
168 | )\r | |
169 | {\r | |
170 | if (Remainder != NULL) {\r | |
171 | *Remainder = Dividend % Divisor;\r | |
172 | }\r | |
173 | return Dividend / Divisor;\r | |
174 | }\r |