From 298aaf63f15350e6248d5a96e8c6a63b0ec93e0f Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 20 May 2021 20:41:24 +0200 Subject: Major restructuring --- libs/libc/crypto.c | 2 +- libs/libc/mem.c | 54 ++++++------------------------------------------------ libs/libc/print.c | 4 ++-- libs/libc/rand.c | 2 +- libs/libc/str.c | 2 +- 5 files changed, 11 insertions(+), 53 deletions(-) (limited to 'libs') diff --git a/libs/libc/crypto.c b/libs/libc/crypto.c index c2d51ba..7681e80 100644 --- a/libs/libc/crypto.c +++ b/libs/libc/crypto.c @@ -167,7 +167,7 @@ u32 crc32(u32 crc, const void *buf, u32 size) #ifdef KERNEL -#include +#include u32 crc32_user(u32 crc, const void *buf, u32 size) { stac(); diff --git a/libs/libc/mem.c b/libs/libc/mem.c index babec3a..080c88d 100644 --- a/libs/libc/mem.c +++ b/libs/libc/mem.c @@ -7,38 +7,6 @@ void *memcpy(void *dest, const void *src, u32 n) { -#ifdef USER - // Inspired by Jeko at osdev - u8 *dest_byte = dest; - const u8 *src_byte = src; - for (u32 i = 0; i < n / 16; i++) { - __asm__ volatile("movups (%0), %%xmm0\n" - "movntdq %%xmm0, (%1)\n" ::"r"(src_byte), - "r"(dest_byte) - : "memory"); - - src_byte += 16; - dest_byte += 16; - } - - if (n & 7) { - n = n & 7; - - int d0, d1, d2; - __asm__ volatile("rep ; movsl\n\t" - "testb $2,%b4\n\t" - "je 1f\n\t" - "movsw\n" - "1:\ttestb $1,%b4\n\t" - "je 2f\n\t" - "movsb\n" - "2:" - : "=&c"(d0), "=&D"(d1), "=&S"(d2) - : "0"(n / 4), "q"(n), "1"((long)dest_byte), "2"((long)src_byte) - : "memory"); - } - return dest_byte; -#else // Inspired by jgraef at osdev u32 num_dwords = n / 4; u32 num_bytes = n % 4; @@ -47,25 +15,20 @@ void *memcpy(void *dest, const void *src, u32 n) u8 *dest8 = ((u8 *)dest) + num_dwords * 4; const u8 *src8 = ((const u8 *)src) + num_dwords * 4; - // TODO: What's faster? __asm__ volatile("rep movsl\n" : "=S"(src32), "=D"(dest32), "=c"(num_dwords) : "S"(src32), "D"(dest32), "c"(num_dwords) : "memory"); - /* for (u32 i = 0; i < num_dwords; i++) { */ - /* dest32[i] = src32[i]; */ - /* } */ - - for (u32 i = 0; i < num_bytes; i++) { + for (u32 i = 0; i < num_bytes; i++) dest8[i] = src8[i]; - } + return dest; -#endif } void *memset(void *dest, u32 val, u32 n) { + // Inspired by jgraef at osdev u32 uval = val; u32 num_dwords = n / 4; u32 num_bytes = n % 4; @@ -74,19 +37,14 @@ void *memset(void *dest, u32 val, u32 n) u8 val8 = (u8)val; u32 val32 = uval | (uval << 8) | (uval << 16) | (uval << 24); - // TODO: What's faster? __asm__ volatile("rep stosl\n" : "=D"(dest32), "=c"(num_dwords) : "D"(dest32), "c"(num_dwords), "a"(val32) : "memory"); - /* for (u32 i = 0; i < num_dwords; i++) { */ - /* dest32[i] = val32; */ - /* } */ - - for (u32 i = 0; i < num_bytes; i++) { + for (u32 i = 0; i < num_bytes; i++) dest8[i] = val8; - } + return dest; } @@ -122,7 +80,7 @@ u8 mememp(const u8 *buf, u32 n) #ifdef KERNEL -#include +#include void *memcpy_user(void *dest, const void *src, u32 n) { diff --git a/libs/libc/print.c b/libs/libc/print.c index 463fef6..46483cd 100644 --- a/libs/libc/print.c +++ b/libs/libc/print.c @@ -187,10 +187,10 @@ int print(const char *str) // The kernel prints everything into the serial console -#include +#include #include #include -#include +#include static void print_kernel(const char *str) { diff --git a/libs/libc/rand.c b/libs/libc/rand.c index 268a21f..ae715b0 100644 --- a/libs/libc/rand.c +++ b/libs/libc/rand.c @@ -5,7 +5,7 @@ #include #ifdef KERNEL -#include +#include #endif static u32 g_seed = 1; diff --git a/libs/libc/str.c b/libs/libc/str.c index 9a30e92..9e1bb2f 100644 --- a/libs/libc/str.c +++ b/libs/libc/str.c @@ -231,7 +231,7 @@ const char *strerror(u32 error) #ifdef KERNEL -#include +#include u32 strlen_user(const char *str) { -- cgit v1.2.3