kernel: Use compiler-builtin memset, memcpy, memmove, memcmp.
Since the kernel is built with -ffreestanding, and thus -fno-builtin, the compiler ignores the function names and doesn't perform optimizations (e.g. inlining for small values) that it otherwise could. So, here, we add a string.h that supplements the default, and uses #define to reinstate the builtins, and thus the optimizations. Linux and FreeBSD at least apparently do the same. A quick compile benchmark in a VM doesn't show much difference, maybe a slight decrease in sys time.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2026, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef KERNEL_STRING_H
|
||||
#define KERNEL_STRING_H
|
||||
|
||||
|
||||
#include_next <string.h>
|
||||
|
||||
|
||||
#define memset(DEST, V, LEN) __builtin_memset((DEST), (V), (LEN))
|
||||
#define memcpy(DEST, SRC, LEN) __builtin_memcpy((DEST), (SRC), (LEN))
|
||||
#define memmove(DEST, SRC, LEN) __builtin_memmove((DEST), (SRC), (LEN))
|
||||
#define memcmp(B1, B2, LEN) __builtin_memcmp((B1), (B2), (LEN))
|
||||
|
||||
|
||||
#endif /* KERNEL_STRING_H */
|
||||
Reference in New Issue
Block a user