Comment #0 by n8sh.secondary — 2018-03-01T11:25:13Z
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
Comment #1 by robert.schadek — 2024-12-13T18:57:35Z