]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / MemLibGuid.c
1 /** @file
2 Implementation of GUID functions.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 The following BaseMemoryLib instances share the same version of this file:
14
15 BaseMemoryLib
16 BaseMemoryLibMmx
17 BaseMemoryLibSse2
18 BaseMemoryLibRepStr
19 PeiMemoryLib
20 DxeMemoryLib
21
22 **/
23
24
25 #include "MemLibInternals.h"
26
27 /**
28 Copies a source GUID to a destination GUID.
29
30 This function copies the contents of the 128-bit GUID specified by SourceGuid to
31 DestinationGuid, and returns DestinationGuid.
32 If DestinationGuid is NULL, then ASSERT().
33 If SourceGuid is NULL, then ASSERT().
34
35 @param DestinationGuid Pointer to the destination GUID.
36 @param SourceGuid Pointer to the source GUID.
37
38 @return DestinationGuid.
39
40 **/
41 GUID *
42 EFIAPI
43 CopyGuid (
44 OUT GUID *DestinationGuid,
45 IN CONST GUID *SourceGuid
46 )
47 {
48 WriteUnaligned64 (
49 (UINT64*)DestinationGuid,
50 ReadUnaligned64 ((CONST UINT64*)SourceGuid)
51 );
52 WriteUnaligned64 (
53 (UINT64*)DestinationGuid + 1,
54 ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)
55 );
56 return DestinationGuid;
57 }
58
59 /**
60 Compares two GUIDs.
61
62 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
63 If there are any bit differences in the two GUIDs, then FALSE is returned.
64 If Guid1 is NULL, then ASSERT().
65 If Guid2 is NULL, then ASSERT().
66
67 @param Guid1 A pointer to a 128 bit GUID.
68 @param Guid2 A pointer to a 128 bit GUID.
69
70 @retval TRUE Guid1 and Guid2 are identical.
71 @retval FALSE Guid1 and Guid2 are not identical.
72
73 **/
74 BOOLEAN
75 EFIAPI
76 CompareGuid (
77 IN CONST GUID *Guid1,
78 IN CONST GUID *Guid2
79 )
80 {
81 UINT64 LowPartOfGuid1;
82 UINT64 LowPartOfGuid2;
83 UINT64 HighPartOfGuid1;
84 UINT64 HighPartOfGuid2;
85
86 LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1);
87 LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2);
88 HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1);
89 HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1);
90
91 return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);
92 }
93
94 /**
95 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
96 in the target buffer.
97
98 This function searches target the buffer specified by Buffer and Length from
99 the lowest address to the highest address at 128-bit increments for the 128-bit
100 GUID value that matches Guid. If a match is found, then a pointer to the matching
101 GUID in the target buffer is returned. If no match is found, then NULL is returned.
102 If Length is 0, then NULL is returned.
103 If Length > 0 and Buffer is NULL, then ASSERT().
104 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
105 If Length is not aligned on a 128-bit boundary, then ASSERT().
106 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
107
108 @param Buffer Pointer to the target buffer to scan.
109 @param Length Number of bytes in Buffer to scan.
110 @param Guid Value to search for in the target buffer.
111
112 @return A pointer to the matching Guid in the target buffer or NULL otherwise.
113
114 **/
115 VOID *
116 EFIAPI
117 ScanGuid (
118 IN CONST VOID *Buffer,
119 IN UINTN Length,
120 IN CONST GUID *Guid
121 )
122 {
123 CONST GUID *GuidPtr;
124
125 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);
126 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
127 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);
128
129 GuidPtr = (GUID*)Buffer;
130 Buffer = GuidPtr + Length / sizeof (*GuidPtr);
131 while (GuidPtr < (CONST GUID*)Buffer) {
132 if (CompareGuid (GuidPtr, Guid)) {
133 return (VOID*)GuidPtr;
134 }
135 GuidPtr++;
136 }
137 return NULL;
138 }