Where can I find how string == is performed in dmd2 source?

Steven Schveighoffer schveiguy at yahoo.com
Mon Dec 6 07:46:43 PST 2010


On Mon, 06 Dec 2010 09:44:10 -0500, spir <denis.spir at gmail.com> wrote:

> Hello,
>
>
> Nearly all is in title.
> I found dmd2/src/phobos/std/string.cmp in string.d. But this performs  
> string comp with positive/negative/zero result, not equality test with  
> boolean result.

It's in druntime.

Easy way to find out what druntime function is used by the compiler

void main()
{
    auto str1 = "hello";
    auto str2 = "world";
    auto iseq = (str1 == str2);
}

compile using -c, then use obj2asm, result of main function:

.text._Dmain	segment
	assume	CS:.text._Dmain
_Dmain:
		push	EBP
		mov	EBP,ESP
		push	EBX
		push	ESI
		mov	EDX,_TMP0 at SYM32[0Bh]
		mov	EAX,_TMP0 at SYM32[0Ch]
		mov	ECX,_TMP1 at SYM32[016h]
		mov	EBX,_TMP1 at SYM32[018h]
		mov	ESI,offset FLAT:_D11TypeInfo_Aa6__initZ at SYM32
		push	ESI
		push	ECX
		push	EBX
		push	EDX
		push	EAX
********	call	  _adEq2 at PC32
		xor	EAX,EAX
		add	ESP,014h
		pop	ESI
		pop	EBX
		pop	EBP
		ret
.text._Dmain	ends


So it looks like adEq2 is the function called (I marked with ********  
above).  Searching druntime, it looks like it's here:

http://www.dsource.org/projects/druntime/browser/trunk/src/rt/adi.d#L353

This is an essential exercise for D runtime hacking ;)

-Steve


More information about the Digitalmars-d-learn mailing list