From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko Stuebner Date: Mon, 27 Mar 2017 21:55:53 +0200 Subject: [U-Boot] [PATCH 2/3] string: Provide a slimmed-down memset() In-Reply-To: <20170326233817.8834-3-sjg@chromium.org> References: <20170326233817.8834-1-sjg@chromium.org> <20170326233817.8834-3-sjg@chromium.org> Message-ID: <1774824.qGkfdM3OR8@phil> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Am Sonntag, 26. M=C3=A4rz 2017, 17:38:16 CEST schrieb Simon Glass: > 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. >=20 > Signed-off-by: Simon Glass This brings down the rk3188-rock tpl from 1020 to 972 bytes (with a 1020 byte size limit for the tpl) even with gcc-4.9 and down to 748 bytes on gcc-6.3. I was using the original memset in all tests before, so am quite sure it should work without issues, but cannot test it on actual hardware this week. Heiko > --- >=20 > lib/Kconfig | 9 +++++++++ > lib/string.c | 6 ++++-- > 2 files changed, 13 insertions(+), 2 deletions(-) >=20 > diff --git a/lib/Kconfig b/lib/Kconfig > index 65c01573e1..5bf512d8c0 100644 > --- a/lib/Kconfig > +++ b/lib/Kconfig > @@ -52,6 +52,15 @@ config LIB_RAND > help > This library provides pseudo-random number generator functions. > =20 > +config FAST_MEMSET > + bool "Use an optimised memset()" > + default y > + 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 write a word at a time. Disable this option > + to reduce code size slightly at the cost of some speed. > + > source lib/dhry/Kconfig > =20 > source lib/rsa/Kconfig > diff --git a/lib/string.c b/lib/string.c > index 67d5f6a421..159493ed17 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 =3D (unsigned long *) s; > - unsigned long cl =3D 0; > char *s8; > + > +#ifdef CONFIG_FAST_MEMSET > + unsigned long cl =3D 0; > int i; > =20 > /* do it one word at a time (32 bits or 64 bits) while possible */ > @@ -452,7 +454,7 @@ void * memset(void * s,int c,size_t count) > count -=3D sizeof(*sl); > } > } > - /* fill 8 bits at a time */ > +#endif /* fill 8 bits at a time */ > s8 =3D (char *)sl; > while (count--) > *s8++ =3D c; >=20