diff options
Diffstat (limited to 'src/wincrt.c')
| -rw-r--r-- | src/wincrt.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/wincrt.c b/src/wincrt.c index ced1203..9a0326b 100644 --- a/src/wincrt.c +++ b/src/wincrt.c @@ -10,11 +10,15 @@ // // Is it actually reasonable to have to do any of this? Of course not. +// Note: these functions have ifdefs with non-asm fallbacks just in case this +// file is ever useful somewhere else, but generally we assume this codebase +// will be built with Clang. + int memcmp(const void *restrict x, const void *restrict y, unsigned int sz) { #if defined(__GNUC__) || defined(__clang__) int a, b; - __asm__ volatile ( - "xor %%eax, %%eax\n" + __asm volatile ( + "xor eax, eax\n" "repz cmpsb\n" : "+D" (x), "+S" (y), "+c" (sz), "=@cca"(a), "=@ccb"(b) : @@ -34,7 +38,7 @@ int memcmp(const void *restrict x, const void *restrict y, unsigned int sz) { void *memcpy(void *restrict x, const void *restrict y, unsigned int sz) { #if defined(__GNUC__) || defined(__clang__) void *r = x; - __asm__ volatile ( + __asm volatile ( "rep movsb\n" : "+D" (x), "+S" (y), "+c" (sz) : @@ -48,13 +52,30 @@ void *memcpy(void *restrict x, const void *restrict y, unsigned int sz) { #endif } +void *memset(void *x, int c, unsigned int sz) { +#if defined(__GNUC__) || defined(__clang__) + void *r = x; + __asm volatile ( + "rep stosb\n" + : "+D" (x), "+c" (sz) + : "a"(c) + : "memory" + ); + return r; +#else + const unsigned char *xb = x; + for (unsigned int i = 0; i < len; ++i) xb[i] = (unsigned char)c; + return x; +#endif +} + int __stdcall _DllMainCRTStartup(void *inst, unsigned int reason, void *reserved) { return 1; } #ifdef __clang__ -__attribute__((used)) +__attribute((used)) #endif int _fltused = 1; |
