www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18542] New: DMD could generate better assembly for common

https://issues.dlang.org/show_bug.cgi?id=18542

          Issue ID: 18542
           Summary: DMD could generate better assembly for common range
                    check idioms
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

DMD could generate better assembly for common range check idioms. Take this
program:

---
bool isUpper(dchar c)  safe pure nothrow  nogc
{
    // Identical code to current std.ascii : isUpper.
    return c <= 'Z' && 'A' <= c;
}
​
void main(string[] args)
{
}
---

Compiled with dmd -O -release, the code for isUpper is:
        push    RBP
        mov     RBP,RSP
        cmp     EDI,05Ah
        ja      LE
        cmp     EDI,041h
        jae     L12
LE:     xor     EAX,EAX
        jmp short       L17
L12:    mov     EAX,1
L17:    pop     RBP
        ret

Compiled with ldc2 -O1, the code for isUpper is:
        addl    $-65, %edi
        cmpl    $26, %edi
        setb    %al
        retq

--
Mar 01 2018