feature (kernel): Optimized memory functions to use 64-bit operations where possible

This commit is contained in:
antifallobst 2023-02-19 22:19:49 +01:00
parent 0127a19d0f
commit 81e4f2abb2
1 changed files with 39 additions and 8 deletions

View File

@ -19,27 +19,58 @@
heap_T g_kernel_heap; heap_T g_kernel_heap;
void memory_copy(void* source, void* destination, uint32_t num) { void memory_copy(void* source, void* destination, uint32_t num) {
uint32_t num_64 = num / 8;
uint64_t* src_64 = (uint64_t*)source;
uint64_t* dst_64 = (uint64_t*)destination;
for (uint32_t i = 0; i < num_64; i++) {
dst_64[i] = src_64[i];
}
uint32_t num_8 = num % 8;
uint8_t* src_8 = (uint8_t*)source; uint8_t* src_8 = (uint8_t*)source;
uint8_t* dst_8 = (uint8_t*)destination; uint8_t* dst_8 = (uint8_t*)destination;
for (int i = 0; i < num; i++) { for (uint32_t i = num_64 * 8; i < num_8; i++) {
dst_8[i] = src_8[i]; dst_8[i] = src_8[i];
} }
} }
void memory_set(void* destination, uint8_t data, uint32_t num) { void memory_set(void* destination, uint8_t data, uint32_t num) {
uint32_t num_64 = num / 8;
uint64_t* dst_64 = (uint64_t*)destination;
uint64_t data_64 = data;
data_64 |= (data_64 << 8) | (data_64 << 16) | (data_64 << 24) | (data_64 << 32) | (data_64 << 40) | (data_64 << 48) | (data_64 << 56);
for (uint32_t i = 0; i < num_64; i++) {
dst_64[i] = data_64;
}
uint32_t num_8 = num % 8;
uint8_t* dst_8 = (uint8_t*)destination; uint8_t* dst_8 = (uint8_t*)destination;
for (int i = 0; i < num; i++) { for (uint32_t i = num_64 * 8; i < num_8; i++) {
dst_8[i] = data; dst_8[i] = data;
} }
} }
bool memory_compare(void* a, void* b, uint32_t num) { bool memory_compare(void* a, void* b, uint32_t num) {
uint32_t num_64 = num / 8;
uint64_t* a_64 = (uint64_t*)a;
uint64_t* b_64 = (uint64_t*)b;
for (uint32_t i = num_64; i < num_64; i++) {
if (a_64[i] != b_64[i]) {
return false;
}
}
uint32_t num_8 = num % 8;
uint8_t* a_8 = (uint8_t*)a; uint8_t* a_8 = (uint8_t*)a;
uint8_t* b_8 = (uint8_t*)b; uint8_t* b_8 = (uint8_t*)b;
for (int i = 0; i < num; i++) { for (uint32_t i = num_64 * 8; i < num_8; i++) {
if (a_8[i] != b_8[i]) { if (a_8[i] != b_8[i]) {
return false; return false;
} }