Skip to content

Commit

Permalink
memset:optimizate speed.
Browse files Browse the repository at this point in the history
Signed-off-by: yangguangcai <[email protected]>
  • Loading branch information
yangguangcai1 authored and xiaoxiang781216 committed Aug 26, 2024
1 parent d6cd953 commit f44232b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libs/libc/string/lib_memset.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ FAR void *memset(FAR void *s, int c, size_t n)
}

#ifndef CONFIG_MEMSET_64BIT
/* Loop while there are at least 16-bytes left to be written */

while (n >= 16)
{
*(FAR uint32_t *)(addr + 0) = val32;
*(FAR uint32_t *)(addr + 4) = val32;
*(FAR uint32_t *)(addr + 8) = val32;
*(FAR uint32_t *)(addr + 12) = val32;
addr += 16;
n -= 16;
}

/* Loop while there are at least 32-bits left to be written */

while (n >= 4)
Expand All @@ -119,6 +131,22 @@ FAR void *memset(FAR void *s, int c, size_t n)
n -= 4;
}

/* Loop while there are at least 64-bytes left to be written */

while (n >= 64)
{
*(FAR uint64_t *)(addr + 0) = val64;
*(FAR uint64_t *)(addr + 8) = val64;
*(FAR uint64_t *)(addr + 16) = val64;
*(FAR uint64_t *)(addr + 24) = val64;
*(FAR uint64_t *)(addr + 32) = val64;
*(FAR uint64_t *)(addr + 40) = val64;
*(FAR uint64_t *)(addr + 48) = val64;
*(FAR uint64_t *)(addr + 56) = val64;
addr += 64;
n -= 64;
}

/* Loop while there are at least 64-bits left to be written */

while (n >= 8)
Expand Down

0 comments on commit f44232b

Please sign in to comment.