]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/Math64.c
Updated CpuFlushCacheLine() to return the address flushed.
[mirror_edk2.git] / MdePkg / Library / BaseLib / Math64.c
CommitLineData
878ddf1f 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
18UINT64\r
19EFIAPI\r
20InternalMathLShiftU64 (\r
21 IN UINT64 Operand,\r
22 IN UINTN Count\r
23 )\r
24{\r
25 return Operand << Count;\r
26}\r
27\r
28UINT64\r
29EFIAPI\r
30InternalMathRShiftU64 (\r
31 IN UINT64 Operand,\r
32 IN UINTN Count\r
33 )\r
34{\r
35 return Operand >> Count;\r
36}\r
37\r
38UINT64\r
39EFIAPI\r
40InternalMathARShiftU64 (\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
62UINT64\r
63EFIAPI\r
64InternalMathLRotU64 (\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
72UINT64\r
73EFIAPI\r
74InternalMathRRotU64 (\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
82UINT64\r
83EFIAPI\r
84InternalMathSwapBytes64 (\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
94UINT64\r
95EFIAPI\r
96InternalMathMultU64x32 (\r
97 IN UINT64 Multiplicand,\r
98 IN UINT32 Multiplier\r
99 )\r
100{\r
101 return Multiplicand * Multiplier;\r
102}\r
103\r
104UINT64\r
105EFIAPI\r
106InternalMathMultU64x64 (\r
107 IN UINT64 Multiplicand,\r
108 IN UINT64 Multiplier\r
109 )\r
110{\r
111 return Multiplicand * Multiplier;\r
112}\r
113\r
114UINT64\r
115EFIAPI\r
116InternalMathDivU64x32 (\r
117 IN UINT64 Dividend,\r
118 IN UINT32 Divisor\r
119 )\r
120{\r
121 return Dividend / Divisor;\r
122}\r
123\r
9a462b41 124UINT32\r
878ddf1f 125EFIAPI\r
126InternalMathModU64x32 (\r
127 IN UINT64 Dividend,\r
128 IN UINT32 Divisor\r
129 )\r
130{\r
9a462b41 131 return (UINT32)(Dividend % Divisor);\r
878ddf1f 132}\r
133\r
134UINT64\r
135EFIAPI\r
136InternalMathDivRemU64x32 (\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
148UINT64\r
149EFIAPI\r
150InternalMathDivRemU64x64 (\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
162INT64\r
163EFIAPI\r
164InternalMathDivRemS64x64 (\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