use optimized memcpy functions for non-cacheable memory

This commit is contained in:
Stefan Lankes 2011-10-05 22:42:09 -07:00
parent bc451eac54
commit 06ddffe09a

View file

@ -266,6 +266,76 @@ typedef struct mmnif {
sem_t com_poll;
} mmnif_t;
inline static void* memcpy_from_nc(void *dest, const void *src, size_t count)
{
#if 0
size_t i;
for(i=0; i<count; i++)
((uint8_t*) dest)[i] = ((uint8_t*) src)[i];
return dest;
#else
int32_t h, i, j, k, l, m;
asm volatile ("cld;\n\t"
"1: cmpl $0, %%eax ; je 3f\n\t"
"movl (%%edi), %%edx\n\t"
"cmpl $1, %%eax ; je 2f\n\t"
"movl 32(%%edi), %%edx\n\t"
"2: movl 0(%%esi), %%ecx\n\t"
"movl 4(%%esi), %%edx\n\t"
"movl %%ecx, 0(%%edi)\n\t"
"movl %%edx, 4(%%edi)\n\t"
"movl 8(%%esi), %%ecx\n\t"
"movl 12(%%esi), %%edx\n\t"
"movl %%ecx, 8(%%edi)\n\t"
"movl %%edx, 12(%%edi)\n\t"
"movl 16(%%esi), %%ecx\n\t"
"movl 20(%%esi), %%edx\n\t"
"movl %%ecx, 16(%%edi)\n\t"
"movl %%edx, 20(%%edi)\n\t"
"movl 24(%%esi), %%ecx\n\t"
"movl 28(%%esi), %%edx\n\t"
"movl %%ecx, 24(%%edi)\n\t"
"movl %%edx, 28(%%edi)\n\t"
"addl $32, %%esi\n\t"
"addl $32, %%edi\n\t"
"dec %%eax ; jmp 1b\n\t"
"3: movl %%ebx, %%ecx\n\t"
"movl (%%edi), %%edx\n\t"
"andl $31, %%ecx\n\t"
"rep ; movsb\n\t" : "=&a"(h), "=&D"(i), "=&S"(j), "=&b"(k), "=&c"(l), "=&d"(m)
: "0"(count / 32), "1"(dest), "2"(src), "3"(count) : "memory","cc");
return dest;
#endif
}
inline static void* memcpy_to_nc(void* dest, const void *src, size_t count)
{
#if 0
size_t i;
for(i=0; i<count; i++)
((uint8_t*) dest)[i] = ((uint8_t*) src)[i];
return dest;
#else
int32_t i, j, k;
asm volatile (
"cld; rep movsl\n\t"
"movl %4, %%ecx\n\t"
"andl $3, %%ecx\n\t"
"rep movsb\n\t"
: "=&c"(i), "=&D"(j), "=&S"(k)
: "0"(count/4), "g"(count), "1"(dest), "2"(src) : "memory","cc");
return dest;
#endif
}
/*
* memory maped interface helper functions
*/
@ -630,7 +700,9 @@ realloc:
for (q = p, i = 0; q != 0; q = q->next)
{
#if MMNIF_USE_MPB
#if !MMNIF_USE_MBO && !USE_CACHE
memcpy_to_nc((char*) write_address+ i, q->payload, q->len);
#elif MMNIF_USE_MPB
memcpy_put((char*) write_address + i, q->payload, q->len);
#else
memcpy((char*) write_address+ i, q->payload, q->len);
@ -794,7 +866,9 @@ realloc:
asm volatile (".byte 0x0f; .byte 0x0a;\n");
#endif
#if MMNIF_USE_MPB
#if !MMNIF_USE_MBO && !USE_CACHE
memcpy_to_nc((void*) write_address, pbuff, CLINE_ALIGN(size));
#elif MMNIF_USE_MPB
memcpy_put(write_address, pbuff, CLINE_ALIGN(size));
#else
memcpy((void*) write_address, pbuff, CLINE_ALIGN(size));
@ -1174,7 +1248,9 @@ anotherpacket:
/* copy packet to pbuf structure going through linked list */
for (q = p, i = 0; q != NULL; q = q->next)
{
#if MMNIF_USE_MPB
#if !USE_CACHE || !MMNIF_USE_MBP
memcpy_from_nc((uint8_t *) q->payload, &packet[i], q->len);
#elif MMNIF_USE_MPB
memcpy_get((uint8_t *) q->payload, &packet[i], q->len);
#else
memcpy((uint8_t *) q->payload, &packet[i], q->len);