BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
c89d999
Branches
Tags
master
mips_sys
fw
memcpy.c
implement menu on LCD
Stefan Schuermans
commited
c89d999
at 2012-04-04 22:26:27
memcpy.c
Blame
History
Raw
#include "memcpy.h" /** * @brief copy memory * @param[in] dest pointer to destination buffer * @param[in] src pointer to source data * @param[in] sz size of data to copy */ void memcpy(void *dest, const void *src, unsigned int sz) { unsigned int *dest4; const unsigned int *src4; unsigned int sz4; unsigned char *dest1; const unsigned char *src1; // word aligned memory addresses -> fast copy if (((unsigned int)dest & 3) == 0 && ((unsigned int)src & 3) == 0) { dest4 = dest; src4 = src; sz4 = sz >> 2; for ( ; sz4 > 0; --sz4) *dest4++ = *src4++; // there might still be a few bytes to copy now dest = dest4; src = src4; sz &= 3; } // safe and slow fallback: copy byte-wise dest1 = dest; src1 = src; for ( ; sz > 0; --sz) *dest1++ = *src1++; } /** * @brief set memory to fixed value * @param[in] dest pointer to destination buffer * @param[in] val fixed value to fill memory with * @param[in] sz size of memory to fill */ void memset(void *dest, int val, unsigned int sz) { unsigned char val1; unsigned int *dest4; unsigned int val4; unsigned int sz4; unsigned char *dest1; val1 = val; // word aligned memory address -> fast fill if (((unsigned int)dest & 3) == 0) { dest4 = dest; val4 = val1; val4 |= val4 << 8; val4 |= val4 << 16; sz4 = sz >> 2; for ( ; sz4 > 0; --sz4) *dest4++ = val4; // there might still be a few bytes to fill now dest = dest4; sz &= 3; } // safe and slow fallback: fill byte-wise dest1 = dest; for ( ; sz > 0; --sz) *dest1++ = val1; }