From: Heiko Stuebner <heiko@sntech.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] string: Provide a slimmed-down memset()
Date: Thu, 30 Mar 2017 13:14:02 +0200 [thread overview]
Message-ID: <4143670.kux4ZBcVD6@phil> (raw)
In-Reply-To: <20170326233817.8834-3-sjg@chromium.org>
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 <sjg@chromium.org>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Hi Simon,
a bit bikesheddy, but might it make more sense to structure the
options like below? That way it matches USE_ARCH_MEMSET and might
make the intent visible better, as you get
USE_ARCH_MEMSET=y = biggest but also fastest
(nothing) = default from libgeneric
USE_TINY_MEMSET=y = optimize for size over speed
Also might make reading defconfigs easier as you would have
CONFIG_USE_TINY_MEMSET=y
instead of
# CONFIG_FAST_MEMSET is not set
when needing that option.
Anyway, I've tested both variants on a live rk3188-rock now and
everything of course still works, even when build with gcc-4.9, so
both variants also
Tested-by: Heiko Stuebner <heiko@sntech.de>
Heiko
lib/Kconfig | 20 ++++++++++++++++++++
lib/string.c | 5 ++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/lib/Kconfig b/lib/Kconfig
index 65c01573e1..ab42413839 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -52,6 +52,26 @@ config LIB_RAND
help
This library provides pseudo-random number generator functions.
+config USE_TINY_MEMSET
+ bool "Use a size-optimized memset()"
+ help
+ This makes memset prefer code size over speed optimizations.
+ The fastest 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 at the cost of
+ slightly bigger memset code, but in some special cases size might
+ be more important than speed.
+
+config SPL_USE_TINY_MEMSET
+ bool "Use a size-optimized memset()"
+ help
+ This makes memset prefer code size over speed optimizations.
+ The fastest 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 at the cost of
+ slightly bigger memset code, but in some special cases size might
+ be more important than speed.
+
source lib/dhry/Kconfig
source lib/rsa/Kconfig
diff --git a/lib/string.c b/lib/string.c
index 67d5f6a421..edae997fa6 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -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(USE_TINY_MEMSET)
+ unsigned long cl = 0;
int i;
/* do it one word at a time (32 bits or 64 bits) while possible */
@@ -452,6 +454,7 @@ void * memset(void * s,int c,size_t count)
count -= sizeof(*sl);
}
}
+#endif
/* fill 8 bits at a time */
s8 = (char *)sl;
while (count--)
--
2.11.0
next prev parent reply other threads:[~2017-03-30 11:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-26 23:38 [U-Boot] [PATCH 0/3] RFC: Patches to reduce TPL code size Simon Glass
2017-03-26 23:38 ` [U-Boot] [PATCH 1/3] Makefile: Correct dependency race condition with TPL Simon Glass
2017-03-27 19:39 ` Heiko Stuebner
2017-04-02 0:05 ` Simon Glass
2017-03-26 23:38 ` [U-Boot] [PATCH 2/3] string: Provide a slimmed-down memset() Simon Glass
2017-03-27 7:14 ` Alexander Graf
2017-03-27 15:17 ` Heiko Stuebner
2017-03-27 21:16 ` Alexander Graf
2017-03-28 12:34 ` Heiko Stuebner
2017-03-27 19:55 ` Heiko Stuebner
2017-03-30 11:14 ` Heiko Stuebner [this message]
2017-03-26 23:38 ` [U-Boot] [PATCH 3/3] Makefile: Provide an option to select SPL or TPL Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4143670.kux4ZBcVD6@phil \
--to=heiko@sntech.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox