1 /*++
2 
3 Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 
12 Module Name:
13 
14   EfiCompareMem.c
15 
16 Abstract:
17 
18   Generic compare-memory routine.
19 
20 --*/
21 
22 #include "Tiano.h"
23 #include "EfiDriverLib.h"
24 
25 
26 INTN
EfiCompareMem(IN VOID * MemOne,IN VOID * MemTwo,IN UINTN Length)27 EfiCompareMem (
28   IN VOID     *MemOne,
29   IN VOID     *MemTwo,
30   IN UINTN    Length
31   )
32 /*++
33 
34 Routine Description:
35 
36   Compares two memory buffers of a given length.
37 
38 Arguments:
39 
40   MemOne - First memory buffer
41 
42   MemTwo - Second memory buffer
43 
44   Len    - Length of Mem1 and Mem2 memory regions to compare
45 
46 Returns:
47 
48   = 0     if MemOne == MemTwo
49 
50 --*/
51 {
52   INTN ReturnValue;
53 
54   if (!(EFI_UINTN_ALIGNED (MemOne) || EFI_UINTN_ALIGNED (MemTwo) || EFI_UINTN_ALIGNED (Length))) {
55     //
56     // If Destination/Source/Length are aligned do UINTN conpare
57     //
58     for (; Length > 0; Length -= sizeof (INTN), MemOne = (VOID *)((UINTN)MemOne + sizeof (INTN)), MemTwo = (VOID *)((UINTN)MemTwo + sizeof (INTN))) {
59       if (*(INTN *)MemOne != *(INTN *)MemTwo) {
60         break;
61       }
62     }
63   }
64 
65   //
66   // If Destination/Source/Length not aligned do byte compare
67   //
68   for (; Length > 0; Length--, MemOne = (VOID *)((UINTN)MemOne + 1), MemTwo = (VOID *)((UINTN)MemTwo + 1)) {
69     ReturnValue = (INTN)(*(INT8 *)MemOne - *(INT8 *)MemTwo);
70     if (ReturnValue != 0) {
71       return ReturnValue;
72     }
73   }
74 
75   return 0;
76 }
77