Browse Source

:new: 增加了memset函数(汇编实现)

fslongjin 3 years ago
parent
commit
ecd78d08e9
1 changed files with 24 additions and 0 deletions
  1. 24 0
      kernel/common/glib.h

+ 24 - 0
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;
+}