Skip to content

Commit

Permalink
string: Provide a slimmed-down memset()
Browse files Browse the repository at this point in the history
Most of the time the optimised memset() is what we want. For extreme
situations such as TPL it may be too large. For example on the 'rock'
board, using a simple loop saves a useful 48 bytes. With gcc 4.9 and
the rodata bug, this patch is enough to reduce the TPL image below the
limit.

Signed-off-by: Simon Glass <[email protected]>
Reviewed-by: Heiko Stuebner <[email protected]>
  • Loading branch information
sjg20 committed Apr 5, 2017
1 parent 3c00a2c commit ab4458b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ config LIB_RAND
help
This library provides pseudo-random number generator functions.

config SPL_TINY_MEMSET
bool "Use a very small memset() in SPL"
help
The faster memset() is the arch-specific one (if available) enabled
by CONFIG_USE_ARCH_MEMSET. If that is not enabled, we can still get
better performance by writing a word at a time. But in very
size-constrained envrionments even this may be too big. Enable this
option to reduce code size slightly at the cost of some speed.

source lib/dhry/Kconfig

source lib/rsa/Kconfig
Expand Down
6 changes: 4 additions & 2 deletions lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,10 @@ char *strswab(const char *s)
void * memset(void * s,int c,size_t count)
{
unsigned long *sl = (unsigned long *) s;
unsigned long cl = 0;
char *s8;

#if !CONFIG_IS_ENABLED(TINY_MEMSET)
unsigned long cl = 0;
int i;

/* do it one word at a time (32 bits or 64 bits) while possible */
Expand All @@ -452,7 +454,7 @@ void * memset(void * s,int c,size_t count)
count -= sizeof(*sl);
}
}
/* fill 8 bits at a time */
#endif /* fill 8 bits at a time */
s8 = (char *)sl;
while (count--)
*s8++ = c;
Expand Down

0 comments on commit ab4458b

Please sign in to comment.