dmd: if still there

Chris via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 19 07:58:23 PDT 2014


Out of curiosity. dmd still produces the if statement, although 
it ain't gonna happen. Same is true of "DoIt.yes". I know, it's 
an unlikely and marginal example.

[code]
import std.stdio;

enum DoIt {
   yes,
   no
}

void main() {
   doit(DoIt.no);
}

void doit(DoIt flag) {
   if (flag == DoIt.yes) {
     writeln("I'm doing it!");
   }
   else {
     writeln("No, I won't");
   }
}

[asm]

_Dmain:
		push	RBP
		mov	RBP,RSP
		mov	EDI,1
		call	  _D7dump_if4doitFE7dump_if4DoItZv at PC32
		xor	EAX,EAX
		pop	RBP
		ret
		0f1f
		add	[RAX],R8B
.text._Dmain	ends
.text._D7dump_if4doitFE7dump_if4DoItZv	segment
	assume	CS:.text._D7dump_if4doitFE7dump_if4DoItZv
_D7dump_if4doitFE7dump_if4DoItZv:
		push	RBP
		mov	RBP,RSP
		sub	RSP,010h
		mov	-8[RBP],EDI
		cmp	dword ptr -8[RBP],0
		jne	L29
		mov	RDX,FLAT:.rodata[00h][RIP]
		mov	RDI,FLAT:.rodata[00h][RIP]
		mov	RSI,RDX
		call	  _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv at PC32
		jmp short	L3F
L29:		mov	RDX,FLAT:.rodata[00h][RIP]
		mov	RDI,FLAT:.rodata[00h][RIP]
		mov	RSI,RDX
		call	  _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv at PC32
L3F:		leave
		ret
		0f1f
		add	byte ptr [RAX],0
		add	[RAX],AL
.text._D7dump_if4doitFE7dump_if4DoItZv	ends

[asm dmd (2.066) -release -boundscheck=off -O -inline]

_Dmain:
		push	RBP
		mov	RBP,RSP
		mov	RDX,FLAT:.rodata[00h][RIP]
		mov	RDI,FLAT:.rodata[00h][RIP]
		mov	RSI,RDX
		call	  _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv at PC32
		xor	EAX,EAX
		pop	RBP
		ret
		nop
.text._Dmain	ends
.text._D7dump_if4doitFE7dump_if4DoItZv	segment
	assume	CS:.text._D7dump_if4doitFE7dump_if4DoItZv
_D7dump_if4doitFE7dump_if4DoItZv:
		push	RBP
		mov	RBP,RSP
		sub	RSP,010h
		mov	-8[RBP],EDI
		cmp	dword ptr -8[RBP],0
		jne	L29
		mov	RDX,FLAT:.rodata[00h][RIP]
		mov	RDI,FLAT:.rodata[00h][RIP]
		mov	RSI,RDX
		call	  _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv at PC32
		jmp short	L3F
L29:		mov	RDX,FLAT:.rodata[00h][RIP]
		mov	RDI,FLAT:.rodata[00h][RIP]
		mov	RSI,RDX
		call	  _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv at PC32
L3F:		mov	RSP,RBP
		pop	RBP
		ret
		0f1f
		add	0[RCX],SPL
.text._D7dump_if4doitFE7dump_if4DoItZv	ends


More information about the Digitalmars-d mailing list