summaryrefslogtreecommitdiff
path: root/nuttx/lib/string/lib_memset.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-21 05:38:24 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-21 05:38:24 +0000
commitd7f2428afb540539a14827ecb2d757329acb71c9 (patch)
tree3c9da87356041eb924bad896997acbc8e421fcd5 /nuttx/lib/string/lib_memset.c
parent1c8f16b1684773cc2b47867b9224154fba1dc1ac (diff)
downloadpx4-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/string/lib_memset.c')
-rw-r--r--nuttx/lib/string/lib_memset.c53
1 files changed, 23 insertions, 30 deletions
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