]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
string: Provide a slimmed-down memset()
authorSimon Glass <sjg@chromium.org>
Sun, 2 Apr 2017 15:50:28 +0000 (09:50 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 5 Apr 2017 02:01:57 +0000 (20:01 -0600)
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>
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
lib/Kconfig
lib/string.c

index 65c01573e194e13b0d4a9c64923c840525782312..5115d047f86f6c192440705c645d7d4d02140181 100644 (file)
@@ -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
index 67d5f6a4213a4c9e3dcdfe067724e4a7885baad6..c1a28c14ced51dd58424a10d2af0e1444207a80a 100644 (file)
@@ -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 */
@@ -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;