From 9b4b10a31954c00813a7cbf9411d30bc84eccea8 Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 17 Apr 2021 23:38:23 +0200 Subject: add memset --- lib/src/common.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/src/common.c (limited to 'lib/src/common.c') diff --git a/lib/src/common.c b/lib/src/common.c new file mode 100644 index 0000000..2d122f5 --- /dev/null +++ b/lib/src/common.c @@ -0,0 +1,18 @@ +// Copyright (c) 2021 Johannes Stoelp + +#include + +#if !defined(__linux__) || !defined(__x86_64__) +# error "Only supported on linux(x86_64)!" +#endif + +void* memset(void* s, int c, size_t n) { + asm volatile( + "cld" + "\n" + "rep stosb" + : "+D"(s), "+c"(n) + : "a"(c) + : "memory"); + return s; +} -- cgit v1.2.3