Decoupling Architectural-specific Code (#35)
[lunaix-os.git] / lunaix-os / arch / i386 / klib / fast_crc.c
diff --git a/lunaix-os/arch/i386/klib/fast_crc.c b/lunaix-os/arch/i386/klib/fast_crc.c
new file mode 100644 (file)
index 0000000..2384390
--- /dev/null
@@ -0,0 +1,24 @@
+#include <lunaix/types.h>
+#include <klibc/crc.h>
+
+#ifdef CONFIG_X86_SSE4
+unsigned int
+crc32b(unsigned char* data, unsigned int size)
+{
+    unsigned int ret;
+    asm volatile(
+        "xorl %%ebx, %%ebx\n"
+        "xorl %%eax, %%eax\n"
+        "1:\n"
+        "crc32 (%%edx, %%ebx, 1), %%eax\n"
+        "incl %%ebx\n"
+        "cmpl %%ebx, %%ecx\n"
+        "jne 1b\n"
+        : "=a"(ret)
+        : "d"((ptr_t)data),
+          "c"(size)
+        :
+    );
+    return ret;
+}
+#endif
\ No newline at end of file