mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
string: better memset and memcpy
This commit is contained in:
@@ -3,20 +3,26 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void *memcpy(void *d, void *s, size_t c) {
|
void *memcpy(void *d, void *s, size_t c) {
|
||||||
|
#ifdef __x86_64__
|
||||||
|
asm volatile ("rep movsb" : : "S"(s), "D"(d), "c"(c) : "memory");
|
||||||
|
#else
|
||||||
uint8_t *sc = (uint8_t *)s;
|
uint8_t *sc = (uint8_t *)s;
|
||||||
uint8_t *dc = (uint8_t *)d;
|
uint8_t *dc = (uint8_t *)d;
|
||||||
|
|
||||||
while (c--)
|
while (c--)
|
||||||
*dc++ = *sc++;
|
*dc++ = *sc++;
|
||||||
|
#endif
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *memset(void *ptr, unsigned long value, size_t num) {
|
void *memset(void *ptr, unsigned long value, size_t num) {
|
||||||
|
#ifdef __x86_64__
|
||||||
|
asm volatile ("rep stosb" : : "D"(ptr), "a"(value), "c"(num) : "memory");
|
||||||
|
#else
|
||||||
char *p = (char *)ptr;
|
char *p = (char *)ptr;
|
||||||
while (num--)
|
while (num--)
|
||||||
*p++ = value;
|
*p++ = value;
|
||||||
|
#endif
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user