Skip to content

Commit

Permalink
Refactor SetMemWrapper to reduce binary size
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
AshrafAliS authored and mergify[bot] committed Sep 11, 2024
1 parent 03c8ec6 commit e41e728
Show file tree
Hide file tree
Showing 21 changed files with 392 additions and 246 deletions.
1 change: 1 addition & 0 deletions MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ScanMem8Wrapper.c
ZeroMemWrapper.c
CompareMemWrapper.c
SetMemNWrapper.c
SetMem64Wrapper.c
SetMem32Wrapper.c
SetMem16Wrapper.c
Expand Down
54 changes: 54 additions & 0 deletions MdePkg/Library/BaseMemoryLib/SetMemNWrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @file
SetMemN() implementation.
The following BaseMemoryLib instances contain the same copy of this file:
BaseMemoryLib
BaseMemoryLibMmx
BaseMemoryLibSse2
BaseMemoryLibRepStr
BaseMemoryLibOptDxe
BaseMemoryLibOptPei
PeiMemoryLib
UefiMemoryLib
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include "MemLibInternals.h"

/**
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
This function fills Length bytes of Buffer with the UINTN sized value specified by
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
bytes of Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Buffer is not aligned on a UINTN boundary, then ASSERT().
If Length is not aligned on a UINTN boundary, then ASSERT().
@param Buffer The pointer to the target buffer to fill.
@param Length The number of bytes in Buffer to fill.
@param Value The value with which to fill Length bytes of Buffer.
@return Buffer.
**/
VOID *
EFIAPI
SetMemN (
OUT VOID *Buffer,
IN UINTN Length,
IN UINTN Value
)
{
if (sizeof (UINTN) == sizeof (UINT64)) {
return SetMem64 (Buffer, Length, (UINT64)Value);
} else {
return SetMem32 (Buffer, Length, (UINT32)Value);
}
}
36 changes: 1 addition & 35 deletions MdePkg/Library/BaseMemoryLib/SetMemWrapper.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
SetMem() and SetMemN() implementation.
SetMem() implementation.
The following BaseMemoryLib instances contain the same copy of this file:
Expand Down Expand Up @@ -49,37 +49,3 @@ SetMem (

return InternalMemSetMem (Buffer, Length, Value);
}

/**
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
This function fills Length bytes of Buffer with the UINTN sized value specified by
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
bytes of Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Buffer is not aligned on a UINTN boundary, then ASSERT().
If Length is not aligned on a UINTN boundary, then ASSERT().
@param Buffer The pointer to the target buffer to fill.
@param Length The number of bytes in Buffer to fill.
@param Value The value with which to fill Length bytes of Buffer.
@return Buffer.
**/
VOID *
EFIAPI
SetMemN (
OUT VOID *Buffer,
IN UINTN Length,
IN UINTN Value
)
{
if (sizeof (UINTN) == sizeof (UINT64)) {
return SetMem64 (Buffer, Length, (UINT64)Value);
} else {
return SetMem32 (Buffer, Length, (UINT32)Value);
}
}
1 change: 1 addition & 0 deletions MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ScanMem8Wrapper.c
ZeroMemWrapper.c
CompareMemWrapper.c
SetMemNWrapper.c
SetMem64Wrapper.c
SetMem32Wrapper.c
SetMem16Wrapper.c
Expand Down
54 changes: 54 additions & 0 deletions MdePkg/Library/BaseMemoryLibMmx/SetMemNWrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @file
SetMemN() implementation.
The following BaseMemoryLib instances contain the same copy of this file:
BaseMemoryLib
BaseMemoryLibMmx
BaseMemoryLibSse2
BaseMemoryLibRepStr
BaseMemoryLibOptDxe
BaseMemoryLibOptPei
PeiMemoryLib
UefiMemoryLib
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include "MemLibInternals.h"

/**
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
This function fills Length bytes of Buffer with the UINTN sized value specified by
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
bytes of Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Buffer is not aligned on a UINTN boundary, then ASSERT().
If Length is not aligned on a UINTN boundary, then ASSERT().
@param Buffer The pointer to the target buffer to fill.
@param Length The number of bytes in Buffer to fill.
@param Value The value with which to fill Length bytes of Buffer.
@return Buffer.
**/
VOID *
EFIAPI
SetMemN (
OUT VOID *Buffer,
IN UINTN Length,
IN UINTN Value
)
{
if (sizeof (UINTN) == sizeof (UINT64)) {
return SetMem64 (Buffer, Length, (UINT64)Value);
} else {
return SetMem32 (Buffer, Length, (UINT32)Value);
}
}
36 changes: 1 addition & 35 deletions MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
SetMem() and SetMemN() implementation.
SetMem() implementation.
The following BaseMemoryLib instances contain the same copy of this file:
Expand Down Expand Up @@ -49,37 +49,3 @@ SetMem (

return InternalMemSetMem (Buffer, Length, Value);
}

/**
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
This function fills Length bytes of Buffer with the UINTN sized value specified by
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
bytes of Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Buffer is not aligned on a UINTN boundary, then ASSERT().
If Length is not aligned on a UINTN boundary, then ASSERT().
@param Buffer The pointer to the target buffer to fill.
@param Length The number of bytes in Buffer to fill.
@param Value The value with which to fill Length bytes of Buffer.
@return Buffer.
**/
VOID *
EFIAPI
SetMemN (
OUT VOID *Buffer,
IN UINTN Length,
IN UINTN Value
)
{
if (sizeof (UINTN) == sizeof (UINT64)) {
return SetMem64 (Buffer, Length, (UINT64)Value);
} else {
return SetMem32 (Buffer, Length, (UINT32)Value);
}
}
1 change: 1 addition & 0 deletions MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
ScanMem8Wrapper.c
ZeroMemWrapper.c
CompareMemWrapper.c
SetMemNWrapper.c
SetMem64Wrapper.c
SetMem32Wrapper.c
SetMem16Wrapper.c
Expand Down
54 changes: 54 additions & 0 deletions MdePkg/Library/BaseMemoryLibOptDxe/SetMemNWrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @file
SetMemN() implementation.
The following BaseMemoryLib instances contain the same copy of this file:
BaseMemoryLib
BaseMemoryLibMmx
BaseMemoryLibSse2
BaseMemoryLibRepStr
BaseMemoryLibOptDxe
BaseMemoryLibOptPei
PeiMemoryLib
UefiMemoryLib
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include "MemLibInternals.h"

/**
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
This function fills Length bytes of Buffer with the UINTN sized value specified by
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
bytes of Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Buffer is not aligned on a UINTN boundary, then ASSERT().
If Length is not aligned on a UINTN boundary, then ASSERT().
@param Buffer The pointer to the target buffer to fill.
@param Length The number of bytes in Buffer to fill.
@param Value The value with which to fill Length bytes of Buffer.
@return Buffer.
**/
VOID *
EFIAPI
SetMemN (
OUT VOID *Buffer,
IN UINTN Length,
IN UINTN Value
)
{
if (sizeof (UINTN) == sizeof (UINT64)) {
return SetMem64 (Buffer, Length, (UINT64)Value);
} else {
return SetMem32 (Buffer, Length, (UINT32)Value);
}
}
36 changes: 1 addition & 35 deletions MdePkg/Library/BaseMemoryLibOptDxe/SetMemWrapper.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
SetMem() and SetMemN() implementation.
SetMem() implementation.
The following BaseMemoryLib instances contain the same copy of this file:
Expand Down Expand Up @@ -49,37 +49,3 @@ SetMem (

return InternalMemSetMem (Buffer, Length, Value);
}

/**
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
This function fills Length bytes of Buffer with the UINTN sized value specified by
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
bytes of Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Buffer is not aligned on a UINTN boundary, then ASSERT().
If Length is not aligned on a UINTN boundary, then ASSERT().
@param Buffer The pointer to the target buffer to fill.
@param Length The number of bytes in Buffer to fill.
@param Value The value with which to fill Length bytes of Buffer.
@return Buffer.
**/
VOID *
EFIAPI
SetMemN (
OUT VOID *Buffer,
IN UINTN Length,
IN UINTN Value
)
{
if (sizeof (UINTN) == sizeof (UINT64)) {
return SetMem64 (Buffer, Length, (UINT64)Value);
} else {
return SetMem32 (Buffer, Length, (UINT32)Value);
}
}
1 change: 1 addition & 0 deletions MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ScanMem8Wrapper.c
ZeroMemWrapper.c
CompareMemWrapper.c
SetMemNWrapper.c
SetMem64Wrapper.c
SetMem32Wrapper.c
SetMem16Wrapper.c
Expand Down
54 changes: 54 additions & 0 deletions MdePkg/Library/BaseMemoryLibOptPei/SetMemNWrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @file
SetMemN() implementation.
The following BaseMemoryLib instances contain the same copy of this file:
BaseMemoryLib
BaseMemoryLibMmx
BaseMemoryLibSse2
BaseMemoryLibRepStr
BaseMemoryLibOptDxe
BaseMemoryLibOptPei
PeiMemoryLib
UefiMemoryLib
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include "MemLibInternals.h"

/**
Fills a target buffer with a value that is size UINTN, and returns the target buffer.
This function fills Length bytes of Buffer with the UINTN sized value specified by
Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
bytes of Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
If Buffer is not aligned on a UINTN boundary, then ASSERT().
If Length is not aligned on a UINTN boundary, then ASSERT().
@param Buffer The pointer to the target buffer to fill.
@param Length The number of bytes in Buffer to fill.
@param Value The value with which to fill Length bytes of Buffer.
@return Buffer.
**/
VOID *
EFIAPI
SetMemN (
OUT VOID *Buffer,
IN UINTN Length,
IN UINTN Value
)
{
if (sizeof (UINTN) == sizeof (UINT64)) {
return SetMem64 (Buffer, Length, (UINT64)Value);
} else {
return SetMem32 (Buffer, Length, (UINT32)Value);
}
}
Loading

0 comments on commit e41e728

Please sign in to comment.