Make memcmp more compiler friendly
The Thumb ISA allows incrementing a pointer right after dereferencing it. This commit attempts to make it more obvious to the compiler to use this instruction in memcmp().
This commit is contained in:
parent
ed60b267a0
commit
056c318e86
1 changed files with 1 additions and 10 deletions
11
lib/string.c
11
lib/string.c
|
@ -10,18 +10,9 @@ int memcmp(const void *s1, const void *s2, size_t n)
|
|||
int delta = 0;
|
||||
|
||||
while (n-- > 0) {
|
||||
/*
|
||||
* TODO
|
||||
* See if avr-gcc is smart enough to combine the pointer
|
||||
* dereferencing and increment into a single `ld Rd,X+`
|
||||
* instruction even if there is an if statement in between
|
||||
*/
|
||||
delta = *(const unsigned char *)s1 - *(const unsigned char *)s2;
|
||||
delta = *(const unsigned char *)s1++ - *(const unsigned char *)s2++;
|
||||
if (delta != 0)
|
||||
break;
|
||||
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return delta;
|
||||
|
|
Loading…
Reference in a new issue