From ecd78d08e9c98b1c590ae27940f04d29402d5539 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Thu, 27 Jan 2022 18:36:32 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E5=A2=9E=E5=8A=A0=E4=BA=86memset?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=88=E6=B1=87=E7=BC=96=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/common/glib.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/kernel/common/glib.h b/kernel/common/glib.h index ed4b522d..e6e7b425 100644 --- a/kernel/common/glib.h +++ b/kernel/common/glib.h @@ -112,3 +112,27 @@ static inline int strlen(char *s) return __res; } + + +inline void *memset(void *dst, unsigned char C, ul Count) +{ + 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"(Count), "0"(Count / 8), "1"(dst) + : "memory"); + return dst; +}