TianoCore EDK2 master
Loading...
Searching...
No Matches
Math64.c
Go to the documentation of this file.
1
10#include "BaseLibInternals.h"
11
25UINT64
26EFIAPI
28 IN UINT64 Operand,
29 IN UINTN Count
30 )
31{
32 return Operand << Count;
33}
34
48UINT64
49EFIAPI
51 IN UINT64 Operand,
52 IN UINTN Count
53 )
54{
55 return Operand >> Count;
56}
57
71UINT64
72EFIAPI
74 IN UINT64 Operand,
75 IN UINTN Count
76 )
77{
78 INTN TestValue;
79
80 //
81 // Test if this compiler supports arithmetic shift
82 //
83 TestValue = (INTN)((INT64)(1ULL << 63) >> 63);
84 if (TestValue == -1) {
85 //
86 // Arithmetic shift is supported
87 //
88 return (UINT64)((INT64)Operand >> Count);
89 }
90
91 //
92 // Arithmetic is not supported
93 //
94 return (Operand >> Count) |
95 ((INTN)Operand < 0 ? ~((UINTN)-1 >> Count) : 0);
96}
97
112UINT64
113EFIAPI
115 IN UINT64 Operand,
116 IN UINTN Count
117 )
118{
119 return (Operand << Count) | (Operand >> (64 - Count));
120}
121
136UINT64
137EFIAPI
139 IN UINT64 Operand,
140 IN UINTN Count
141 )
142{
143 return (Operand >> Count) | (Operand << (64 - Count));
144}
145
158UINT64
159EFIAPI
161 IN UINT64 Operand
162 )
163{
164 UINT64 LowerBytes;
165 UINT64 HigherBytes;
166
167 LowerBytes = (UINT64)SwapBytes32 ((UINT32)Operand);
168 HigherBytes = (UINT64)SwapBytes32 ((UINT32)(Operand >> 32));
169
170 return (LowerBytes << 32 | HigherBytes);
171}
172
187UINT64
188EFIAPI
190 IN UINT64 Multiplicand,
191 IN UINT32 Multiplier
192 )
193{
194 return Multiplicand * Multiplier;
195}
196
211UINT64
212EFIAPI
214 IN UINT64 Multiplicand,
215 IN UINT64 Multiplier
216 )
217{
218 return Multiplicand * Multiplier;
219}
220
235UINT64
236EFIAPI
238 IN UINT64 Dividend,
239 IN UINT32 Divisor
240 )
241{
242 return Dividend / Divisor;
243}
244
259UINT32
260EFIAPI
262 IN UINT64 Dividend,
263 IN UINT32 Divisor
264 )
265{
266 return (UINT32)(Dividend % Divisor);
267}
268
286UINT64
287EFIAPI
289 IN UINT64 Dividend,
290 IN UINT32 Divisor,
291 OUT UINT32 *Remainder OPTIONAL
292 )
293{
294 if (Remainder != NULL) {
295 *Remainder = (UINT32)(Dividend % Divisor);
296 }
297
298 return Dividend / Divisor;
299}
300
318UINT64
319EFIAPI
321 IN UINT64 Dividend,
322 IN UINT64 Divisor,
323 OUT UINT64 *Remainder OPTIONAL
324 )
325{
326 if (Remainder != NULL) {
327 *Remainder = Dividend % Divisor;
328 }
329
330 return Dividend / Divisor;
331}
332
350INT64
351EFIAPI
353 IN INT64 Dividend,
354 IN INT64 Divisor,
355 OUT INT64 *Remainder OPTIONAL
356 )
357{
358 if (Remainder != NULL) {
359 *Remainder = Dividend % Divisor;
360 }
361
362 return Dividend / Divisor;
363}
UINT64 UINTN
INT64 INTN
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
UINT64 EFIAPI InternalMathMultU64x64(IN UINT64 Multiplicand, IN UINT64 Multiplier)
Definition: Math64.c:213
UINT64 EFIAPI InternalMathDivRemU64x64(IN UINT64 Dividend, IN UINT64 Divisor, OUT UINT64 *Remainder OPTIONAL)
Definition: Math64.c:320
UINT64 EFIAPI InternalMathRRotU64(IN UINT64 Operand, IN UINTN Count)
Definition: Math64.c:138
UINT64 EFIAPI InternalMathSwapBytes64(IN UINT64 Operand)
Definition: Math64.c:160
UINT64 EFIAPI InternalMathDivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: Math64.c:237
UINT64 EFIAPI InternalMathLShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: Math64.c:27
INT64 EFIAPI InternalMathDivRemS64x64(IN INT64 Dividend, IN INT64 Divisor, OUT INT64 *Remainder OPTIONAL)
Definition: Math64.c:352
UINT64 EFIAPI InternalMathDivRemU64x32(IN UINT64 Dividend, IN UINT32 Divisor, OUT UINT32 *Remainder OPTIONAL)
Definition: Math64.c:288
UINT32 EFIAPI InternalMathModU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: Math64.c:261
UINT64 EFIAPI InternalMathMultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
Definition: Math64.c:189
UINT64 EFIAPI InternalMathRShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: Math64.c:50
UINT64 EFIAPI InternalMathLRotU64(IN UINT64 Operand, IN UINTN Count)
Definition: Math64.c:114
UINT64 EFIAPI InternalMathARShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: Math64.c:73
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284