From d7f2428afb540539a14827ecb2d757329acb71c9 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 21 Oct 2012 05:38:24 +0000 Subject: Minor tweaks to memset git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5245 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/Documentation/NuttxPortingGuide.html | 1 + nuttx/configs/README.txt | 11 ++++--- nuttx/lib/Kconfig | 10 +++--- nuttx/lib/string/lib_memset.c | 53 +++++++++++++----------------- 4 files changed, 37 insertions(+), 38 deletions(-) (limited to 'nuttx') diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index 08c6534cb..d8ccfc340 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -4452,6 +4452,7 @@ build diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index 9714b0228..c7f3db0e7 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -625,8 +625,9 @@ defconfig -- This is a configuration file similar to the Linux Vik's optimized implementation of memcpy(): CONFIG_MEMCPY_VIK - Select this option to use the optimized memcpy() - function by Daniel Vik. See licensing information in the top-level - COPYING file. Default: n + function by Daniel Vik. Select this option for improved performance + at the expense of increased size. See licensing information in the + top-level COPYING file. Default: n And if CONFIG_MEMCPY_VIK is selected, the following tuning options are available: @@ -636,7 +637,8 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_MEMCPY_INDEXED_COPY - Copying data using array indexing. Using this option, disables the CONFIG_MEMCPY_PRE_INC_PTRS option. - CONFIG_MEMCPY_64BIT - Compiles memcpy for 64 bit architectures + CONFIG_MEMCPY_64BIT - Compiles memcpy for architectures that suppport + 64-bit operations efficiently. If CONFIG_ARCH_MEMSET is not selected, then the following option is also available: @@ -647,7 +649,8 @@ defconfig -- This is a configuration file similar to the Linux And if CONFIG_MEMSET_OPTSPEED is selected, the following tuning option is available: - CONFIG_MEMSET_64BIT - Compiles memset() for 64 bit architectures + CONFIG_MEMSET_64BIT - Compiles memset() for architectures that suppport + 64-bit operations efficiently. The architecture may provide custom versions of certain standard header files: diff --git a/nuttx/lib/Kconfig b/nuttx/lib/Kconfig index 80c584ce9..ddd5e2dde 100644 --- a/nuttx/lib/Kconfig +++ b/nuttx/lib/Kconfig @@ -165,8 +165,8 @@ config MEMCPY_VIK depends on !ARCH_MEMCPY ---help--- Select this option to use the optimized memcpy() function by Daniel Vik. - Select this option to option for speed at the expense of increased size. - See licensing information in the top-level COPYING file. + Select this option for improved performance at the expense of increased + size. See licensing information in the top-level COPYING file. if MEMCPY_VIK config MEMCPY_PRE_INC_PTRS @@ -186,7 +186,8 @@ config MEMCPY_64BIT bool "64-bit memcpy()" default n ---help--- - Compiles memcpy() for 64 bit architectures + Compiles memcpy() for architectures that suppport 64-bit operations + efficiently. endif @@ -224,7 +225,8 @@ config MEMSET_64BIT default n depends on MEMSET_OPTSPEED ---help--- - Compiles memset() for 64 bit architectures + Compiles memset() for architectures that suppport 64-bit operations + efficiently. config ARCH_STRCMP bool "strcmp()" diff --git a/nuttx/lib/string/lib_memset.c b/nuttx/lib/string/lib_memset.c index 902a040c5..31c386e92 100644 --- a/nuttx/lib/string/lib_memset.c +++ b/nuttx/lib/string/lib_memset.c @@ -92,7 +92,7 @@ void *memset(void *s, int c, size_t n) n -= 1; } - /* Check if there are at least 16-bits left to be zeroed */ + /* Check if there are at least 16-bits left to be written */ if (n >= 2) { @@ -108,7 +108,7 @@ void *memset(void *s, int c, size_t n) } #ifndef CONFIG_MEMSET_64BIT - /* Loop while there are at least 32-bits left to be zeroed */ + /* Loop while there are at least 32-bits left to be written */ while (n >= 4) { @@ -117,7 +117,7 @@ void *memset(void *s, int c, size_t n) n -= 4; } #else - /* Check if there are at least 32-bits left to be zeroed */ + /* Check if there are at least 32-bits left to be written */ if (n >= 4) { @@ -132,7 +132,7 @@ void *memset(void *s, int c, size_t n) n -= 4; } - /* Loop while there are at least 64-bits left to be zeroed */ + /* Loop while there are at least 64-bits left to be written */ while (n >= 8) { @@ -145,16 +145,16 @@ void *memset(void *s, int c, size_t n) } #ifdef CONFIG_MEMSET_64BIT - /* We may get here with n in the range 0..7. If n >= 4, then we should - * have 64-bit alignment. - */ - - if (n >= 4) - { - *(uint32_t*)addr = val32; - addr += 4; - n -= 4; - } + /* We may get here with n in the range 0..7. If n >= 4, then we should + * have 64-bit alignment. + */ + + if (n >= 4) + { + *(uint32_t*)addr = val32; + addr += 4; + n -= 4; + } #endif /* We may get here under the following conditions: @@ -165,23 +165,16 @@ void *memset(void *s, int c, size_t n) * n = 3, addr is aligned to a 32-bit boundary */ - switch (n) + if (n >= 2) { - default: - case 0: - DEBUGASSERT(n == 0); - break; - - case 2: - *(uint16_t*)addr = val16; - break; - - case 3: - *(uint16_t*)addr = val16; - addr += 2; - case 1: - *(uint8_t*)addr = (uint8_t)c; - break; + *(uint16_t*)addr = val16; + addr += 2; + n -= 2; + } + + if (n >= 1) + { + *(uint8_t*)addr = (uint8_t)c; } } #else -- cgit v1.2.3