3.12 C99 restrict.
$LN6@memcmp_123:
sbb eax, eax
or eax, 1
pop esi
ret 0
_memcmp_1235 ENDP
strcat()
This is inlined strcat() as it has been generated by MSVC 6.0. There are 3 parts visible: 1) getting source
string length (firstscasb); 2) getting destination string length (secondscasb); 3) copying source string
into the end of destination string (movsd/movsbpair).
Listing 3.52: strcat()
lea edi, [src]
or ecx, 0FFFFFFFFh
repne scasb
not ecx
sub edi, ecx
mov esi, edi
mov edi, [dst]
mov edx, ecx
or ecx, 0FFFFFFFFh
repne scasb
mov ecx, edx
dec edi
shr ecx, 2
rep movsd
mov ecx, edx
and ecx, 3
rep movsb
IDA script
There is also a smallIDAscript for searching and folding such very frequently seen pieces of inline code:
GitHub.
3.12 C99 restrict
Here is a reason why Fortran programs, in some cases, work faster than C/C++ ones.
void f1 (int x, int y, int sum, int product, int sum_product, int update_me, size_t s)
{
for (int i=0; i<s; i++)
{
sum[i]=x[i]+y[i];
product[i]=x[i]y[i];
update_me[i]=i123; // some dummy value
sum_product[i]=sum[i]+product[i];
};
};
That’s very simple example with one specific thing in it: the pointer to theupdate_mearray could be a
pointer to thesumarray,productarray, or even thesum_productarray—nothing forbids that, right?
The compiler is fully aware of this, so it generates code with four stages in the loop body:
- calculate nextsum[i]
- calculate nextproduct[i]
- calculate nextupdate_me[i]