diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-10-21 05:38:24 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-10-21 05:38:24 +0000 |
commit | d7f2428afb540539a14827ecb2d757329acb71c9 (patch) | |
tree | 3c9da87356041eb924bad896997acbc8e421fcd5 /nuttx/lib | |
parent | 1c8f16b1684773cc2b47867b9224154fba1dc1ac (diff) | |
download | px4-nuttx-d7f2428afb540539a14827ecb2d757329acb71c9.tar.gz px4-nuttx-d7f2428afb540539a14827ecb2d757329acb71c9.tar.bz2 px4-nuttx-d7f2428afb540539a14827ecb2d757329acb71c9.zip |
Minor tweaks to memset
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5245 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r-- | nuttx/lib/Kconfig | 10 | ||||
-rw-r--r-- | nuttx/lib/string/lib_memset.c | 53 |
2 files changed, 29 insertions, 34 deletions
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 |