std.data.json formal review

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 18 08:39:41 PDT 2015


Am Tue, 18 Aug 2015 10:58:17 -0400
schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:

> On 8/18/15 7:02 AM, Johannes Pfau wrote:
> > Am Tue, 18 Aug 2015 09:10:25 +0000
> > schrieb "Marc Schütz" <schuetzm at gmx.net>:
> >
> >> On Monday, 17 August 2015 at 22:34:36 UTC, Andrei Alexandrescu
> >> wrote:
> >>> On 8/17/15 2:51 PM, deadalnix wrote:
> >>>>   From the compiler perspective, the tag is much nicer.
> >>>> Compiler can use
> >>>> jump table for instance.
> >>>
> >>> The pointer is a more direct conduit to a jump table.
> >>
> >> Not really, because it most likely doesn't point to where you
> >> need it, but to a `TypeInfo` struct instead, which doesn't help
> >> you in a `switch` statement. Besides, you probably shouldn't
> >> compare pointers vs integers, but pointers vs enums.
> >
> > Here's an example with an enum tag, showing what compilers can do:
> > http://goo.gl/NUZwNo
> >
> > ARM ASM is easier to read for me. Feel free to switch to X86.
> >
> > The jump table requires only one instruction (the cmp #4 shouldn't
> > be necessary for a final switch, probably a GDC/GCC enhancement).
> > All instructions/data should be in the instruction cache. There's no
> > register save / function call overhead.
> >
> >
> > If you use a pointer:
> > http://goo.gl/9kb0vQ
> 
> That's a language issue - switch does not work with any pointers. I
> just submitted https://issues.dlang.org/show_bug.cgi?id=14931. --
> Andrei
> 

Yes, if we enable switch for pointers we get nicer D code.

No, this won't improve the ASM much: Enum values start at 0 and are
consecutive. With a final switch they're also bounded. All these points
do not apply to pointers. They don't start at 0, are not guaranteed to
be consecutive and likely can't be used with final switch. Because of
that a switch on pointers can never use jump tables.



More information about the Digitalmars-d mailing list