Skip to content

Commit e41e728

Browse files
AshrafAliSmergify[bot]
authored andcommitted
Refactor SetMemWrapper to reduce binary size
Moved SetMemN API to a separate file to eliminate unnecessary inclusion of InternalMemSetMem64 and InternalMemSetMem32 APIs in driver binary. When the compiler linking the Object files it may not remove all the unused from NASM OBJs. This change is to reorganize the C files to minimize the impact of the NASM behavior resulting is code size reduction. Signed-off-by: Ashraf Ali <[email protected]>
1 parent 03c8ec6 commit e41e728

21 files changed

+392
-246
lines changed

MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
ScanMem8Wrapper.c
3333
ZeroMemWrapper.c
3434
CompareMemWrapper.c
35+
SetMemNWrapper.c
3536
SetMem64Wrapper.c
3637
SetMem32Wrapper.c
3738
SetMem16Wrapper.c
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** @file
2+
SetMemN() implementation.
3+
4+
The following BaseMemoryLib instances contain the same copy of this file:
5+
6+
BaseMemoryLib
7+
BaseMemoryLibMmx
8+
BaseMemoryLibSse2
9+
BaseMemoryLibRepStr
10+
BaseMemoryLibOptDxe
11+
BaseMemoryLibOptPei
12+
PeiMemoryLib
13+
UefiMemoryLib
14+
15+
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
16+
SPDX-License-Identifier: BSD-2-Clause-Patent
17+
18+
**/
19+
20+
#include "MemLibInternals.h"
21+
22+
/**
23+
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
24+
25+
This function fills Length bytes of Buffer with the UINTN sized value specified by
26+
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
27+
bytes of Buffer.
28+
29+
If Length > 0 and Buffer is NULL, then ASSERT().
30+
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
31+
If Buffer is not aligned on a UINTN boundary, then ASSERT().
32+
If Length is not aligned on a UINTN boundary, then ASSERT().
33+
34+
@param Buffer The pointer to the target buffer to fill.
35+
@param Length The number of bytes in Buffer to fill.
36+
@param Value The value with which to fill Length bytes of Buffer.
37+
38+
@return Buffer.
39+
40+
**/
41+
VOID *
42+
EFIAPI
43+
SetMemN (
44+
OUT VOID *Buffer,
45+
IN UINTN Length,
46+
IN UINTN Value
47+
)
48+
{
49+
if (sizeof (UINTN) == sizeof (UINT64)) {
50+
return SetMem64 (Buffer, Length, (UINT64)Value);
51+
} else {
52+
return SetMem32 (Buffer, Length, (UINT32)Value);
53+
}
54+
}

MdePkg/Library/BaseMemoryLib/SetMemWrapper.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @file
2-
SetMem() and SetMemN() implementation.
2+
SetMem() implementation.
33
44
The following BaseMemoryLib instances contain the same copy of this file:
55
@@ -49,37 +49,3 @@ SetMem (
4949

5050
return InternalMemSetMem (Buffer, Length, Value);
5151
}
52-
53-
/**
54-
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
55-
56-
This function fills Length bytes of Buffer with the UINTN sized value specified by
57-
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
58-
bytes of Buffer.
59-
60-
If Length > 0 and Buffer is NULL, then ASSERT().
61-
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
62-
If Buffer is not aligned on a UINTN boundary, then ASSERT().
63-
If Length is not aligned on a UINTN boundary, then ASSERT().
64-
65-
@param Buffer The pointer to the target buffer to fill.
66-
@param Length The number of bytes in Buffer to fill.
67-
@param Value The value with which to fill Length bytes of Buffer.
68-
69-
@return Buffer.
70-
71-
**/
72-
VOID *
73-
EFIAPI
74-
SetMemN (
75-
OUT VOID *Buffer,
76-
IN UINTN Length,
77-
IN UINTN Value
78-
)
79-
{
80-
if (sizeof (UINTN) == sizeof (UINT64)) {
81-
return SetMem64 (Buffer, Length, (UINT64)Value);
82-
} else {
83-
return SetMem32 (Buffer, Length, (UINT32)Value);
84-
}
85-
}

MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
ScanMem8Wrapper.c
3737
ZeroMemWrapper.c
3838
CompareMemWrapper.c
39+
SetMemNWrapper.c
3940
SetMem64Wrapper.c
4041
SetMem32Wrapper.c
4142
SetMem16Wrapper.c
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** @file
2+
SetMemN() implementation.
3+
4+
The following BaseMemoryLib instances contain the same copy of this file:
5+
6+
BaseMemoryLib
7+
BaseMemoryLibMmx
8+
BaseMemoryLibSse2
9+
BaseMemoryLibRepStr
10+
BaseMemoryLibOptDxe
11+
BaseMemoryLibOptPei
12+
PeiMemoryLib
13+
UefiMemoryLib
14+
15+
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
16+
SPDX-License-Identifier: BSD-2-Clause-Patent
17+
18+
**/
19+
20+
#include "MemLibInternals.h"
21+
22+
/**
23+
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
24+
25+
This function fills Length bytes of Buffer with the UINTN sized value specified by
26+
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
27+
bytes of Buffer.
28+
29+
If Length > 0 and Buffer is NULL, then ASSERT().
30+
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
31+
If Buffer is not aligned on a UINTN boundary, then ASSERT().
32+
If Length is not aligned on a UINTN boundary, then ASSERT().
33+
34+
@param Buffer The pointer to the target buffer to fill.
35+
@param Length The number of bytes in Buffer to fill.
36+
@param Value The value with which to fill Length bytes of Buffer.
37+
38+
@return Buffer.
39+
40+
**/
41+
VOID *
42+
EFIAPI
43+
SetMemN (
44+
OUT VOID *Buffer,
45+
IN UINTN Length,
46+
IN UINTN Value
47+
)
48+
{
49+
if (sizeof (UINTN) == sizeof (UINT64)) {
50+
return SetMem64 (Buffer, Length, (UINT64)Value);
51+
} else {
52+
return SetMem32 (Buffer, Length, (UINT32)Value);
53+
}
54+
}

MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @file
2-
SetMem() and SetMemN() implementation.
2+
SetMem() implementation.
33
44
The following BaseMemoryLib instances contain the same copy of this file:
55
@@ -49,37 +49,3 @@ SetMem (
4949

5050
return InternalMemSetMem (Buffer, Length, Value);
5151
}
52-
53-
/**
54-
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
55-
56-
This function fills Length bytes of Buffer with the UINTN sized value specified by
57-
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
58-
bytes of Buffer.
59-
60-
If Length > 0 and Buffer is NULL, then ASSERT().
61-
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
62-
If Buffer is not aligned on a UINTN boundary, then ASSERT().
63-
If Length is not aligned on a UINTN boundary, then ASSERT().
64-
65-
@param Buffer The pointer to the target buffer to fill.
66-
@param Length The number of bytes in Buffer to fill.
67-
@param Value The value with which to fill Length bytes of Buffer.
68-
69-
@return Buffer.
70-
71-
**/
72-
VOID *
73-
EFIAPI
74-
SetMemN (
75-
OUT VOID *Buffer,
76-
IN UINTN Length,
77-
IN UINTN Value
78-
)
79-
{
80-
if (sizeof (UINTN) == sizeof (UINT64)) {
81-
return SetMem64 (Buffer, Length, (UINT64)Value);
82-
} else {
83-
return SetMem32 (Buffer, Length, (UINT32)Value);
84-
}
85-
}

MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
ScanMem8Wrapper.c
9393
ZeroMemWrapper.c
9494
CompareMemWrapper.c
95+
SetMemNWrapper.c
9596
SetMem64Wrapper.c
9697
SetMem32Wrapper.c
9798
SetMem16Wrapper.c
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** @file
2+
SetMemN() implementation.
3+
4+
The following BaseMemoryLib instances contain the same copy of this file:
5+
6+
BaseMemoryLib
7+
BaseMemoryLibMmx
8+
BaseMemoryLibSse2
9+
BaseMemoryLibRepStr
10+
BaseMemoryLibOptDxe
11+
BaseMemoryLibOptPei
12+
PeiMemoryLib
13+
UefiMemoryLib
14+
15+
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
16+
SPDX-License-Identifier: BSD-2-Clause-Patent
17+
18+
**/
19+
20+
#include "MemLibInternals.h"
21+
22+
/**
23+
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
24+
25+
This function fills Length bytes of Buffer with the UINTN sized value specified by
26+
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
27+
bytes of Buffer.
28+
29+
If Length > 0 and Buffer is NULL, then ASSERT().
30+
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
31+
If Buffer is not aligned on a UINTN boundary, then ASSERT().
32+
If Length is not aligned on a UINTN boundary, then ASSERT().
33+
34+
@param Buffer The pointer to the target buffer to fill.
35+
@param Length The number of bytes in Buffer to fill.
36+
@param Value The value with which to fill Length bytes of Buffer.
37+
38+
@return Buffer.
39+
40+
**/
41+
VOID *
42+
EFIAPI
43+
SetMemN (
44+
OUT VOID *Buffer,
45+
IN UINTN Length,
46+
IN UINTN Value
47+
)
48+
{
49+
if (sizeof (UINTN) == sizeof (UINT64)) {
50+
return SetMem64 (Buffer, Length, (UINT64)Value);
51+
} else {
52+
return SetMem32 (Buffer, Length, (UINT32)Value);
53+
}
54+
}

MdePkg/Library/BaseMemoryLibOptDxe/SetMemWrapper.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @file
2-
SetMem() and SetMemN() implementation.
2+
SetMem() implementation.
33
44
The following BaseMemoryLib instances contain the same copy of this file:
55
@@ -49,37 +49,3 @@ SetMem (
4949

5050
return InternalMemSetMem (Buffer, Length, Value);
5151
}
52-
53-
/**
54-
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
55-
56-
This function fills Length bytes of Buffer with the UINTN sized value specified by
57-
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
58-
bytes of Buffer.
59-
60-
If Length > 0 and Buffer is NULL, then ASSERT().
61-
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
62-
If Buffer is not aligned on a UINTN boundary, then ASSERT().
63-
If Length is not aligned on a UINTN boundary, then ASSERT().
64-
65-
@param Buffer The pointer to the target buffer to fill.
66-
@param Length The number of bytes in Buffer to fill.
67-
@param Value The value with which to fill Length bytes of Buffer.
68-
69-
@return Buffer.
70-
71-
**/
72-
VOID *
73-
EFIAPI
74-
SetMemN (
75-
OUT VOID *Buffer,
76-
IN UINTN Length,
77-
IN UINTN Value
78-
)
79-
{
80-
if (sizeof (UINTN) == sizeof (UINT64)) {
81-
return SetMem64 (Buffer, Length, (UINT64)Value);
82-
} else {
83-
return SetMem32 (Buffer, Length, (UINT32)Value);
84-
}
85-
}

MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
ScanMem8Wrapper.c
3434
ZeroMemWrapper.c
3535
CompareMemWrapper.c
36+
SetMemNWrapper.c
3637
SetMem64Wrapper.c
3738
SetMem32Wrapper.c
3839
SetMem16Wrapper.c
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** @file
2+
SetMemN() implementation.
3+
4+
The following BaseMemoryLib instances contain the same copy of this file:
5+
6+
BaseMemoryLib
7+
BaseMemoryLibMmx
8+
BaseMemoryLibSse2
9+
BaseMemoryLibRepStr
10+
BaseMemoryLibOptDxe
11+
BaseMemoryLibOptPei
12+
PeiMemoryLib
13+
UefiMemoryLib
14+
15+
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
16+
SPDX-License-Identifier: BSD-2-Clause-Patent
17+
18+
**/
19+
20+
#include "MemLibInternals.h"
21+
22+
/**
23+
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
24+
25+
This function fills Length bytes of Buffer with the UINTN sized value specified by
26+
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
27+
bytes of Buffer.
28+
29+
If Length > 0 and Buffer is NULL, then ASSERT().
30+
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
31+
If Buffer is not aligned on a UINTN boundary, then ASSERT().
32+
If Length is not aligned on a UINTN boundary, then ASSERT().
33+
34+
@param Buffer The pointer to the target buffer to fill.
35+
@param Length The number of bytes in Buffer to fill.
36+
@param Value The value with which to fill Length bytes of Buffer.
37+
38+
@return Buffer.
39+
40+
**/
41+
VOID *
42+
EFIAPI
43+
SetMemN (
44+
OUT VOID *Buffer,
45+
IN UINTN Length,
46+
IN UINTN Value
47+
)
48+
{
49+
if (sizeof (UINTN) == sizeof (UINT64)) {
50+
return SetMem64 (Buffer, Length, (UINT64)Value);
51+
} else {
52+
return SetMem32 (Buffer, Length, (UINT32)Value);
53+
}
54+
}

0 commit comments

Comments
 (0)