mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-10 23:09:18 +00:00
Update kernel
This commit is contained in:
@ -63,11 +63,23 @@ EXTERNC int strncmp(const char *s1, const char *s2, size_t n)
|
||||
|
||||
EXTERNC long unsigned strlen(const char s[])
|
||||
{
|
||||
long unsigned i = 0;
|
||||
if (s)
|
||||
while (s[i] != '\0')
|
||||
++i;
|
||||
return i;
|
||||
if (Config.SIMD)
|
||||
{
|
||||
uint64_t simd = CPU::CheckSIMD();
|
||||
if (simd & CPU::x86SIMDType::SIMD_SSE42)
|
||||
return strlen_sse4_2(s);
|
||||
else if (simd & CPU::x86SIMDType::SIMD_SSE41)
|
||||
return strlen_sse4_1(s);
|
||||
else if (simd & CPU::x86SIMDType::SIMD_SSSE3)
|
||||
return strlen_ssse3(s);
|
||||
else if (simd & CPU::x86SIMDType::SIMD_SSE3)
|
||||
return strlen_sse3(s);
|
||||
else if (simd & CPU::x86SIMDType::SIMD_SSE2)
|
||||
return strlen_sse2(s);
|
||||
else if (simd & CPU::x86SIMDType::SIMD_SSE)
|
||||
return strlen_sse(s);
|
||||
}
|
||||
return __strlen(s);
|
||||
}
|
||||
|
||||
EXTERNC char *strcat_unsafe(char *destination, const char *source)
|
||||
@ -128,6 +140,19 @@ EXTERNC int strcmp(const char *l, const char *r)
|
||||
return *(unsigned char *)l - *(unsigned char *)r;
|
||||
}
|
||||
|
||||
EXTERNC int strncasecmp(const char *string1, const char *string2, size_t count)
|
||||
{
|
||||
int result = 0;
|
||||
while (count--)
|
||||
{
|
||||
if ((result = std::tolower(*string1) - std::tolower(*string2)) != 0 || !*string1)
|
||||
break;
|
||||
string1++;
|
||||
string2++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
EXTERNC char *strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
const char *a = haystack, *b = needle;
|
||||
@ -147,6 +172,8 @@ EXTERNC char *strstr(const char *haystack, const char *needle)
|
||||
|
||||
EXTERNC char *strchr(const char *String, int Char)
|
||||
{
|
||||
assert(String != NULL);
|
||||
|
||||
while (*String != (char)Char)
|
||||
{
|
||||
if (!*String++)
|
||||
@ -774,7 +801,7 @@ EXTERNC __no_stack_protector void *__memcpy_chk(void *dest, const void *src, siz
|
||||
{
|
||||
error("dest is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -783,7 +810,7 @@ EXTERNC __no_stack_protector void *__memcpy_chk(void *dest, const void *src, siz
|
||||
{
|
||||
error("src is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -792,7 +819,7 @@ EXTERNC __no_stack_protector void *__memcpy_chk(void *dest, const void *src, siz
|
||||
{
|
||||
error("len is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -801,7 +828,7 @@ EXTERNC __no_stack_protector void *__memcpy_chk(void *dest, const void *src, siz
|
||||
{
|
||||
error("slen is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -810,7 +837,7 @@ EXTERNC __no_stack_protector void *__memcpy_chk(void *dest, const void *src, siz
|
||||
__chk_fail();
|
||||
|
||||
void *ret = nullptr;
|
||||
if (0) /* FIXME */
|
||||
if (Config.SIMD)
|
||||
{
|
||||
uint64_t simd = CPU::CheckSIMD();
|
||||
if (simd & CPU::x86SIMDType::SIMD_SSE42)
|
||||
@ -847,7 +874,7 @@ EXTERNC __no_stack_protector void *__memset_chk(void *dest, int val, size_t len,
|
||||
{
|
||||
error("dest is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -856,7 +883,7 @@ EXTERNC __no_stack_protector void *__memset_chk(void *dest, int val, size_t len,
|
||||
{
|
||||
error("len is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -865,7 +892,7 @@ EXTERNC __no_stack_protector void *__memset_chk(void *dest, int val, size_t len,
|
||||
{
|
||||
error("slen is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -874,7 +901,7 @@ EXTERNC __no_stack_protector void *__memset_chk(void *dest, int val, size_t len,
|
||||
__chk_fail();
|
||||
|
||||
void *ret = nullptr;
|
||||
if (0) /* FIXME */
|
||||
if (Config.SIMD)
|
||||
{
|
||||
uint64_t simd = CPU::CheckSIMD();
|
||||
if (simd & CPU::x86SIMDType::SIMD_SSE42)
|
||||
@ -912,7 +939,7 @@ EXTERNC __no_stack_protector void *__memmove_chk(void *dest, const void *src, si
|
||||
{
|
||||
error("dest is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -921,7 +948,7 @@ EXTERNC __no_stack_protector void *__memmove_chk(void *dest, const void *src, si
|
||||
{
|
||||
error("src is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -930,7 +957,7 @@ EXTERNC __no_stack_protector void *__memmove_chk(void *dest, const void *src, si
|
||||
{
|
||||
error("len is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -939,7 +966,7 @@ EXTERNC __no_stack_protector void *__memmove_chk(void *dest, const void *src, si
|
||||
{
|
||||
error("slen is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -948,7 +975,7 @@ EXTERNC __no_stack_protector void *__memmove_chk(void *dest, const void *src, si
|
||||
__chk_fail();
|
||||
|
||||
void *ret = nullptr;
|
||||
if (0) /* FIXME */
|
||||
if (Config.SIMD)
|
||||
{
|
||||
uint64_t simd = CPU::CheckSIMD();
|
||||
if (simd & CPU::x86SIMDType::SIMD_SSE42)
|
||||
@ -986,7 +1013,7 @@ EXTERNC __no_stack_protector char *__strcat_chk(char *dest, const char *src, siz
|
||||
{
|
||||
error("dest is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -995,7 +1022,7 @@ EXTERNC __no_stack_protector char *__strcat_chk(char *dest, const char *src, siz
|
||||
{
|
||||
error("src is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -1004,7 +1031,7 @@ EXTERNC __no_stack_protector char *__strcat_chk(char *dest, const char *src, siz
|
||||
{
|
||||
error("slen is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -1025,7 +1052,7 @@ EXTERNC __no_stack_protector char *__strcpy_chk(char *dest, const char *src, siz
|
||||
{
|
||||
error("dest is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -1034,7 +1061,7 @@ EXTERNC __no_stack_protector char *__strcpy_chk(char *dest, const char *src, siz
|
||||
{
|
||||
error("src is NULL (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
@ -1043,7 +1070,7 @@ EXTERNC __no_stack_protector char *__strcpy_chk(char *dest, const char *src, siz
|
||||
{
|
||||
error("slen is 0 (for %#lx %s)",
|
||||
__builtin_return_address(0),
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__builtin_return_address(0))
|
||||
KernelSymbolTable ? KernelSymbolTable->GetSymbol((uintptr_t)__builtin_return_address(0))
|
||||
: "Unknown");
|
||||
__convert_chk_fail();
|
||||
}
|
||||
|
144
library/crc32.c
144
library/crc32.c
@ -18,79 +18,79 @@
|
||||
#include <crc32.h>
|
||||
|
||||
uint32_t LookupTable[256] =
|
||||
{
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
|
||||
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
|
||||
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
|
||||
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,
|
||||
0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
||||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,
|
||||
0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
|
||||
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
||||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
|
||||
0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,
|
||||
0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
||||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,
|
||||
0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
|
||||
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
||||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
|
||||
0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,
|
||||
0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
||||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
|
||||
0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
|
||||
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
||||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
|
||||
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,
|
||||
0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
||||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,
|
||||
0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
|
||||
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
||||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
|
||||
0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
|
||||
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
||||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,
|
||||
0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
|
||||
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
||||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
|
||||
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,
|
||||
0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
||||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,
|
||||
0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
|
||||
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
||||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
|
||||
0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,
|
||||
0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
||||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,
|
||||
0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
|
||||
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
||||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
|
||||
0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,
|
||||
0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
||||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
|
||||
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
|
||||
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
||||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
|
||||
0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,
|
||||
0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
||||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,
|
||||
0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
|
||||
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
||||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
|
||||
0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
|
||||
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
||||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,
|
||||
0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
|
||||
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4};
|
||||
{
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
|
||||
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
|
||||
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
|
||||
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,
|
||||
0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
||||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,
|
||||
0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
|
||||
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
||||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
|
||||
0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,
|
||||
0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
||||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,
|
||||
0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
|
||||
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
||||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
|
||||
0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,
|
||||
0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
||||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
|
||||
0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
|
||||
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
||||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
|
||||
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,
|
||||
0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
||||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,
|
||||
0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
|
||||
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
||||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
|
||||
0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
|
||||
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
||||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,
|
||||
0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
|
||||
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
||||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
|
||||
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,
|
||||
0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
||||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,
|
||||
0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
|
||||
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
||||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
|
||||
0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,
|
||||
0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
||||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,
|
||||
0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
|
||||
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
||||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
|
||||
0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,
|
||||
0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
||||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
|
||||
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
|
||||
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
||||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
|
||||
0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,
|
||||
0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
||||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,
|
||||
0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
|
||||
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
||||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
|
||||
0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
|
||||
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
||||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,
|
||||
0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
|
||||
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4};
|
||||
|
||||
uint32_t crc32(const uint8_t *Buffer, int Length)
|
||||
{
|
||||
uint32_t ret = 0xffffffff;
|
||||
while (Length--)
|
||||
{
|
||||
ret = (ret << 8) ^ LookupTable[((ret >> 24) ^ *Buffer) & 255];
|
||||
Buffer++;
|
||||
}
|
||||
return ret;
|
||||
uint32_t ret = 0xffffffff;
|
||||
while (Length--)
|
||||
{
|
||||
ret = (ret << 8) ^ LookupTable[((ret >> 24) ^ *Buffer) & 255];
|
||||
Buffer++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -27,65 +27,59 @@ NewLock(DumperLock);
|
||||
|
||||
using namespace UniversalAsynchronousReceiverTransmitter;
|
||||
|
||||
static inline void print_wrapper(char c, void *unused)
|
||||
{
|
||||
UART(COM1).Write(c);
|
||||
UNUSED(unused);
|
||||
}
|
||||
|
||||
int vprintf_dumper(const char *format, va_list list) { return vfctprintf(print_wrapper, NULL, format, list); }
|
||||
int vprintf_dumper(const char *format, va_list list) { return vfctprintf(uart_wrapper, NULL, format, list); }
|
||||
|
||||
void WriteRaw(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf_dumper(format, args);
|
||||
va_end(args);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf_dumper(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DumpData(const char *Description, void *Address, unsigned long Length)
|
||||
{
|
||||
SmartLock(DumperLock);
|
||||
WriteRaw("-------------------------------------------------------------------------\n");
|
||||
unsigned char *AddressChar = (unsigned char *)Address;
|
||||
unsigned char Buffer[17];
|
||||
unsigned long Iterate;
|
||||
SmartLock(DumperLock);
|
||||
WriteRaw("-------------------------------------------------------------------------\n");
|
||||
unsigned char *AddressChar = (unsigned char *)Address;
|
||||
unsigned char Buffer[17];
|
||||
unsigned long Iterate;
|
||||
|
||||
if (Description != nullptr)
|
||||
WriteRaw("%s:\n", Description);
|
||||
if (Description != nullptr)
|
||||
WriteRaw("%s (%d bytes):\n", Description, Length);
|
||||
|
||||
for (Iterate = 0; Iterate < Length; Iterate++)
|
||||
{
|
||||
if ((Iterate % 16) == 0)
|
||||
{
|
||||
if (Iterate != 0)
|
||||
WriteRaw(" %s\n", Buffer);
|
||||
WriteRaw(" %04x ", Iterate);
|
||||
}
|
||||
for (Iterate = 0; Iterate < Length; Iterate++)
|
||||
{
|
||||
if ((Iterate % 16) == 0)
|
||||
{
|
||||
if (Iterate != 0)
|
||||
WriteRaw(" %s\n", Buffer);
|
||||
WriteRaw(" %04x ", Iterate);
|
||||
}
|
||||
|
||||
WriteRaw(" %02x", AddressChar[Iterate]);
|
||||
WriteRaw(" %02x", AddressChar[Iterate]);
|
||||
|
||||
if ((AddressChar[Iterate] < 0x20) || (AddressChar[Iterate] > 0x7e))
|
||||
Buffer[Iterate % 16] = '.';
|
||||
else
|
||||
Buffer[Iterate % 16] = AddressChar[Iterate];
|
||||
if ((AddressChar[Iterate] < 0x20) || (AddressChar[Iterate] > 0x7e))
|
||||
Buffer[Iterate % 16] = '.';
|
||||
else
|
||||
Buffer[Iterate % 16] = AddressChar[Iterate];
|
||||
|
||||
Buffer[(Iterate % 16) + 1] = '\0';
|
||||
}
|
||||
Buffer[(Iterate % 16) + 1] = '\0';
|
||||
}
|
||||
|
||||
while ((Iterate % 16) != 0)
|
||||
{
|
||||
WriteRaw(" ");
|
||||
Iterate++;
|
||||
}
|
||||
while ((Iterate % 16) != 0)
|
||||
{
|
||||
WriteRaw(" ");
|
||||
Iterate++;
|
||||
}
|
||||
|
||||
WriteRaw(" %s\n", Buffer);
|
||||
WriteRaw("-------------------------------------------------------------------------\n");
|
||||
WriteRaw("Length: %ld bytes\n", Length);
|
||||
uint8_t *result = md5File(AddressChar, Length);
|
||||
WriteRaw("MD5: ");
|
||||
for (int i = 0; i < 16; i++)
|
||||
WriteRaw("%02x", result[i]);
|
||||
kfree(result);
|
||||
WriteRaw("\n-------------------------------------------------------------------------\n");
|
||||
WriteRaw(" %s\n", Buffer);
|
||||
WriteRaw("-------------------------------------------------------------------------\n");
|
||||
WriteRaw("Length: %ld bytes\n", Length);
|
||||
uint8_t *result = md5File(AddressChar, Length);
|
||||
WriteRaw("MD5: ");
|
||||
for (int i = 0; i < 16; i++)
|
||||
WriteRaw("%02x", result[i]);
|
||||
kfree(result);
|
||||
WriteRaw("\n-------------------------------------------------------------------------\n");
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ namespace __cxxabiv1
|
||||
if (KernelSymbolTable)
|
||||
{
|
||||
debug("Registering atexit function for \"%s\" with destructor \"%s\"",
|
||||
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)objptr),
|
||||
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)f));
|
||||
KernelSymbolTable->GetSymbol((uintptr_t)objptr),
|
||||
KernelSymbolTable->GetSymbol((uintptr_t)f));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -79,7 +79,7 @@ namespace __cxxabiv1
|
||||
if (KernelSymbolTable)
|
||||
{
|
||||
debug("Calling atexit function \"%s\"",
|
||||
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__atexit_funcs[i].destructor_func));
|
||||
KernelSymbolTable->GetSymbol((uintptr_t)__atexit_funcs[i].destructor_func));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
502
library/memop.c
502
library/memop.c
@ -34,8 +34,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
void *memcpy_unsafe(void *dest, const void *src, size_t n)
|
||||
{
|
||||
unsigned char *d = dest;
|
||||
const unsigned char *s = src;
|
||||
unsigned char *d = dest;
|
||||
const unsigned char *s = src;
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
@ -47,305 +47,305 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
|
||||
#define RS >>
|
||||
#endif
|
||||
|
||||
typedef uint32_t __attribute__((__may_alias__)) u32;
|
||||
uint32_t w, x;
|
||||
typedef uint32_t __attribute__((__may_alias__)) u32;
|
||||
uint32_t w, x;
|
||||
|
||||
for (; (uintptr_t)s % 4 && n; n--)
|
||||
*d++ = *s++;
|
||||
for (; (uintptr_t)s % 4 && n; n--)
|
||||
*d++ = *s++;
|
||||
|
||||
if ((uintptr_t)d % 4 == 0)
|
||||
{
|
||||
for (; n >= 16; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
*(u32 *)(d + 0) = *(u32 *)(s + 0);
|
||||
*(u32 *)(d + 4) = *(u32 *)(s + 4);
|
||||
*(u32 *)(d + 8) = *(u32 *)(s + 8);
|
||||
*(u32 *)(d + 12) = *(u32 *)(s + 12);
|
||||
}
|
||||
if (n & 8)
|
||||
{
|
||||
*(u32 *)(d + 0) = *(u32 *)(s + 0);
|
||||
*(u32 *)(d + 4) = *(u32 *)(s + 4);
|
||||
d += 8;
|
||||
s += 8;
|
||||
}
|
||||
if (n & 4)
|
||||
{
|
||||
*(u32 *)(d + 0) = *(u32 *)(s + 0);
|
||||
d += 4;
|
||||
s += 4;
|
||||
}
|
||||
if (n & 2)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
if (n & 1)
|
||||
{
|
||||
*d = *s;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
if ((uintptr_t)d % 4 == 0)
|
||||
{
|
||||
for (; n >= 16; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
*(u32 *)(d + 0) = *(u32 *)(s + 0);
|
||||
*(u32 *)(d + 4) = *(u32 *)(s + 4);
|
||||
*(u32 *)(d + 8) = *(u32 *)(s + 8);
|
||||
*(u32 *)(d + 12) = *(u32 *)(s + 12);
|
||||
}
|
||||
if (n & 8)
|
||||
{
|
||||
*(u32 *)(d + 0) = *(u32 *)(s + 0);
|
||||
*(u32 *)(d + 4) = *(u32 *)(s + 4);
|
||||
d += 8;
|
||||
s += 8;
|
||||
}
|
||||
if (n & 4)
|
||||
{
|
||||
*(u32 *)(d + 0) = *(u32 *)(s + 0);
|
||||
d += 4;
|
||||
s += 4;
|
||||
}
|
||||
if (n & 2)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
if (n & 1)
|
||||
{
|
||||
*d = *s;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
if (n >= 32)
|
||||
{
|
||||
switch ((uintptr_t)d % 4)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
w = *(u32 *)s;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
n -= 3;
|
||||
for (; n >= 17; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
x = *(u32 *)(s + 1);
|
||||
*(u32 *)(d + 0) = (w LS 24) | (x RS 8);
|
||||
w = *(u32 *)(s + 5);
|
||||
*(u32 *)(d + 4) = (x LS 24) | (w RS 8);
|
||||
x = *(u32 *)(s + 9);
|
||||
*(u32 *)(d + 8) = (w LS 24) | (x RS 8);
|
||||
w = *(u32 *)(s + 13);
|
||||
*(u32 *)(d + 12) = (x LS 24) | (w RS 8);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
w = *(u32 *)s;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
n -= 2;
|
||||
for (; n >= 18; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
x = *(u32 *)(s + 2);
|
||||
*(u32 *)(d + 0) = (w LS 16) | (x RS 16);
|
||||
w = *(u32 *)(s + 6);
|
||||
*(u32 *)(d + 4) = (x LS 16) | (w RS 16);
|
||||
x = *(u32 *)(s + 10);
|
||||
*(u32 *)(d + 8) = (w LS 16) | (x RS 16);
|
||||
w = *(u32 *)(s + 14);
|
||||
*(u32 *)(d + 12) = (x LS 16) | (w RS 16);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
w = *(u32 *)s;
|
||||
*d++ = *s++;
|
||||
n -= 1;
|
||||
for (; n >= 19; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
x = *(u32 *)(s + 3);
|
||||
*(u32 *)(d + 0) = (w LS 8) | (x RS 24);
|
||||
w = *(u32 *)(s + 7);
|
||||
*(u32 *)(d + 4) = (x LS 8) | (w RS 24);
|
||||
x = *(u32 *)(s + 11);
|
||||
*(u32 *)(d + 8) = (w LS 8) | (x RS 24);
|
||||
w = *(u32 *)(s + 15);
|
||||
*(u32 *)(d + 12) = (x LS 8) | (w RS 24);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n >= 32)
|
||||
{
|
||||
switch ((uintptr_t)d % 4)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
w = *(u32 *)s;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
n -= 3;
|
||||
for (; n >= 17; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
x = *(u32 *)(s + 1);
|
||||
*(u32 *)(d + 0) = (w LS 24) | (x RS 8);
|
||||
w = *(u32 *)(s + 5);
|
||||
*(u32 *)(d + 4) = (x LS 24) | (w RS 8);
|
||||
x = *(u32 *)(s + 9);
|
||||
*(u32 *)(d + 8) = (w LS 24) | (x RS 8);
|
||||
w = *(u32 *)(s + 13);
|
||||
*(u32 *)(d + 12) = (x LS 24) | (w RS 8);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
w = *(u32 *)s;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
n -= 2;
|
||||
for (; n >= 18; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
x = *(u32 *)(s + 2);
|
||||
*(u32 *)(d + 0) = (w LS 16) | (x RS 16);
|
||||
w = *(u32 *)(s + 6);
|
||||
*(u32 *)(d + 4) = (x LS 16) | (w RS 16);
|
||||
x = *(u32 *)(s + 10);
|
||||
*(u32 *)(d + 8) = (w LS 16) | (x RS 16);
|
||||
w = *(u32 *)(s + 14);
|
||||
*(u32 *)(d + 12) = (x LS 16) | (w RS 16);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
w = *(u32 *)s;
|
||||
*d++ = *s++;
|
||||
n -= 1;
|
||||
for (; n >= 19; s += 16, d += 16, n -= 16)
|
||||
{
|
||||
x = *(u32 *)(s + 3);
|
||||
*(u32 *)(d + 0) = (w LS 8) | (x RS 24);
|
||||
w = *(u32 *)(s + 7);
|
||||
*(u32 *)(d + 4) = (x LS 8) | (w RS 24);
|
||||
x = *(u32 *)(s + 11);
|
||||
*(u32 *)(d + 8) = (w LS 8) | (x RS 24);
|
||||
w = *(u32 *)(s + 15);
|
||||
*(u32 *)(d + 12) = (x LS 8) | (w RS 24);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (n & 16)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
if (n & 16)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
|
||||
if (n & 8)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
if (n & 8)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
|
||||
if (n & 4)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
if (n & 4)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
|
||||
if (n & 2)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
if (n & 2)
|
||||
{
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
}
|
||||
|
||||
if (n & 1)
|
||||
{
|
||||
*d = *s;
|
||||
}
|
||||
return dest;
|
||||
if (n & 1)
|
||||
{
|
||||
*d = *s;
|
||||
}
|
||||
return dest;
|
||||
#endif
|
||||
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
return dest;
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memset_unsafe(void *dest, int c, size_t n)
|
||||
{
|
||||
unsigned char *s = dest;
|
||||
size_t k;
|
||||
unsigned char *s = dest;
|
||||
size_t k;
|
||||
|
||||
if (!n)
|
||||
return dest;
|
||||
if (!n)
|
||||
return dest;
|
||||
|
||||
s[0] = c;
|
||||
s[n - 1] = c;
|
||||
s[0] = c;
|
||||
s[n - 1] = c;
|
||||
|
||||
if (n <= 2)
|
||||
return dest;
|
||||
if (n <= 2)
|
||||
return dest;
|
||||
|
||||
s[1] = c;
|
||||
s[2] = c;
|
||||
s[n - 2] = c;
|
||||
s[n - 3] = c;
|
||||
s[1] = c;
|
||||
s[2] = c;
|
||||
s[n - 2] = c;
|
||||
s[n - 3] = c;
|
||||
|
||||
if (n <= 6)
|
||||
return dest;
|
||||
if (n <= 6)
|
||||
return dest;
|
||||
|
||||
s[3] = c;
|
||||
s[n - 4] = c;
|
||||
s[3] = c;
|
||||
s[n - 4] = c;
|
||||
|
||||
if (n <= 8)
|
||||
return dest;
|
||||
if (n <= 8)
|
||||
return dest;
|
||||
|
||||
k = -(uintptr_t)s & 3;
|
||||
s += k;
|
||||
n -= k;
|
||||
n &= -4;
|
||||
k = -(uintptr_t)s & 3;
|
||||
s += k;
|
||||
n -= k;
|
||||
n &= -4;
|
||||
|
||||
#ifdef __GNUC__
|
||||
typedef uint32_t __attribute__((__may_alias__)) u32;
|
||||
typedef uint64_t __attribute__((__may_alias__)) u64;
|
||||
typedef uint32_t __attribute__((__may_alias__)) u32;
|
||||
typedef uint64_t __attribute__((__may_alias__)) u64;
|
||||
|
||||
u32 c32 = ((u32)-1) / 255 * (unsigned char)c;
|
||||
*(u32 *)(s + 0) = c32;
|
||||
*(u32 *)(s + n - 4) = c32;
|
||||
u32 c32 = ((u32)-1) / 255 * (unsigned char)c;
|
||||
*(u32 *)(s + 0) = c32;
|
||||
*(u32 *)(s + n - 4) = c32;
|
||||
|
||||
if (n <= 8)
|
||||
return dest;
|
||||
if (n <= 8)
|
||||
return dest;
|
||||
|
||||
*(u32 *)(s + 4) = c32;
|
||||
*(u32 *)(s + 8) = c32;
|
||||
*(u32 *)(s + n - 12) = c32;
|
||||
*(u32 *)(s + n - 8) = c32;
|
||||
*(u32 *)(s + 4) = c32;
|
||||
*(u32 *)(s + 8) = c32;
|
||||
*(u32 *)(s + n - 12) = c32;
|
||||
*(u32 *)(s + n - 8) = c32;
|
||||
|
||||
if (n <= 24)
|
||||
return dest;
|
||||
if (n <= 24)
|
||||
return dest;
|
||||
|
||||
*(u32 *)(s + 12) = c32;
|
||||
*(u32 *)(s + 16) = c32;
|
||||
*(u32 *)(s + 20) = c32;
|
||||
*(u32 *)(s + 24) = c32;
|
||||
*(u32 *)(s + n - 28) = c32;
|
||||
*(u32 *)(s + n - 24) = c32;
|
||||
*(u32 *)(s + n - 20) = c32;
|
||||
*(u32 *)(s + n - 16) = c32;
|
||||
*(u32 *)(s + 12) = c32;
|
||||
*(u32 *)(s + 16) = c32;
|
||||
*(u32 *)(s + 20) = c32;
|
||||
*(u32 *)(s + 24) = c32;
|
||||
*(u32 *)(s + n - 28) = c32;
|
||||
*(u32 *)(s + n - 24) = c32;
|
||||
*(u32 *)(s + n - 20) = c32;
|
||||
*(u32 *)(s + n - 16) = c32;
|
||||
|
||||
k = 24 + ((uintptr_t)s & 4);
|
||||
s += k;
|
||||
n -= k;
|
||||
k = 24 + ((uintptr_t)s & 4);
|
||||
s += k;
|
||||
n -= k;
|
||||
|
||||
u64 c64 = c32 | ((u64)c32 << 32);
|
||||
for (; n >= 32; n -= 32, s += 32)
|
||||
{
|
||||
*(u64 *)(s + 0) = c64;
|
||||
*(u64 *)(s + 8) = c64;
|
||||
*(u64 *)(s + 16) = c64;
|
||||
*(u64 *)(s + 24) = c64;
|
||||
}
|
||||
u64 c64 = c32 | ((u64)c32 << 32);
|
||||
for (; n >= 32; n -= 32, s += 32)
|
||||
{
|
||||
*(u64 *)(s + 0) = c64;
|
||||
*(u64 *)(s + 8) = c64;
|
||||
*(u64 *)(s + 16) = c64;
|
||||
*(u64 *)(s + 24) = c64;
|
||||
}
|
||||
#else
|
||||
for (; n; n--, s++)
|
||||
*s = c;
|
||||
for (; n; n--, s++)
|
||||
*s = c;
|
||||
#endif
|
||||
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memmove_unsafe(void *dest, const void *src, size_t n)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
typedef __attribute__((__may_alias__)) size_t WT;
|
||||
typedef __attribute__((__may_alias__)) size_t WT;
|
||||
#define WS (sizeof(WT))
|
||||
#endif
|
||||
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
|
||||
if (d == s)
|
||||
return d;
|
||||
if (d == s)
|
||||
return d;
|
||||
|
||||
if ((uintptr_t)s - (uintptr_t)d - n <= -2 * n)
|
||||
return memcpy(d, s, n);
|
||||
if ((uintptr_t)s - (uintptr_t)d - n <= -2 * n)
|
||||
return memcpy(d, s, n);
|
||||
|
||||
if (d < s)
|
||||
{
|
||||
if (d < s)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
if ((uintptr_t)s % WS == (uintptr_t)d % WS)
|
||||
{
|
||||
while ((uintptr_t)d % WS)
|
||||
{
|
||||
if (!n--)
|
||||
return dest;
|
||||
if ((uintptr_t)s % WS == (uintptr_t)d % WS)
|
||||
{
|
||||
while ((uintptr_t)d % WS)
|
||||
{
|
||||
if (!n--)
|
||||
return dest;
|
||||
|
||||
*d++ = *s++;
|
||||
}
|
||||
for (; n >= WS; n -= WS, d += WS, s += WS)
|
||||
*(WT *)d = *(WT *)s;
|
||||
}
|
||||
*d++ = *s++;
|
||||
}
|
||||
for (; n >= WS; n -= WS, d += WS, s += WS)
|
||||
*(WT *)d = *(WT *)s;
|
||||
}
|
||||
#endif
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
if ((uintptr_t)s % WS == (uintptr_t)d % WS)
|
||||
{
|
||||
while ((uintptr_t)(d + n) % WS)
|
||||
{
|
||||
if (!n--)
|
||||
return dest;
|
||||
if ((uintptr_t)s % WS == (uintptr_t)d % WS)
|
||||
{
|
||||
while ((uintptr_t)(d + n) % WS)
|
||||
{
|
||||
if (!n--)
|
||||
return dest;
|
||||
|
||||
d[n] = s[n];
|
||||
}
|
||||
while (n >= WS)
|
||||
n -= WS, *(WT *)(d + n) = *(WT *)(s + n);
|
||||
}
|
||||
d[n] = s[n];
|
||||
}
|
||||
while (n >= WS)
|
||||
n -= WS, *(WT *)(d + n) = *(WT *)(s + n);
|
||||
}
|
||||
#endif
|
||||
while (n)
|
||||
n--, d[n] = s[n];
|
||||
}
|
||||
while (n)
|
||||
n--, d[n] = s[n];
|
||||
}
|
||||
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
@ -24,172 +24,257 @@
|
||||
|
||||
/*
|
||||
TODO: Replace these functions with even more optimized versions.
|
||||
The current versions are fast but not as fast as they could be and also we need implementation for avx, not only sse.
|
||||
The current versions are fast but not as fast as they could be and also we need implementation for avx, not only sse.
|
||||
*/
|
||||
|
||||
EXTERNC void *memcpy_sse(void *dest, const void *src, size_t n)
|
||||
{
|
||||
#if defined(a64)
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movaps (%0), %%xmm0\n"
|
||||
"movaps %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movaps (%0), %%xmm0\n"
|
||||
"movaps %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movups (%0), %%xmm0\n"
|
||||
"movups %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
|
||||
memcpy_unsafe(d, s, n);
|
||||
memcpy_unsafe(d, s, n);
|
||||
#endif // defined(a64)
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
EXTERNC void *memcpy_sse2(void *dest, const void *src, size_t n)
|
||||
{
|
||||
#if defined(a64)
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqu (%0), %%xmm0\n"
|
||||
"movdqu %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
|
||||
memcpy_unsafe(d, s, n);
|
||||
memcpy_unsafe(d, s, n);
|
||||
#endif // defined(a64)
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
EXTERNC void *memcpy_sse3(void *dest, const void *src, size_t n)
|
||||
{
|
||||
#if defined(a64)
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0x7) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 8;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movq (%0), %%xmm0\n"
|
||||
"movddup %%xmm0, %%xmm1\n"
|
||||
"movq %%xmm1, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0", "xmm1");
|
||||
d += 8;
|
||||
s += 8;
|
||||
}
|
||||
n -= num_vectors * 8;
|
||||
}
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqu (%0), %%xmm0\n"
|
||||
"movdqu %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
|
||||
memcpy_unsafe(d, s, n);
|
||||
memcpy_unsafe(d, s, n);
|
||||
#endif // defined(a64)
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
EXTERNC void *memcpy_ssse3(void *dest, const void *src, size_t n)
|
||||
{
|
||||
#if defined(a64)
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"movdqa 16(%0), %%xmm1\n"
|
||||
"palignr $8, %%xmm0, %%xmm1\n"
|
||||
"movdqa %%xmm1, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0", "xmm1");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("lddqu (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("lddqu (%0), %%xmm0\n"
|
||||
"movdqu %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
|
||||
memcpy_unsafe(d, s, n);
|
||||
memcpy_unsafe(d, s, n);
|
||||
#endif // defined(a64)
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
EXTERNC void *memcpy_sse4_1(void *dest, const void *src, size_t n)
|
||||
{
|
||||
#if defined(a64)
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
// movntdqa
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqu (%0), %%xmm0\n"
|
||||
"movdqu %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
|
||||
memcpy_unsafe(d, s, n);
|
||||
memcpy_unsafe(d, s, n);
|
||||
#endif // defined(a64)
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
EXTERNC void *memcpy_sse4_2(void *dest, const void *src, size_t n)
|
||||
{
|
||||
#if defined(a64)
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"pcmpistri $0, (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
if ((((uintptr_t)d | (uintptr_t)s) & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqa (%0), %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movdqu (%0), %%xmm0\n"
|
||||
"movdqu %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(s), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
s += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
|
||||
memcpy_unsafe(d, s, n);
|
||||
memcpy_unsafe(d, s, n);
|
||||
#endif // defined(a64)
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
@ -24,37 +24,37 @@
|
||||
|
||||
/*
|
||||
TODO: Replace these functions with even more optimized versions.
|
||||
The current versions are fast but not as fast as they could be and also we need implementation for avx, not only sse.
|
||||
The current versions are fast but not as fast as they could be and also we need implementation for avx, not only sse.
|
||||
*/
|
||||
|
||||
// TODO: Implement these functions
|
||||
|
||||
EXTERNC void *memmove_sse(void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove_unsafe(dest, src, n);
|
||||
return memmove_unsafe(dest, src, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memmove_sse2(void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove_unsafe(dest, src, n);
|
||||
return memmove_sse(dest, src, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memmove_sse3(void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove_unsafe(dest, src, n);
|
||||
return memmove_sse(dest, src, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memmove_ssse3(void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove_unsafe(dest, src, n);
|
||||
return memmove_sse(dest, src, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memmove_sse4_1(void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove_unsafe(dest, src, n);
|
||||
return memmove_sse(dest, src, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memmove_sse4_2(void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove_unsafe(dest, src, n);
|
||||
return memmove_sse(dest, src, n);
|
||||
}
|
||||
|
@ -24,58 +24,91 @@
|
||||
|
||||
/*
|
||||
TODO: Replace these functions with even more optimized versions.
|
||||
The current versions are fast but not as fast as they could be and also we need implementation for avx, not only sse.
|
||||
The current versions are fast but not as fast as they could be and also we need implementation for avx, not only sse.
|
||||
*/
|
||||
|
||||
// TODO: Implement these functions
|
||||
|
||||
EXTERNC void *memset_sse(void *dest, int c, size_t n)
|
||||
{
|
||||
return memset_unsafe(dest, c, n);
|
||||
return memset_unsafe(dest, c, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memset_sse2(void *dest, int c, size_t n)
|
||||
{
|
||||
return memset_unsafe(dest, c, n);
|
||||
size_t i;
|
||||
if ((size_t)dest & (16 - 1))
|
||||
{
|
||||
i = 0;
|
||||
while (((size_t)dest + i) & (16 - 1) && i < n)
|
||||
{
|
||||
asmv("stosb\n"
|
||||
:
|
||||
: "D"((size_t)dest + i),
|
||||
"a"(c));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
for (; i + 64 <= n; i += 64)
|
||||
{
|
||||
asmv("movd %0, %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
"movdqa %%xmm0, 16(%1)\n"
|
||||
"movdqa %%xmm0, 32(%1)\n"
|
||||
"movdqa %%xmm0, 48(%1)\n"
|
||||
:
|
||||
: "r"(c), "r"(((size_t)dest) + i)
|
||||
: "xmm0");
|
||||
}
|
||||
|
||||
asmv("rep stosb\n" ::"a"((size_t)(c)),
|
||||
"D"(((size_t)dest) + i),
|
||||
"c"(n - i));
|
||||
|
||||
i += n - i;
|
||||
return (void *)(((size_t)dest) + i);
|
||||
}
|
||||
|
||||
EXTERNC void *memset_sse3(void *dest, int c, size_t n)
|
||||
{
|
||||
return memset_unsafe(dest, c, n);
|
||||
return memset_sse2(dest, c, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memset_ssse3(void *dest, int c, size_t n)
|
||||
{
|
||||
return memset_unsafe(dest, c, n);
|
||||
return memset_sse2(dest, c, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memset_sse4_1(void *dest, int c, size_t n)
|
||||
{
|
||||
return memset_unsafe(dest, c, n);
|
||||
return memset_sse2(dest, c, n);
|
||||
}
|
||||
|
||||
EXTERNC void *memset_sse4_2(void *dest, int c, size_t n)
|
||||
{
|
||||
#if defined(a64)
|
||||
char *d = (char *)dest;
|
||||
char *d = (char *)dest;
|
||||
|
||||
if (((uintptr_t)d & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movd %0, %%xmm0\n"
|
||||
"pshufd $0, %%xmm0, %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(c), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
if (((uintptr_t)d & 0xF) == 0)
|
||||
{
|
||||
size_t num_vectors = n / 16;
|
||||
for (size_t i = 0; i < num_vectors; i++)
|
||||
{
|
||||
asmv("movd %0, %%xmm0\n"
|
||||
"pshufd $0, %%xmm0, %%xmm0\n"
|
||||
"movdqa %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r"(c), "r"(d)
|
||||
: "xmm0");
|
||||
d += 16;
|
||||
}
|
||||
n -= num_vectors * 16;
|
||||
}
|
||||
|
||||
memset_unsafe(d, c, n);
|
||||
memset_unsafe(d, c, n);
|
||||
#endif
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
122
library/simd_strlen.cpp
Normal file
122
library/simd_strlen.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <convert.h>
|
||||
|
||||
#include <memory.hpp>
|
||||
#include <limits.h>
|
||||
#include <debug.h>
|
||||
#include <cpu.hpp>
|
||||
|
||||
/*
|
||||
TODO: Replace these functions with even more optimized versions.
|
||||
The current versions are fast but not as fast as they could be and also we need implementation for avx, not only sse.
|
||||
*/
|
||||
|
||||
long unsigned __strlen(const char s[])
|
||||
{
|
||||
size_t ret = (size_t)s;
|
||||
|
||||
asmv("._strlenLoop:"
|
||||
"cmpb $0, 0(%1)\n"
|
||||
"jz ._strlenExit\n"
|
||||
"cmpb $0, 1(%1)\n"
|
||||
"jz .scmp1\n"
|
||||
"cmpb $0, 2(%1)\n"
|
||||
"jz .scmp2\n"
|
||||
"cmpb $0, 3(%1)\n"
|
||||
"jz .scmp3\n"
|
||||
"cmpb $0, 4(%1)\n"
|
||||
"jz .scmp4\n"
|
||||
"cmpb $0, 5(%1)\n"
|
||||
"jz .scmp5\n"
|
||||
"cmpb $0, 6(%1)\n"
|
||||
"jz .scmp6\n"
|
||||
"cmpb $0, 7(%1)\n"
|
||||
"jz .scmp7\n"
|
||||
|
||||
"add $8, %1\n"
|
||||
"jmp ._strlenLoop\n"
|
||||
|
||||
".scmp1:"
|
||||
"inc %1\n"
|
||||
"jmp ._strlenExit\n"
|
||||
".scmp2:"
|
||||
"add $2, %1\n"
|
||||
"jmp ._strlenExit\n"
|
||||
".scmp3:"
|
||||
"add $3, %1\n"
|
||||
"jmp ._strlenExit\n"
|
||||
".scmp4:"
|
||||
"add $4, %1\n"
|
||||
"jmp ._strlenExit\n"
|
||||
".scmp5:"
|
||||
"add $5, %1\n"
|
||||
"jmp ._strlenExit\n"
|
||||
".scmp6:"
|
||||
"add $6, %1\n"
|
||||
"jmp ._strlenExit\n"
|
||||
".scmp7:"
|
||||
"add $7, %1\n"
|
||||
|
||||
"._strlenExit:"
|
||||
"mov %1, %0\n"
|
||||
: "=r"(ret) : "0"(ret));
|
||||
|
||||
return ret - (size_t)s;
|
||||
}
|
||||
|
||||
long unsigned strlen_sse(const char s[])
|
||||
{
|
||||
return __strlen(s);
|
||||
}
|
||||
|
||||
long unsigned strlen_sse2(const char s[])
|
||||
{
|
||||
return __strlen(s);
|
||||
}
|
||||
|
||||
long unsigned strlen_sse3(const char s[])
|
||||
{
|
||||
return __strlen(s);
|
||||
}
|
||||
|
||||
long unsigned strlen_ssse3(const char s[])
|
||||
{
|
||||
return __strlen(s);
|
||||
}
|
||||
|
||||
long unsigned strlen_sse4_1(const char s[])
|
||||
{
|
||||
return __strlen(s);
|
||||
}
|
||||
|
||||
long unsigned strlen_sse4_2(const char s[])
|
||||
{
|
||||
size_t ret;
|
||||
asmv("mov $-16, %0\n"
|
||||
"pxor %%xmm0, %%xmm0\n"
|
||||
".strlen42Loop:"
|
||||
"add $16, %0\n"
|
||||
"pcmpistri $0x08, (%0,%1), %%xmm0\n"
|
||||
"jnz .strlen42Loop\n"
|
||||
"add %2, %0\n"
|
||||
: "=a"(ret)
|
||||
: "d"((size_t)s), "c"((size_t)s));
|
||||
|
||||
return ret;
|
||||
}
|
@ -25,9 +25,281 @@
|
||||
|
||||
__aligned(16) static int errno_value = 0;
|
||||
|
||||
int *__errno_location(void)
|
||||
EXTERNC int *__errno_location(void)
|
||||
{
|
||||
if (unlikely(!TaskManager || !thisThread))
|
||||
return &errno_value;
|
||||
return &thisThread->ErrorNumber;
|
||||
}
|
||||
|
||||
const char *strerror(int errnum)
|
||||
{
|
||||
if (errnum < 0)
|
||||
errnum = -errnum;
|
||||
|
||||
switch (errnum)
|
||||
{
|
||||
case 0:
|
||||
return "Success";
|
||||
case EPERM:
|
||||
return "Operation not permitted";
|
||||
case ENOENT:
|
||||
return "No such file or directory";
|
||||
case ESRCH:
|
||||
return "No such process";
|
||||
case EINTR:
|
||||
return "Interrupted system call";
|
||||
case EIO:
|
||||
return "Input/output error";
|
||||
case ENXIO:
|
||||
return "No such device or address";
|
||||
case E2BIG:
|
||||
return "Argument list too long";
|
||||
case ENOEXEC:
|
||||
return "Exec format error";
|
||||
case EBADF:
|
||||
return "Bad file descriptor";
|
||||
case ECHILD:
|
||||
return "No child processes";
|
||||
case EAGAIN:
|
||||
return "Resource temporarily unavailable";
|
||||
case ENOMEM:
|
||||
return "Cannot allocate memory";
|
||||
case EACCES:
|
||||
return "Permission denied";
|
||||
case EFAULT:
|
||||
return "Bad address";
|
||||
case ENOTBLK:
|
||||
return "Block device required";
|
||||
case EBUSY:
|
||||
return "Device or resource busy";
|
||||
case EEXIST:
|
||||
return "File exists";
|
||||
case EXDEV:
|
||||
return "Invalid cross-device link";
|
||||
case ENODEV:
|
||||
return "No such device";
|
||||
case ENOTDIR:
|
||||
return "Not a directory";
|
||||
case EISDIR:
|
||||
return "Is a directory";
|
||||
case EINVAL:
|
||||
return "Invalid argument";
|
||||
case ENFILE:
|
||||
return "Too many open files in system";
|
||||
case EMFILE:
|
||||
return "Too many open files";
|
||||
case ENOTTY:
|
||||
return "Inappropriate ioctl for device";
|
||||
case ETXTBSY:
|
||||
return "Text file busy";
|
||||
case EFBIG:
|
||||
return "File too large";
|
||||
case ENOSPC:
|
||||
return "No space left on device";
|
||||
case ESPIPE:
|
||||
return "Illegal seek";
|
||||
case EROFS:
|
||||
return "Read-only file system";
|
||||
case EMLINK:
|
||||
return "Too many links";
|
||||
case EPIPE:
|
||||
return "Broken pipe";
|
||||
case EDOM:
|
||||
return "Numerical argument out of domain";
|
||||
case ERANGE:
|
||||
return "Numerical result out of range";
|
||||
case EDEADLK:
|
||||
return "Resource deadlock avoided";
|
||||
case ENAMETOOLONG:
|
||||
return "File name too long";
|
||||
case ENOLCK:
|
||||
return "No locks available";
|
||||
case ENOSYS:
|
||||
return "Function not implemented";
|
||||
case ENOTEMPTY:
|
||||
return "Directory not empty";
|
||||
case ELOOP:
|
||||
return "Too many levels of symbolic links";
|
||||
case ENOMSG:
|
||||
return "No message of desired type";
|
||||
case EIDRM:
|
||||
return "Identifier removed";
|
||||
case ECHRNG:
|
||||
return "Channel number out of range";
|
||||
case EL2NSYNC:
|
||||
return "Level 2 not synchronized";
|
||||
case EL3HLT:
|
||||
return "Level 3 halted";
|
||||
case EL3RST:
|
||||
return "Level 3 reset";
|
||||
case ELNRNG:
|
||||
return "Link number out of range";
|
||||
case EUNATCH:
|
||||
return "Protocol driver not attached";
|
||||
case ENOCSI:
|
||||
return "No CSI structure available";
|
||||
case EL2HLT:
|
||||
return "Level 2 halted";
|
||||
case EBADE:
|
||||
return "Invalid exchange";
|
||||
case EBADR:
|
||||
return "Invalid request descriptor";
|
||||
case EXFULL:
|
||||
return "Exchange full";
|
||||
case ENOANO:
|
||||
return "No anode";
|
||||
case EBADRQC:
|
||||
return "Invalid request code";
|
||||
case EBADSLT:
|
||||
return "Invalid slot";
|
||||
case EBFONT:
|
||||
return "Bad font file format";
|
||||
case ENOSTR:
|
||||
return "Device not a stream";
|
||||
case ENODATA:
|
||||
return "No data available";
|
||||
case ETIME:
|
||||
return "Timer expired";
|
||||
case ENOSR:
|
||||
return "Out of streams resources";
|
||||
case ENONET:
|
||||
return "Machine is not on the network";
|
||||
case ENOPKG:
|
||||
return "Package not installed";
|
||||
case EREMOTE:
|
||||
return "Object is remote";
|
||||
case ENOLINK:
|
||||
return "Link has been severed";
|
||||
case EADV:
|
||||
return "Advertise error";
|
||||
case ESRMNT:
|
||||
return "Srmount error";
|
||||
case ECOMM:
|
||||
return "Communication error on send";
|
||||
case EPROTO:
|
||||
return "Protocol error";
|
||||
case EMULTIHOP:
|
||||
return "Multihop attempted";
|
||||
case EDOTDOT:
|
||||
return "RFS specific error";
|
||||
case EBADMSG:
|
||||
return "Bad message";
|
||||
case EOVERFLOW:
|
||||
return "Value too large for defined data type";
|
||||
case ENOTUNIQ:
|
||||
return "Name not unique on network";
|
||||
case EBADFD:
|
||||
return "File descriptor in bad state";
|
||||
case EREMCHG:
|
||||
return "Remote address changed";
|
||||
case ELIBACC:
|
||||
return "Can not access a needed shared library";
|
||||
case ELIBBAD:
|
||||
return "Accessing a corrupted shared library";
|
||||
case ELIBSCN:
|
||||
return ".lib section in a.out corrupted";
|
||||
case ELIBMAX:
|
||||
return "Attempting to link in too many shared libraries";
|
||||
case ELIBEXEC:
|
||||
return "Cannot exec a shared library directly";
|
||||
case EILSEQ:
|
||||
return "Illegal byte sequence";
|
||||
case ERESTART:
|
||||
return "Interrupted system call should be restarted";
|
||||
case ESTRPIPE:
|
||||
return "Streams pipe error";
|
||||
case EUSERS:
|
||||
return "Too many users";
|
||||
case ENOTSOCK:
|
||||
return "Socket operation on non-socket";
|
||||
case EDESTADDRREQ:
|
||||
return "Destination address required";
|
||||
case EMSGSIZE:
|
||||
return "Message too long";
|
||||
case EPROTOTYPE:
|
||||
return "Protocol wrong type for socket";
|
||||
case ENOPROTOOPT:
|
||||
return "Protocol not available";
|
||||
case EPROTONOSUPPORT:
|
||||
return "Protocol not supported";
|
||||
case ESOCKTNOSUPPORT:
|
||||
return "Socket type not supported";
|
||||
case EOPNOTSUPP:
|
||||
return "Operation not supported";
|
||||
case EPFNOSUPPORT:
|
||||
return "Protocol family not supported";
|
||||
case EAFNOSUPPORT:
|
||||
return "Address family not supported by protocol";
|
||||
case EADDRINUSE:
|
||||
return "Address already in use";
|
||||
case EADDRNOTAVAIL:
|
||||
return "Cannot assign requested address";
|
||||
case ENETDOWN:
|
||||
return "Network is down";
|
||||
case ENETUNREACH:
|
||||
return "Network is unreachable";
|
||||
case ENETRESET:
|
||||
return "Network dropped connection on reset";
|
||||
case ECONNABORTED:
|
||||
return "Software caused connection abort";
|
||||
case ECONNRESET:
|
||||
return "Connection reset by peer";
|
||||
case ENOBUFS:
|
||||
return "No buffer space available";
|
||||
case EISCONN:
|
||||
return "Transport endpoint is already connected";
|
||||
case ENOTCONN:
|
||||
return "Transport endpoint is not connected";
|
||||
case ESHUTDOWN:
|
||||
return "Cannot send after transport endpoint shutdown";
|
||||
case ETOOMANYREFS:
|
||||
return "Too many references: cannot splice";
|
||||
case ETIMEDOUT:
|
||||
return "Connection timed out";
|
||||
case ECONNREFUSED:
|
||||
return "Connection refused";
|
||||
case EHOSTDOWN:
|
||||
return "Host is down";
|
||||
case EHOSTUNREACH:
|
||||
return "No route to host";
|
||||
case EALREADY:
|
||||
return "Operation already in progress";
|
||||
case EINPROGRESS:
|
||||
return "Operation now in progress";
|
||||
case ESTALE:
|
||||
return "Stale file handle";
|
||||
case EUCLEAN:
|
||||
return "Structure needs cleaning";
|
||||
case ENOTNAM:
|
||||
return "Not a XENIX named type file";
|
||||
case ENAVAIL:
|
||||
return "No XENIX semaphores available";
|
||||
case EISNAM:
|
||||
return "Is a named type file";
|
||||
case EREMOTEIO:
|
||||
return "Remote I/O error";
|
||||
case EDQUOT:
|
||||
return "Quota exceeded";
|
||||
case ENOMEDIUM:
|
||||
return "No medium found";
|
||||
case EMEDIUMTYPE:
|
||||
return "Wrong medium type";
|
||||
case ECANCELED:
|
||||
return "Operation Canceled";
|
||||
case ENOKEY:
|
||||
return "Required key not available";
|
||||
case EKEYEXPIRED:
|
||||
return "Key has expired";
|
||||
case EKEYREVOKED:
|
||||
return "Key has been revoked";
|
||||
case EKEYREJECTED:
|
||||
return "Key was rejected by service";
|
||||
case EOWNERDEAD:
|
||||
return "Owner died";
|
||||
case ENOTRECOVERABLE:
|
||||
return "State not recoverable";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
@ -22,26 +22,26 @@
|
||||
|
||||
void targp_parse(const char *cmd, char **argv, int *argc)
|
||||
{
|
||||
const char delim[] = " ";
|
||||
const char delim[] = " ";
|
||||
|
||||
char *token = strtok((char *)cmd, delim);
|
||||
while (token != NULL)
|
||||
{
|
||||
char *quote = strchr(token, '"');
|
||||
if (quote != NULL)
|
||||
{
|
||||
memmove(quote, quote + 1, strlen(quote));
|
||||
char *endQuote = strchr(quote, '"');
|
||||
if (endQuote != NULL)
|
||||
*endQuote = '\0';
|
||||
}
|
||||
char *token = strtok((char *)cmd, delim);
|
||||
while (token != NULL)
|
||||
{
|
||||
char *quote = strchr(token, '"');
|
||||
if (quote != NULL)
|
||||
{
|
||||
memmove(quote, quote + 1, strlen(quote));
|
||||
char *endQuote = strchr(quote, '"');
|
||||
if (endQuote != NULL)
|
||||
*endQuote = '\0';
|
||||
}
|
||||
|
||||
char *arg = (char *)kmalloc(strlen(token) + 1);
|
||||
strcpy(arg, token);
|
||||
char *arg = (char *)kmalloc(strlen(token) + 1);
|
||||
strcpy(arg, token);
|
||||
|
||||
argv[(*argc)++] = arg;
|
||||
argv[(*argc)++] = arg;
|
||||
|
||||
token = strtok(NULL, delim);
|
||||
}
|
||||
argv[(*argc)] = NULL;
|
||||
token = strtok(NULL, delim);
|
||||
}
|
||||
argv[(*argc)] = NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user