mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 17:26:31 +00:00
🆕 malloc 、printf
This commit is contained in:
37
user/libs/libc/string.h
Normal file
37
user/libs/libc/string.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <libc/sys/types.h>
|
||||
|
||||
void *memset(void *dst, unsigned char C, uint64_t size)
|
||||
{
|
||||
|
||||
int d0, d1;
|
||||
unsigned long tmp = C * 0x0101010101010101UL;
|
||||
__asm__ __volatile__("cld \n\t"
|
||||
"rep \n\t"
|
||||
"stosq \n\t"
|
||||
"testb $4, %b3 \n\t"
|
||||
"je 1f \n\t"
|
||||
"stosl \n\t"
|
||||
"1:\ttestb $2, %b3 \n\t"
|
||||
"je 2f\n\t"
|
||||
"stosw \n\t"
|
||||
"2:\ttestb $1, %b3 \n\t"
|
||||
"je 3f \n\t"
|
||||
"stosb \n\t"
|
||||
"3: \n\t"
|
||||
: "=&c"(d0), "=&D"(d1)
|
||||
: "a"(tmp), "q"(size), "0"(size / 8), "1"(dst)
|
||||
: "memory");
|
||||
return dst;
|
||||
}
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
register size_t __res = 0;
|
||||
while (s[__res] != '\0')
|
||||
{
|
||||
++__res;
|
||||
}
|
||||
return __res;
|
||||
}
|
Reference in New Issue
Block a user