]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Math64.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / Math64.c
index 6c5f73203307934ae9b7e86e19fbaa5c17e8af5b..5756d0fe9263ab861362b4a59636b6be16436cd4 100644 (file)
@@ -2,20 +2,11 @@
   Leaf math worker functions that require 64-bit arithmetic support from the\r
   compiler.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
-\r
-\r
-\r
 #include "BaseLibInternals.h"\r
 \r
 /**\r
   @param  Operand The 64-bit operand to shift left.\r
   @param  Count   The number of bits to shift left.\r
 \r
-  @return Operand << Count\r
+  @return Operand << Count.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathLShiftU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   )\r
 {\r
   return Operand << Count;\r
@@ -51,14 +42,14 @@ InternalMathLShiftU64 (
   @param  Operand The 64-bit operand to shift right.\r
   @param  Count   The number of bits to shift right.\r
 \r
-  @return Operand >> Count\r
+  @return Operand >> Count.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathRShiftU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   )\r
 {\r
   return Operand >> Count;\r
@@ -71,19 +62,17 @@ InternalMathRShiftU64 (
   This function shifts the 64-bit value Operand to the right by Count bits. The\r
   high Count bits are set to bit 63 of Operand.  The shifted value is returned.\r
 \r
-  If Count is greater than 63, then ASSERT().\r
-\r
   @param  Operand The 64-bit operand to shift right.\r
   @param  Count   The number of bits to shift right.\r
 \r
-  @return Operand arithmetically shifted right by Count\r
+  @return Operand arithmetically shifted right by Count.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathARShiftU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   )\r
 {\r
   INTN  TestValue;\r
@@ -91,7 +80,7 @@ InternalMathARShiftU64 (
   //\r
   // Test if this compiler supports arithmetic shift\r
   //\r
-  TestValue = (((-1) << (sizeof (-1) * 8 - 1)) >> (sizeof (-1) * 8 - 1));\r
+  TestValue = (INTN)((INT64)(1ULL << 63) >> 63);\r
   if (TestValue == -1) {\r
     //\r
     // Arithmetic shift is supported\r
@@ -106,7 +95,6 @@ InternalMathARShiftU64 (
          ((INTN)Operand < 0 ? ~((UINTN)-1 >> Count) : 0);\r
 }\r
 \r
-\r
 /**\r
   Rotates a 64-bit integer left between 0 and 63 bits, filling\r
   the low bits with the high bits that were rotated.\r
@@ -118,14 +106,14 @@ InternalMathARShiftU64 (
   @param  Operand The 64-bit operand to rotate left.\r
   @param  Count   The number of bits to rotate left.\r
 \r
-  @return Operand <<< Count\r
+  @return Operand <<< Count.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathLRotU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   )\r
 {\r
   return (Operand << Count) | (Operand >> (64 - Count));\r
@@ -142,14 +130,14 @@ InternalMathLRotU64 (
   @param  Operand The 64-bit operand to rotate right.\r
   @param  Count   The number of bits to rotate right.\r
 \r
-  @return Operand >>> Count\r
+  @return Operand >>> Count.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathRRotU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   )\r
 {\r
   return (Operand >> Count) | (Operand << (64 - Count));\r
@@ -164,29 +152,29 @@ InternalMathRRotU64 (
 \r
   @param  Operand A 64-bit unsigned value.\r
 \r
-  @return The byte swaped Operand.\r
+  @return The byte swapped Operand.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathSwapBytes64 (\r
-  IN      UINT64                    Operand\r
+  IN      UINT64  Operand\r
   )\r
 {\r
   UINT64  LowerBytes;\r
   UINT64  HigherBytes;\r
 \r
-  LowerBytes  = (UINT64) SwapBytes32 ((UINT32) Operand);\r
-  HigherBytes = (UINT64) SwapBytes32 ((UINT32) (Operand >> 32));\r
+  LowerBytes  = (UINT64)SwapBytes32 ((UINT32)Operand);\r
+  HigherBytes = (UINT64)SwapBytes32 ((UINT32)(Operand >> 32));\r
 \r
   return (LowerBytes << 32 | HigherBytes);\r
 }\r
 \r
 /**\r
-  Multiples a 64-bit unsigned integer by a 32-bit unsigned integer\r
+  Multiplies a 64-bit unsigned integer by a 32-bit unsigned integer\r
   and generates a 64-bit unsigned result.\r
 \r
-  This function multiples the 64-bit unsigned value Multiplicand by the 32-bit\r
+  This function multiplies the 64-bit unsigned value Multiplicand by the 32-bit\r
   unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
   bit unsigned result is returned.\r
 \r
@@ -199,33 +187,32 @@ InternalMathSwapBytes64 (
 UINT64\r
 EFIAPI\r
 InternalMathMultU64x32 (\r
-  IN      UINT64                    Multiplicand,\r
-  IN      UINT32                    Multiplier\r
+  IN      UINT64  Multiplicand,\r
+  IN      UINT32  Multiplier\r
   )\r
 {\r
   return Multiplicand * Multiplier;\r
 }\r
 \r
-\r
 /**\r
-  Multiples a 64-bit unsigned integer by a 64-bit unsigned integer\r
+  Multiplies a 64-bit unsigned integer by a 64-bit unsigned integer\r
   and generates a 64-bit unsigned result.\r
 \r
-  This function multiples the 64-bit unsigned value Multiplicand by the 64-bit\r
+  This function multiplies the 64-bit unsigned value Multiplicand by the 64-bit\r
   unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
   bit unsigned result is returned.\r
 \r
   @param  Multiplicand  A 64-bit unsigned value.\r
   @param  Multiplier    A 64-bit unsigned value.\r
 \r
-  @return Multiplicand * Multiplier\r
+  @return Multiplicand * Multiplier.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathMultU64x64 (\r
-  IN      UINT64                    Multiplicand,\r
-  IN      UINT64                    Multiplier\r
+  IN      UINT64  Multiplicand,\r
+  IN      UINT64  Multiplier\r
   )\r
 {\r
   return Multiplicand * Multiplier;\r
@@ -239,25 +226,25 @@ InternalMathMultU64x64 (
   unsigned value Divisor and generates a 64-bit unsigned quotient. This\r
   function returns the 64-bit unsigned quotient.\r
 \r
-   @param  Dividend  A 64-bit unsigned value.\r
+  @param  Dividend  A 64-bit unsigned value.\r
   @param  Divisor   A 32-bit unsigned value.\r
 \r
-  @return Dividend / Divisor\r
+  @return Dividend / Divisor.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathDivU64x32 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT32                    Divisor\r
+  IN      UINT64  Dividend,\r
+  IN      UINT32  Divisor\r
   )\r
 {\r
   return Dividend / Divisor;\r
 }\r
 \r
 /**\r
-  Divides a 64-bit unsigned integer by a 32-bit unsigned integer\r
-  and generates a 32-bit unsigned remainder.\r
+  Divides a 64-bit unsigned integer by a 32-bit unsigned integer and\r
+  generates a 32-bit unsigned remainder.\r
 \r
   This function divides the 64-bit unsigned value Dividend by the 32-bit\r
   unsigned value Divisor and generates a 32-bit remainder. This function\r
@@ -266,14 +253,14 @@ InternalMathDivU64x32 (
   @param  Dividend  A 64-bit unsigned value.\r
   @param  Divisor   A 32-bit unsigned value.\r
 \r
-  @return Dividend % Divisor\r
+  @return Dividend % Divisor.\r
 \r
 **/\r
 UINT32\r
 EFIAPI\r
 InternalMathModU64x32 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT32                    Divisor\r
+  IN      UINT64  Dividend,\r
+  IN      UINT32  Divisor\r
   )\r
 {\r
   return (UINT32)(Dividend % Divisor);\r
@@ -293,20 +280,21 @@ InternalMathModU64x32 (
   @param  Remainder A pointer to a 32-bit unsigned value. This parameter is\r
                     optional and may be NULL.\r
 \r
-  @return Dividend / Divisor\r
+  @return Dividend / Divisor.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 InternalMathDivRemU64x32 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT32                    Divisor,\r
-  OUT     UINT32                    *Remainder  OPTIONAL\r
+  IN      UINT64  Dividend,\r
+  IN      UINT32  Divisor,\r
+  OUT     UINT32  *Remainder OPTIONAL\r
   )\r
 {\r
   if (Remainder != NULL) {\r
     *Remainder = (UINT32)(Dividend % Divisor);\r
   }\r
+\r
   return Dividend / Divisor;\r
 }\r
 \r
@@ -330,20 +318,21 @@ InternalMathDivRemU64x32 (
 UINT64\r
 EFIAPI\r
 InternalMathDivRemU64x64 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT64                    Divisor,\r
-  OUT     UINT64                    *Remainder  OPTIONAL\r
+  IN      UINT64  Dividend,\r
+  IN      UINT64  Divisor,\r
+  OUT     UINT64  *Remainder OPTIONAL\r
   )\r
 {\r
   if (Remainder != NULL) {\r
     *Remainder = Dividend % Divisor;\r
   }\r
+\r
   return Dividend / Divisor;\r
 }\r
 \r
 /**\r
   Divides a 64-bit signed integer by a 64-bit signed integer and\r
-  generates a 64-bit signed result and a optional 64-bit signed remainder.\r
+  generates a 64-bit signed result and an optional 64-bit signed remainder.\r
 \r
   This function divides the 64-bit signed value Dividend by the 64-bit\r
   signed value Divisor and generates a 64-bit signed quotient. If Remainder\r
@@ -355,19 +344,20 @@ InternalMathDivRemU64x64 (
   @param  Remainder A pointer to a 64-bit signed value. This parameter is\r
                     optional and may be NULL.\r
 \r
-  @return Dividend / Divisor\r
+  @return Dividend / Divisor.\r
 \r
 **/\r
 INT64\r
 EFIAPI\r
 InternalMathDivRemS64x64 (\r
-  IN      INT64                     Dividend,\r
-  IN      INT64                     Divisor,\r
-  OUT     INT64                     *Remainder  OPTIONAL\r
+  IN      INT64  Dividend,\r
+  IN      INT64  Divisor,\r
+  OUT     INT64  *Remainder  OPTIONAL\r
   )\r
 {\r
   if (Remainder != NULL) {\r
     *Remainder = Dividend % Divisor;\r
   }\r
+\r
   return Dividend / Divisor;\r
 }\r