Re: Simulating computed goto

2020-11-26 Thread NonNull via Digitalmars-d-learn
On Thursday, 26 November 2020 at 04:42:08 UTC, Dukc wrote: On Wednesday, 25 November 2020 at 18:44:52 UTC, NonNull wrote: Is there a good way to simulate computed goto in D? I haven't used assembly myself, but it's possible that you can define a mixin that does this, using inline assembly.

Re: Simulating computed goto

2020-11-26 Thread NonNull via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 18:57:35 UTC, Paul Backus wrote: On Wednesday, 25 November 2020 at 18:44:52 UTC, NonNull wrote: How good is optimization in ldc2, gdc, dmd at compiling chained jumps into one jump each time? The easiest way to find the answer to a question like this is to

Re: Simulating computed goto

2020-11-26 Thread Dukc via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 20:05:28 UTC, NonNull wrote: So to simulate computed goto have to 1. wrap switch(x) in a loop [ while(0) ] 2. inside each case recompute x (instead of jump to computed y) 3. jump back to execute switch again [ continue ] It does look as if a nested switch can

Re: Simulating computed goto

2020-11-25 Thread Dukc via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 18:44:52 UTC, NonNull wrote: Is there a good way to simulate computed goto in D? I haven't used assembly myself, but it's possible that you can define a mixin that does this, using inline assembly.

Re: Simulating computed goto

2020-11-25 Thread NonNull via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 19:04:45 UTC, H. S. Teoh wrote: FWIW, D's switch statement is flexible enough to directly write Duff's device. How good is optimization in ldc2, gdc, dmd at compiling chained jumps into one jump each time? I'm pretty sure ldc2 and gdc will optimize away

Re: Simulating computed goto

2020-11-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 25, 2020 at 06:44:52PM +, NonNull via Digitalmars-d-learn wrote: > For automatically generated code of some low level kinds it is > convenient to have "computed goto" like this: > > https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html > > and D does not have this. > > A

Re: Simulating computed goto

2020-11-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 18:44:52 UTC, NonNull wrote: How good is optimization in ldc2, gdc, dmd at compiling chained jumps into one jump each time? The easiest way to find the answer to a question like this is to use the compiler explorer: https://d.godbolt.org/

Simulating computed goto

2020-11-25 Thread NonNull via Digitalmars-d-learn
For automatically generated code of some low level kinds it is convenient to have "computed goto" like this: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html and D does not have this. A switch could be used to simulate it. But this would lead to what could have been a single jump