[PATCH] V13 of experiment for a simpler path encoding for hashed paths (for "fncache2")

Adrian Buehlmann adrian at cadifra.com
Sat Sep 29 15:44:49 CDT 2012



On 2012-09-29 19:15, Isaac Jurado wrote:
> On Sat, Sep 29, 2012 at 7:00 PM, Adrian Buehlmann <adrian at cadifra.com> wrote:
>>> I pasted the (hopefully) relevant part here:
>>> http://pastebin.com/Pjr4N9h3
>>
>> I'm surprised to see that memcpy is *called*, not inlined. memcpy should
>> be an intrinsic and the command line options for the compiler (cl.exe)
>> are set correctly (/Ox which implies /Oi [1]).
>>
>> The compiler is the one from the SDK
>> http://www.microsoft.com/en-us/download/details.aspx?id=3138
>>
>> I was under the impression that it's the optimzing one. At least it
>> inlines functions, e.g. our own memcopy function appears to get inlined
>> as expected, but not the call to memcpy inside it.
> 
> The calls to memcpy are only inlined when both the src and length are
> constant at compile time; which is not the case in that code.  At
> least, that's how it works with GCC.  I believe there cannot be much
> more magic about that, so probably other compilers behave the same.

Interesting.

As a try I've replaced the memcopy call with

				//memcopy(dest, &destlen, destsize, &seg, seglen);
				if (dest) {
					for (t = 0; t < seglen; ++t)
						dest[destlen] = seg[t];
				}
				destlen += seglen;

which is translated by MS C as

<paste>
$LN9 at cutdirs:

; 530  : 				}
; 531  : 				/* memcopy(dest, &destlen, destsize, &seg, seglen); */
; 532  : 				if (dest) {

	test	r12, r12
	je	SHORT $LN6 at cutdirs

; 533  : 					for (t = 0; t < seglen; ++t)

	test	r8, r8
	jle	SHORT $LN6 at cutdirs
	lea	rcx, QWORD PTR [r12+rdi]
	lea	rdx, QWORD PTR seg$[rsp]
	call	memcpy
	lea	rdx, OFFSET FLAT:encchar
$LN6 at cutdirs:
	mov	rcx, QWORD PTR len$[rsp]

; 534  : 						dest[destlen + t] = seg[t];
; 535  : 				}
; 536  : 				destlen += seglen;

	movsxd	rax, esi

; 537  : 
; 538  : 				seglen = 0;

	xor	esi, esi
	add	rdi, rax
	xor	r8d, r8d
$LN15 at cutdirs:

; 539  : 			}
</paste>

So the compiler even creates a memcpy call if I write a for loop that copies
memory around.


More information about the Mercurial-devel mailing list