]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/CheckSum.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / BaseLib / CheckSum.c
index 957a2224f924bf0281d1700658c803ce6d46f852..4991923f475cc58ffa4bc0139a1722c346cc763b 100644 (file)
   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
 \r
-  Module Name:  CheckSum.c\r
-\r
 **/\r
 \r
+\r
+#include <BaseLibInternals.h>\r
+\r
+\r
 /**\r
   Calculate the sum of all elements in a buffer in unit of UINT8. \r
   During calculation, the carry bits are dropped.\r
@@ -27,8 +29,8 @@
   If Buffer is NULL, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer                       Pointer to the buffer to carry out the sum operation.\r
-  @param  Length           The size, in bytes, of Buffer .\r
+  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Length      The size, in bytes, of Buffer .\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
 \r
@@ -47,7 +49,7 @@ CalculateSum8 (
   ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
 \r
   for (Sum = 0, Count = 0; Count < Length; Count++) {\r
-    Sum = Sum + *(Buffer + Count);\r
+    Sum = (UINT8) (Sum + *(Buffer + Count));\r
   }\r
   \r
   return Sum;\r
@@ -66,9 +68,8 @@ CalculateSum8 (
   If Buffer is NULL, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-\r
-  @param  Buffer                       Pointer to the buffer to carry out the checksum operation.\r
-  @param  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Checksum       The 2's complement checksum of Buffer.\r
 \r
@@ -103,8 +104,8 @@ CalculateCheckSum8 (
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer                       Pointer to the buffer to carry out the sum operation.\r
-  @param  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
 \r
@@ -118,15 +119,16 @@ CalculateSum16 (
 {\r
   UINT16    Sum;\r
   UINTN     Count;\r
+  UINTN     Total;\r
 \r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN) Buffer & 0x1) == 0);\r
   ASSERT ((Length & 0x1) == 0);\r
   ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
 \r
-\r
-  for (Sum = 0, Count = 0; Count < Length; Count++) {\r
-    Sum = Sum + *(Buffer + Count);\r
+  Total = Length / sizeof (*Buffer);\r
+  for (Sum = 0, Count = 0; Count < Total; Count++) {\r
+    Sum = (UINT16) (Sum + *(Buffer + Count));\r
   }\r
   \r
   return Sum;\r
@@ -147,8 +149,8 @@ CalculateSum16 (
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer                       Pointer to the buffer to carry out the checksum operation.\r
-  @param  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Checksum       The 2's complement checksum of Buffer.\r
 \r
@@ -184,8 +186,8 @@ CalculateCheckSum16 (
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer                       Pointer to the buffer to carry out the sum operation.\r
-  @param  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
 \r
@@ -199,14 +201,15 @@ CalculateSum32 (
 {\r
   UINT32    Sum;\r
   UINTN     Count;\r
+  UINTN     Total;\r
 \r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN) Buffer & 0x3) == 0);\r
   ASSERT ((Length & 0x3) == 0);\r
   ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
 \r
-\r
-  for (Sum = 0, Count = 0; Count < Length; Count++) {\r
+  Total = Length / sizeof (*Buffer);\r
+  for (Sum = 0, Count = 0; Count < Total; Count++) {\r
     Sum = Sum + *(Buffer + Count);\r
   }\r
   \r
@@ -228,8 +231,8 @@ CalculateSum32 (
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer                       Pointer to the buffer to carry out the checksum operation.\r
-  @param  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Checksum       The 2's complement checksum of Buffer.\r
 \r
@@ -265,8 +268,8 @@ CalculateCheckSum32 (
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer                       Pointer to the buffer to carry out the sum operation.\r
-  @param  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
 \r
@@ -280,13 +283,15 @@ CalculateSum64 (
 {\r
   UINT64    Sum;\r
   UINTN     Count;\r
+  UINTN     Total;\r
 \r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN) Buffer & 0x7) == 0);\r
   ASSERT ((Length & 0x7) == 0);\r
   ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
 \r
-  for (Sum = 0, Count = 0; Count < Length; Count++) {\r
+  Total = Length / sizeof (*Buffer);\r
+  for (Sum = 0, Count = 0; Count < Total; Count++) {\r
     Sum = Sum + *(Buffer + Count);\r
   }\r
   \r
@@ -308,8 +313,8 @@ CalculateSum64 (
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer                       Pointer to the buffer to carry out the checksum operation.\r
-  @param  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Checksum       The 2's complement checksum of Buffer.\r
 \r