www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11289] New: Better compilation of code using std.typecons.NullableRef

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11289

           Summary: Better compilation of code using
                    std.typecons.NullableRef
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is a DMD bug report/enhancement request. It's not a Phobos enhancement
request.

In attach there is a small benchmark program in two versions, the first
versions uses pointers to fixed-size arrays and has to use this bad looking
syntax to access array items:

(*number)[Nation.Norvegian]

The second wraps the arrays in NullableRef, that allow a more natural syntax:

number[Nation.Norvegian]

A NullableRef is essentially a smart pointer (NullableRef.sizeof ==
(void*).sizeof), but in this code leads to a program about 15% slower (compiled
with dmd 2.064beta1, dmd -O -release -inline -noboundscheck test2.d).

To encourage the usage of such safer smart pointers, the compiler should be
able to remove this little abstraction penality. So I think this is a problem
to be solved at compiler level, because I think the Phobos code of NullableRef
is fine.

-----------------------------------

test1:

isPossible:
        push    EAX
        push    EBX
        push    EBP
        mov    EBP,010h[ESP]
        push    ESI
        mov    ESI,EAX
        push    EDI
        mov    EDI,024h[ESP]
        test    EDI,EDI
        je    L1D
        cmp    dword ptr 0Ch[EDI],0
        jne    L179
L1D:        cmp    dword ptr 020h[ESP],0
        je    L31
        mov    ECX,020h[ESP]
        cmp    dword ptr [ECX],0
        jne    L179
L31:        cmp    dword ptr 01Ch[ESP],0
        je    L46
        mov    EDX,01Ch[ESP]
        cmp    dword ptr 8[EDX],4
        jne    L179
L46:        test    EBP,EBP
        je    L54
        cmp    dword ptr 010h[EBP],4
        jne    L179
L54:        test    ESI,ESI
        je    L62
        cmp    dword ptr 4[ESI],0
        jne    L179
L62:        test    EDI,EDI
        je    L19B
        cmp    dword ptr 020h[ESP],0
        je    L19B
        cmp    dword ptr 01Ch[ESP],0
        je    L19B
        test    EBP,EBP
        je    L19B
        test    ESI,ESI
        je    L19B
        mov    018h[ESP],EBP
        xor    EBP,EBP
L96:        mov    ECX,020h[ESP]
        mov    EDX,[EBP*4][ECX]
        mov    ECX,1
        cmp    EDX,ECX
        jne    LB3
        mov    EAX,01Ch[ESP]
        cmp    [EBP*4][EAX],ECX
        jne    L179
LB3:        mov    EBX,018h[ESP]
        mov    EAX,[EBP*4][EBX]
        test    EAX,EAX
        jne    LC8
        cmp    [EBP*4][ESI],4
        jne    L179
LC8:        cmp    EDX,4
        jne    LD5
        cmp    EAX,ECX
        jne    L179
LD5:        mov    EBX,[EBP*4][EDI]
        cmp    EBX,2
        jne    LEB
        mov    ECX,01Ch[ESP]
        cmp    [EBP*4][ECX],0
        jne    L179
LEB:        mov    ECX,3
        cmp    EAX,ECX
        jne    LFD
        mov    EAX,01Ch[ESP]
        cmp    [EBP*4][EAX],ECX
        jne    L179
LFD:        cmp    EDX,2
        jne    L107
        cmp    EBX,1
        jne    L179
L107:        mov    EDX,020h[ESP]
        xor    EBX,EBX
        lea    EAX,[EBP*4][EDX]
L110:        cmp    dword ptr [EAX],1
        jne    L12A
        mov    ECX,020h[ESP]
        cmp    [EBX*4][ECX],3
        jne    L12A
        mov    EDX,[EBX*4][EDI]
        sub    EDX,[EBP*4][EDI]
        cmp    EDX,1
        jne    L179
L12A:        mov    010h[ESP],EAX
        mov    EAX,[EBP*4][EDI]
        mov    EDX,018h[ESP]
        sub    EAX,[EBX*4][EDI]
        mov    ECX,EAX
        sar    ECX,01Fh
        xor    EAX,ECX
        sub    EAX,ECX
        mov    ECX,[EBP*4][EDX]
        cmp    ECX,2
        jne    L154
        cmp    [EBX*4][ESI],1
        jne    L154
        cmp    EAX,1
        jne    L179
L154:        cmp    [EBP*4][ESI],3
        jne    L165
        cmp    [EBX*4][EDX],1
        jne    L165
        cmp    EAX,1
        jne    L179
L165:        cmp    ECX,2
        jne    L183
        mov    EDX,01Ch[ESP]
        cmp    [EBX*4][EDX],2
        jne    L183
        cmp    EAX,1
        je    L183
L179:        pop    EDI
        xor    EAX,EAX
        pop    ESI
        pop    EBP
        pop    EBX
        pop    ECX
        ret    010h
L183:        inc    EBX
        mov    EAX,010h[ESP]
        cmp    EBX,5
        jb    L110
        inc    EBP
        cmp    EBP,5
        jb    L96
L19B:        pop    EDI
        mov    EAX,1
        pop    ESI
        pop    EBP
        pop    EBX
        pop    ECX
        ret    010h


Dmain:
L0:        sub    ESP,054h
        mov    EAX,offset FLAT:_D25TypeInfo_yAE5test16Nation6__initZ
        push    EBX
        push    EBP
        push    ESI
        push    EDI
        push    5
        push    EAX
        call    near ptr __d_arrayliteralTX
        mov    EBX,EAX
        mov    ESI,5
        mov    dword ptr [EAX],0
        mov    ECX,EBX
        mov    dword ptr 4[EBX],1
        mov    dword ptr 8[EBX],2
        mov    dword ptr 0Ch[EBX],3
        mov    dword ptr 010h[EBX],4
        mov    EAX,_D5test14mainFZv11permsNumberyAG5E5test16Number
        mov    04Ch[ESP],ESI
        mov    EDX,_D5test14mainFZv11permsNumberyAG5E5test16Number[04h]
        mov    050h[ESP],ECX
        mov    024h[ESP],EAX
        mov    028h[ESP],EDX
        add    ESP,8
        cmp    dword ptr _D5test14mainFZv11permsNumberyAG5E5test16Number,0
        je    L382
        mov    EBX,020h[ESP]
        mov    EDI,_D5test14mainFZv11permsNumberyAG5E5test16Number
        lea    ECX,[EDI*4][EDI]
        mov    060h[ESP],EBX
        lea    ECX,[00h][ECX*4]
        add    ECX,EBX
        mov    04Ch[ESP],ECX
L88:        push    dword ptr 060h[ESP]
        xor    EAX,EAX
        push    0
        push    0
        push    0
        call    near ptr
_D5test110isPossibleFNaNbyPG5E5test16NumberyPG5E5test15ColoryPG5E5test15DrinkyPG5E5test15SmokeyPG5E5test13PetZb
        test    AL,AL
        je    L36F
        cmp    dword ptr _D5test14mainFZv10permsColoryAG5E5test15Color,0
        mov    EAX,_D5test14mainFZv10permsColoryAG5E5test15Color
        mov    EDX,_D5test14mainFZv10permsColoryAG5E5test15Color[04h]
        mov    03Ch[ESP],EAX
        mov    040h[ESP],EDX
        je    L36F
        mov    EBX,_D5test14mainFZv10permsColoryAG5E5test15Color
        lea    ESI,[EBX*4][EBX]
        lea    ESI,[00h][ESI*4]
        add    ESI,040h[ESP]
        mov    EBP,040h[ESP]
        mov    050h[ESP],ESI
LDD:        push    dword ptr 060h[ESP]
        xor    EAX,EAX
        push    EBP
        push    0
        push    0
        call    near ptr
_D5test110isPossibleFNaNbyPG5E5test16NumberyPG5E5test15ColoryPG5E5test15DrinkyPG5E5test15SmokeyPG5E5test13PetZb
        test    AL,AL
        je    L362
        cmp    dword ptr _D5test14mainFZv10permsDrinkyAG5E5test15Drink,0
        mov    EAX,_D5test14mainFZv10permsDrinkyAG5E5test15Drink
        mov    EDX,_D5test14mainFZv10permsDrinkyAG5E5test15Drink[04h]
        mov    034h[ESP],EAX
        mov    038h[ESP],EDX
        je    L362
        mov    ECX,_D5test14mainFZv10permsDrinkyAG5E5test15Drink
        lea    EBX,[ECX*4][ECX]
        lea    EBX,[00h][EBX*4]
        add    EBX,038h[ESP]
        mov    EDI,038h[ESP]
        mov    054h[ESP],EBX
L131:        push    dword ptr 060h[ESP]
        xor    EAX,EAX
        push    EBP
        push    EDI
        push    0
        call    near ptr
_D5test110isPossibleFNaNbyPG5E5test16NumberyPG5E5test15ColoryPG5E5test15DrinkyPG5E5test15SmokeyPG5E5test13PetZb
        test    AL,AL
        je    L355
        cmp    dword ptr _D5test14mainFZv10permsSmokeyAG5E5test15Smoke,0
        mov    EAX,_D5test14mainFZv10permsSmokeyAG5E5test15Smoke
        mov    EDX,_D5test14mainFZv10permsSmokeyAG5E5test15Smoke[04h]
        mov    014h[ESP],EAX
        mov    018h[ESP],EDX
        je    L355
        mov    ECX,_D5test14mainFZv10permsSmokeyAG5E5test15Smoke
        lea    EDX,[ECX*4][ECX]
        lea    EDX,[00h][EDX*4]
        add    EDX,018h[ESP]
        mov    ESI,018h[ESP]
        mov    058h[ESP],EDX
L184:        push    dword ptr 060h[ESP]
        xor    EAX,EAX
        push    EBP
        push    EDI
        push    ESI
        call    near ptr
_D5test110isPossibleFNaNbyPG5E5test16NumberyPG5E5test15ColoryPG5E5test15DrinkyPG5E5test15SmokeyPG5E5test13PetZb
        test    AL,AL
        je    L348
        cmp    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet,0
        mov    EAX,_D5test14mainFZv8permsPetyAG5E5test13Pet
        mov    EDX,_D5test14mainFZv8permsPetyAG5E5test13Pet[04h]
        mov    024h[ESP],EAX
        mov    028h[ESP],EDX
        je    L348
        mov    ECX,_D5test14mainFZv8permsPetyAG5E5test13Pet
        lea    EDX,[ECX*4][ECX]
        lea    EDX,[00h][EDX*4]
        add    EDX,028h[ESP]
        mov    EBX,028h[ESP]
        mov    05Ch[ESP],EDX
L1D6:        push    dword ptr 060h[ESP]
        mov    EAX,EBX
        push    EBP
        push    EDI
        push    ESI
        call    near ptr
_D5test110isPossibleFNaNbyPG5E5test16NumberyPG5E5test15ColoryPG5E5test15DrinkyPG5E5test15SmokeyPG5E5test13PetZb
        test    AL,AL
        je    L33B
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[024h]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[020h]
        call    near ptr _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv
        mov    EAX,044h[ESP]
        mov    EDX,048h[ESP]
        mov    02Ch[ESP],EAX
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        mov    030h[ESP],EDX
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[04Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[048h]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[05Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[058h]
        mov    ECX,040h[ESP]
        push    dword ptr [ECX]
        push    dword ptr 4[ECX]
        push    dword ptr 8[ECX]
        push    dword ptr 0Ch[ECX]
        push    dword ptr 010h[ECX]
        call    near ptr
_D3std5Úio4File99__T8writeflnTaTAyÙyE5test16Nation€€
 €Z€‰àMFxAa€ƒâ€¡€€žž€Ýv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[04Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[048h]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[06Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[068h]
        mov    EDX,070h[ESP]
        push    dword ptr [EDX]
        push    dword ptr 4[EDX]
        push    dword ptr 8[EDX]
        push    dword ptr 0Ch[EDX]
        push    dword ptr 010h[EDX]
        call    near ptr
_D3std5Úio4File99__T8writeflnTaTAyÙyE5test16Number€€
 €Z€‰àMFxAa€ƒâ€¡€€žž€Ýv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[04Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[048h]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[07Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[078h]
        push    dword ptr 0[EBP]
        push    dword ptr 4[EBP]
        push    dword ptr 8[EBP]
        push    dword ptr 0Ch[EBP]
        push    dword ptr 010h[EBP]
        call    near ptr
_D3std5Úio4File94__T8writeflnTaTAyÙyE5test15Color€€žž€Z€‰ÛMFxAa€ƒÝ€Ž
€ŽŽ€œœ€Øv
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[04Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[048h]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[08Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[088h]
        push    dword ptr [EDI]
        push    dword ptr 4[EDI]
        push    dword ptr 8[EDI]
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr 0Ch[EDI]
        push    dword ptr 010h[EDI]
        call    near ptr
_D3std5Úio4File94__T8writeflnTaTAyÙyE5test15Drink€€žž€Z€‰ÛMFxAa€ƒÝ€Ž
€ŽŽ€œœ€Øv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[04Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[048h]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[09Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[098h]
        push    dword ptr [ESI]
        push    dword ptr 4[ESI]
        push    dword ptr 8[ESI]
        push    dword ptr 0Ch[ESI]
        push    dword ptr 010h[ESI]
        call    near ptr
_D3std5Úio4File94__T8writeflnTaTAyÙyE5test15Smoke€€žž€Z€‰ÛMFxAa€ƒÝ€Ž
€ŽŽ€œœ€Øv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[04Ch]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[048h]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[0ACh]
        push    dword ptr _D5test14mainFZv8permsPetyAG5E5test13Pet[0A8h]
        push    dword ptr [EBX]
        push    dword ptr 4[EBX]
        push    dword ptr 8[EBX]
        push    dword ptr 0Ch[EBX]
        push    dword ptr 010h[EBX]
        call    near ptr
_D3std5Úio4File84__T8writeflnTaTAyÙyE5test13Pet€€šš€Z€‰ÑMFxAa€ƒÓ€Œž€ŒŒ€˜˜€Îv
        call    near ptr _D3std5stdio12__T7writelnZ7writelnFZv
L33B:        add    EBX,014h
        cmp    EBX,05Ch[ESP]
        jb    L1D6
L348:        add    ESI,014h
        cmp    ESI,058h[ESP]
        jb    L184
L355:        add    EDI,014h
        cmp    EDI,054h[ESP]
        jb    L131
L362:        add    EBP,014h
        cmp    EBP,050h[ESP]
        jb    LDD
L36F:        add    dword ptr 060h[ESP],014h
        mov    ECX,04Ch[ESP]
        cmp    060h[ESP],ECX
        jb    L88
L382:        pop    EDI
        xor    EAX,EAX
        pop    ESI
        pop    EBP
        pop    EBX
        add    ESP,054h
        ret

-----------------------------------

test2:

isPossible:
        push    EAX
        push    EBX
        push    EBP
        push    ESI
        push    EDI
        cmp    dword ptr 024h[ESP],0
        je    L1A
        mov    ECX,024h[ESP]
        cmp    dword ptr 0Ch[ECX],0
        jne    L1A7
L1A:        cmp    dword ptr 020h[ESP],0
        je    L2E
        mov    EDX,020h[ESP]
        cmp    dword ptr [EDX],0
        jne    L1A7
L2E:        cmp    dword ptr 01Ch[ESP],0
        je    L43
        mov    EBX,01Ch[ESP]
        cmp    dword ptr 8[EBX],4
        jne    L1A7
L43:        cmp    dword ptr 018h[ESP],0
        je    L58
        mov    ESI,018h[ESP]
        cmp    dword ptr 010h[ESI],4
        jne    L1A7
L58:        cmp    dword ptr 010h[ESP],0
        je    L6D
        mov    EAX,010h[ESP]
        cmp    dword ptr 4[EAX],0
        jne    L1A7
L6D:        cmp    dword ptr 024h[ESP],0
        je    L1C8
        cmp    dword ptr 020h[ESP],0
        je    L1C8
        cmp    dword ptr 01Ch[ESP],0
        je    L1C8
        cmp    dword ptr 018h[ESP],0
        je    L1C8
        cmp    dword ptr 010h[ESP],0
        je    L1C8
        xor    EDI,EDI
LA6:        mov    ECX,020h[ESP]
        mov    EDX,[EDI*4][ECX]
        mov    EBX,1
        cmp    EDX,EBX
        jne    LC3
        mov    ESI,01Ch[ESP]
        cmp    [EDI*4][ESI],EBX
        jne    L1A7
LC3:        mov    EAX,018h[ESP]
        mov    ECX,[EDI*4][EAX]
        test    ECX,ECX
        jne    LDC
        mov    ESI,010h[ESP]
        cmp    [EDI*4][ESI],4
        jne    L1A7
LDC:        cmp    EDX,4
        jne    LE9
        cmp    ECX,EBX
        jne    L1A7
LE9:        mov    EAX,024h[ESP]
        mov    ESI,[EDI*4][EAX]
        cmp    ESI,2
        jne    L103
        mov    EAX,01Ch[ESP]
        cmp    [EDI*4][EAX],0
        jne    L1A7
L103:        mov    EAX,3
        cmp    ECX,EAX
        jne    L119
        mov    ECX,01Ch[ESP]
        cmp    [EDI*4][ECX],EAX
        jne    L1A7
L119:        cmp    EDX,2
        jne    L126
        cmp    ESI,EBX
        jne    L1A7
L126:        mov    EDX,020h[ESP]
        xor    EBX,EBX
        lea    ESI,[EDI*4][EDX]
L12F:        mov    ECX,1
        cmp    [ESI],ECX
        jne    L150
        mov    EDX,020h[ESP]
        cmp    [EBX*4][EDX],3
        jne    L150
        mov    EDX,024h[ESP]
        mov    EAX,[EBX*4][EDX]
        sub    EAX,[EDI*4][EDX]
        cmp    EAX,ECX
        jne    L1A7
L150:        mov    EDX,024h[ESP]
        mov    EAX,[EDI*4][EDX]
        sub    EAX,[EBX*4][EDX]
        mov    EDX,EAX
        sar    EDX,01Fh
        xor    EAX,EDX
        sub    EAX,EDX
        mov    EDX,018h[ESP]
        mov    EBP,[EDI*4][EDX]
        cmp    EBP,2
        jne    L17E
        mov    ECX,010h[ESP]
        cmp    [EBX*4][ECX],1
        jne    L17E
        cmp    EAX,1
        jne    L1A7
L17E:        mov    ECX,010h[ESP]
        cmp    [EDI*4][ECX],3
        jne    L193
        cmp    [EBX*4][EDX],1
        jne    L193
        cmp    EAX,1
        jne    L1A7
L193:        cmp    EBP,2
        jne    L1B1
        mov    EDX,01Ch[ESP]
        cmp    [EBX*4][EDX],2
        jne    L1B1
        cmp    EAX,1
        je    L1B1
L1A7:        pop    EDI
        xor    EAX,EAX
        pop    ESI
        pop    EBP
        pop    EBX
        pop    ECX
        ret    010h
L1B1:        inc    EBX
        mov    ECX,5
        cmp    EBX,ECX
        jb    L12F
        inc    EDI
        cmp    EDI,ECX
        jb    LA6
L1C8:        pop    EDI
        mov    EAX,1
        pop    ESI
        pop    EBP
        pop    EBX
        pop    ECX
        ret    010h


Dmain:
L0:        sub    ESP,04Ch
        mov    EAX,offset FLAT:_D25TypeInfo_yAE5test26Nation6__initZ
        push    EBX
        push    EBP
        push    ESI
        push    EDI
        push    5
        push    EAX
        call    near ptr __d_arrayliteralTX
        mov    EBX,EAX
        mov    ECX,EBX
        mov    dword ptr [EAX],0
        mov    ESI,5
        mov    dword ptr 4[EBX],1
        mov    dword ptr 8[EBX],2
        mov    dword ptr 0Ch[EBX],3
        mov    dword ptr 010h[EBX],4
        mov    EAX,_D5test24mainFZv11permsNumberyAG5E5test26Number
        mov    01Ch[ESP],EAX
        mov    EDX,_D5test24mainFZv11permsNumberyAG5E5test26Number[04h]
        mov    020h[ESP],EDX
        add    ESP,8
        cmp    dword ptr _D5test24mainFZv11permsNumberyAG5E5test26Number,0
        je    L372
        mov    040h[ESP],ECX
        mov    EBX,018h[ESP]
        mov    EDI,_D5test24mainFZv11permsNumberyAG5E5test26Number
        lea    ECX,[EDI*4][EDI]
        lea    ECX,[00h][ECX*4]
        add    ECX,EBX
        mov    03Ch[ESP],ESI
        mov    058h[ESP],EBX
        mov    044h[ESP],ECX
L88:        push    dword ptr 058h[ESP]
        xor    EAX,EAX
        push    0
        push    0
        push    0
        call    near ptr
_D5test210isPossibleFNaNbS€†˜35__T11Nulla€ƒ›RefTyG5E€†6NumberZ€
€ˆ¹4€›¹5Colo€´¸Drink€³¸Smoke€–¸2€›¸3Pet€Ž¶Zb
        test    AL,AL
        je    L35F
        cmp    dword ptr _D5test24mainFZv10permsColoryAG5E5test25Color,0
        mov    EAX,_D5test24mainFZv10permsColoryAG5E5test25Color
        mov    EDX,_D5test24mainFZv10permsColoryAG5E5test25Color[04h]
        mov    01Ch[ESP],EAX
        mov    020h[ESP],EDX
        je    L35F
        mov    EBX,_D5test24mainFZv10permsColoryAG5E5test25Color
        lea    ESI,[EBX*4][EBX]
        lea    ESI,[00h][ESI*4]
        add    ESI,020h[ESP]
        mov    EBP,020h[ESP]
        mov    048h[ESP],ESI
LDD:        push    dword ptr 058h[ESP]
        xor    EAX,EAX
        push    EBP
        push    0
        push    0
        call    near ptr
_D5test210isPossibleFNaNbS€†˜35__T11Nulla€ƒ›RefTyG5E€†6NumberZ€
€ˆ¹4€›¹5Colo€´¸Drink€³¸Smoke€–¸2€›¸3Pet€Ž¶Zb
        test    AL,AL
        je    L352
        cmp    dword ptr _D5test24mainFZv10permsDrinkyAG5E5test25Drink,0
        mov    EAX,_D5test24mainFZv10permsDrinkyAG5E5test25Drink
        mov    EDX,_D5test24mainFZv10permsDrinkyAG5E5test25Drink[04h]
        mov    024h[ESP],EAX
        mov    028h[ESP],EDX
        je    L352
        mov    ECX,_D5test24mainFZv10permsDrinkyAG5E5test25Drink
        lea    EBX,[ECX*4][ECX]
        lea    EBX,[00h][EBX*4]
        add    EBX,028h[ESP]
        mov    EDI,028h[ESP]
        mov    04Ch[ESP],EBX
L131:        push    dword ptr 058h[ESP]
        xor    EAX,EAX
        push    EBP
        push    EDI
        push    0
        call    near ptr
_D5test210isPossibleFNaNbS€†˜35__T11Nulla€ƒ›RefTyG5E€†6NumberZ€
€ˆ¹4€›¹5Colo€´¸Drink€³¸Smoke€–¸2€›¸3Pet€Ž¶Zb
        test    AL,AL
        je    L345
        cmp    dword ptr _D5test24mainFZv10permsSmokeyAG5E5test25Smoke,0
        mov    EAX,_D5test24mainFZv10permsSmokeyAG5E5test25Smoke
        mov    EDX,_D5test24mainFZv10permsSmokeyAG5E5test25Smoke[04h]
        mov    02Ch[ESP],EAX
        mov    030h[ESP],EDX
        je    L345
        mov    ECX,_D5test24mainFZv10permsSmokeyAG5E5test25Smoke
        lea    EDX,[ECX*4][ECX]
        lea    EDX,[00h][EDX*4]
        add    EDX,030h[ESP]
        mov    ESI,030h[ESP]
        mov    050h[ESP],EDX
L184:        push    dword ptr 058h[ESP]
        xor    EAX,EAX
        push    EBP
        push    EDI
        push    ESI
        call    near ptr
_D5test210isPossibleFNaNbS€†˜35__T11Nulla€ƒ›RefTyG5E€†6NumberZ€
€ˆ¹4€›¹5Colo€´¸Drink€³¸Smoke€–¸2€›¸3Pet€Ž¶Zb
        test    AL,AL
        je    L338
        cmp    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet,0
        mov    EAX,_D5test24mainFZv8permsPetyAG5E5test23Pet
        mov    EDX,_D5test24mainFZv8permsPetyAG5E5test23Pet[04h]
        mov    034h[ESP],EAX
        mov    038h[ESP],EDX
        je    L338
        mov    ECX,_D5test24mainFZv8permsPetyAG5E5test23Pet
        lea    EDX,[ECX*4][ECX]
        lea    EDX,[00h][EDX*4]
        add    EDX,038h[ESP]
        mov    EBX,038h[ESP]
        mov    054h[ESP],EDX
L1D6:        push    dword ptr 058h[ESP]
        mov    EAX,EBX
        push    EBP
        push    EDI
        push    ESI
        call    near ptr
_D5test210isPossibleFNaNbS€†˜35__T11Nulla€ƒ›RefTyG5E€†6NumberZ€
€ˆ¹4€›¹5Colo€´¸Drink€³¸Smoke€–¸2€›¸3Pet€Ž¶Zb
        test    AL,AL
        je    L32B
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[024h]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[020h]
        call    near ptr _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[04Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[048h]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[05Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[058h]
        mov    ECX,050h[ESP]
        push    dword ptr [ECX]
        push    dword ptr 4[ECX]
        push    dword ptr 8[ECX]
        push    dword ptr 0Ch[ECX]
        push    dword ptr 010h[ECX]
        call    near ptr
_D3std5Úio4File99__T8writeflnTaTAyÙyE5test26Nation€€
 €Z€‰àMFxAa€ƒâ€¡€€žž€Ýv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[04Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[048h]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[06Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[068h]
        mov    EDX,068h[ESP]
        push    dword ptr [EDX]
        push    dword ptr 4[EDX]
        push    dword ptr 8[EDX]
        push    dword ptr 0Ch[EDX]
        push    dword ptr 010h[EDX]
        call    near ptr
_D3std5Úio4File99__T8writeflnTaTAyÙyE5test26Number€€
 €Z€‰àMFxAa€ƒâ€¡€€žž€Ýv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[04Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[048h]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[07Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[078h]
        push    dword ptr 0[EBP]
        push    dword ptr 4[EBP]
        push    dword ptr 8[EBP]
        push    dword ptr 0Ch[EBP]
        push    dword ptr 010h[EBP]
        call    near ptr
_D3std5Úio4File94__T8writeflnTaTAyÙyE5test25Color€€žž€Z€‰ÛMFxAa€ƒÝ€Ž
€ŽŽ€œœ€Øv
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[04Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[048h]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[08Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[088h]
        push    dword ptr [EDI]
        push    dword ptr 4[EDI]
        push    dword ptr 8[EDI]
        push    dword ptr 0Ch[EDI]
        push    dword ptr 010h[EDI]
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        call    near ptr
_D3std5Úio4File94__T8writeflnTaTAyÙyE5test25Drink€€žž€Z€‰ÛMFxAa€ƒÝ€Ž
€ŽŽ€œœ€Øv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[04Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[048h]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[09Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[098h]
        push    dword ptr [ESI]
        push    dword ptr 4[ESI]
        push    dword ptr 8[ESI]
        push    dword ptr 0Ch[ESI]
        push    dword ptr 010h[ESI]
        call    near ptr
_D3std5Úio4File94__T8writeflnTaTAyÙyE5test25Smoke€€žž€Z€‰ÛMFxAa€ƒÝ€Ž
€ŽŽ€œœ€Øv
        mov    EAX,offset FLAT:_D3std5stdio6stdoutS3std5stdio4File
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[04Ch]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[048h]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[0ACh]
        push    dword ptr _D5test24mainFZv8permsPetyAG5E5test23Pet[0A8h]
        push    dword ptr [EBX]
        push    dword ptr 4[EBX]
        push    dword ptr 8[EBX]
        push    dword ptr 0Ch[EBX]
        push    dword ptr 010h[EBX]
        call    near ptr
_D3std5Úio4File84__T8writeflnTaTAyÙyE5test23Pet€€šš€Z€‰ÑMFxAa€ƒÓ€Œž€ŒŒ€˜˜€Îv
        call    near ptr _D3std5stdio12__T7writelnZ7writelnFZv
L32B:        add    EBX,014h
        cmp    EBX,054h[ESP]
        jb    L1D6
L338:        add    ESI,014h
        cmp    ESI,050h[ESP]
        jb    L184
L345:        add    EDI,014h
        cmp    EDI,04Ch[ESP]
        jb    L131
L352:        add    EBP,014h
        cmp    EBP,048h[ESP]
        jb    LDD
L35F:        add    dword ptr 058h[ESP],014h
        mov    ECX,044h[ESP]
        cmp    058h[ESP],ECX
        jb    L88
L372:        pop    EDI
        xor    EAX,EAX
        pop    ESI
        pop    EBP
        pop    EBX
        add    ESP,04Ch
        ret

-----------------------------------

This is one central part of the isPossible function of test1:


L96:    mov ECX,020h[ESP]
        mov EDX,[EBP*4][ECX]
        mov ECX,1
        cmp EDX,ECX
        jne LB3
        mov EAX,01Ch[ESP]
        cmp [EBP*4][EAX],ECX
        jne L179
LB3:    mov EBX,018h[ESP]
        mov EAX,[EBP*4][EBX]
        test    EAX,EAX
        jne LC8
        cmp [EBP*4][ESI],4
        jne L179
LC8:    cmp EDX,4
        jne LD5
        cmp EAX,ECX
        jne L179
LD5:    mov EBX,[EBP*4][EDI]
        cmp EBX,2
        jne LEB
        mov ECX,01Ch[ESP]
        cmp [EBP*4][ECX],0
        jne L179
LEB:    mov ECX,3
        cmp EAX,ECX
        jne LFD
        mov EAX,01Ch[ESP]
        cmp [EBP*4][EAX],ECX
        jne L179
LFD:    cmp EDX,2
        jne L107
        cmp EBX,1
        jne L179
L107:   mov EDX,020h[ESP]
        xor EBX,EBX
        lea EAX,[EBP*4][EDX]
L110:   cmp dword ptr [EAX],1
        jne L12A
        mov ECX,020h[ESP]
        cmp [EBX*4][ECX],3
        jne L12A
        mov EDX,[EBX*4][EDI]
        sub EDX,[EBP*4][EDI]
        cmp EDX,1
        jne L179
L12A:   mov 010h[ESP],EAX
        mov EAX,[EBP*4][EDI]
        mov EDX,018h[ESP]
        sub EAX,[EBX*4][EDI]
        mov ECX,EAX
        sar ECX,01Fh
        xor EAX,ECX
        sub EAX,ECX
        mov ECX,[EBP*4][EDX]
        cmp ECX,2
        jne L154
        cmp [EBX*4][ESI],1
        jne L154
        cmp EAX,1
        jne L179



This is the same part of the isPossible function of test2:

LA6:    mov ECX,020h[ESP]
        mov EDX,[EDI*4][ECX]
        mov EBX,1
        cmp EDX,EBX
        jne LC3
        mov ESI,01Ch[ESP]
        cmp [EDI*4][ESI],EBX
        jne L1A7
LC3:    mov EAX,018h[ESP]
        mov ECX,[EDI*4][EAX]
        test    ECX,ECX
        jne LDC
       mov ESI,010h[ESP]
cmp [EDI*4][ESI],4 jne L1A7 LDC: cmp EDX,4 jne LE9 cmp ECX,EBX jne L1A7
LE9:   mov EAX,024h[ESP]
mov ESI,[EDI*4][EAX] cmp ESI,2 jne L103 mov EAX,01Ch[ESP] cmp [EDI*4][EAX],0 jne L1A7 L103: mov EAX,3 cmp ECX,EAX jne L119 mov ECX,01Ch[ESP] cmp [EDI*4][ECX],EAX jne L1A7 L119: cmp EDX,2 jne L126 cmp ESI,EBX jne L1A7 L126: mov EDX,020h[ESP] xor EBX,EBX lea ESI,[EDI*4][EDX]
L12F:  mov ECX,1
cmp [ESI],ECX jne L150 mov EDX,020h[ESP] cmp [EBX*4][EDX],3 jne L150
       mov EDX,024h[ESP]
mov EAX,[EBX*4][EDX] sub EAX,[EDI*4][EDX] cmp EAX,ECX jne L1A7 L150: mov EDX,024h[ESP]
       mov EAX,[EDI*4][EDX]
sub EAX,[EBX*4][EDX] mov EDX,EAX sar EDX,01Fh xor EAX,EDX sub EAX,EDX mov EDX,018h[ESP] mov EBP,[EDI*4][EDX] cmp EBP,2 jne L17E mov ECX,010h[ESP] cmp [EBX*4][ECX],1 jne L17E cmp EAX,1 jne L1A7 You can see several extra mov instructions (that I have tried to mark with a ">"), that could cause the about 15% slowdown. I don't know the cause of the lower performance of the second version. Perhaps those extra mov instructions are caused by a higher reister pressure. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 17 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11289




Created an attachment (id=1269)
First benchmark version with pointers

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11289




Created an attachment (id=1270)
First benchmark version with RefNullable

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 17 2013