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:
Felix Kopp 2020-11-19 16:33:40 +01:00
parent ed60b267a0
commit 056c318e86
No known key found for this signature in database
GPG key ID: C478BA0A85F75728

View file

@ -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;