implement cu_memtest in x86-64 assembly in more efficient way that C does
This commit is contained in:
parent
0b610097b4
commit
f2a1dddbca
3 changed files with 32 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
.globl hw_bswap16
|
.globl hw_bswap16
|
||||||
.globl hw_bswap32
|
.globl hw_bswap32
|
||||||
.globl hw_bswap64
|
.globl hw_bswap64
|
||||||
|
.globl cu_memtest
|
||||||
|
|
||||||
.text
|
.text
|
||||||
|
|
||||||
|
|
@ -19,3 +20,31 @@ hw_bswap64:
|
||||||
bswap %rax
|
bswap %rax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
cu_memtest:
|
||||||
|
// RDI - ptr, RSI - size
|
||||||
|
xchg %rsi, %rdi
|
||||||
|
|
||||||
|
mov %rdi, %rcx
|
||||||
|
shr $3, %rcx
|
||||||
|
je .testok
|
||||||
|
.testq:
|
||||||
|
lodsq
|
||||||
|
test %rax, %rax
|
||||||
|
jnz .testfail
|
||||||
|
loop .testq
|
||||||
|
|
||||||
|
mov %rdi, %rcx
|
||||||
|
and $7, %rcx
|
||||||
|
je .testok
|
||||||
|
.testb:
|
||||||
|
lodsb
|
||||||
|
test %al, %al
|
||||||
|
jnz .testfail
|
||||||
|
loop .testb
|
||||||
|
|
||||||
|
.testok:
|
||||||
|
xor %rax, %rax
|
||||||
|
ret
|
||||||
|
.testfail:
|
||||||
|
mov %rsi, %rax
|
||||||
|
ret
|
||||||
4
cutil.c
4
cutil.c
|
|
@ -25,7 +25,7 @@ void cutil_exit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* cu_memtest(const void* mem, uint size)
|
/*const void* cu_memtest(const void* mem, uint size)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
for (i = 0; i < size / sizeof(uword); i++)
|
for (i = 0; i < size / sizeof(uword); i++)
|
||||||
|
|
@ -41,4 +41,4 @@ const void* cu_memtest(const void* mem, uint size)
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}*/
|
||||||
|
|
|
||||||
2
cutil.h
2
cutil.h
|
|
@ -21,6 +21,6 @@ extern void* (*cu_memmove)(void*,const void*,size_t);
|
||||||
void cutil_init();
|
void cutil_init();
|
||||||
void cutil_exit();
|
void cutil_exit();
|
||||||
|
|
||||||
const void* cu_memtest(const void* mem, uint size);
|
extern const void* cu_memtest(const void* mem, uint size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Add table
Reference in a new issue