goto [variable], and address of code labels

2011-10-28 Thread Manu
Hi people. I'd like to propose support for taking the address of code labels, and supporting variable goto statements. This is a feature I have found extremely useful, implemented as a GCC specific extension. I've used this to get great speedups and simplify code while writing emulators/vm's. Per

Re: goto [variable], and address of code labels

2011-10-28 Thread Norbert Nemec
Have you considered how this mechanism should handle crossing of scope boundaries? On 28.10.2011 18:30, Manu wrote: Hi people. I'd like to propose support for taking the address of code labels, and supporting variable goto statements. This is a feature I have found extremely useful, implement

Re: goto [variable], and address of code labels

2011-10-28 Thread ponce
Provided some hairy conditions, the switch instruction will optimize to a jump table in GCC and probably most C compilers. In ICC, some static analysis is even used to optimize out the test before the switch. In D, final switch might enable such an optimization with statically checking for o

Re: goto [variable], and address of code labels

2011-10-28 Thread Dmitry Olshansky
On 28.10.2011 20:30, Manu wrote: Hi people. I'd like to propose support for taking the address of code labels, and supporting variable goto statements. This is a feature I have found extremely useful, implemented as a GCC specific extension. I've used this to get great speedups and simplify cod

Re: goto [variable], and address of code labels

2011-10-28 Thread bearophile
ponce: > Provided some hairy conditions, the switch instruction will optimize to > a jump table in GCC and probably most C compilers. > > In ICC, some static analysis is even used to optimize out the test > before the switch. > > In D, final switch might enable such an optimization with static

Re: goto [variable], and address of code labels

2011-10-28 Thread Dmitry Olshansky
On 28.10.2011 22:57, ponce wrote: Provided some hairy conditions, the switch instruction will optimize to a jump table in GCC and probably most C compilers. They do, you have no guaranties. It will either fly or crawl, depending on sparseness of values. Even so it *usually* makes table, just

Re: goto [variable], and address of code labels

2011-10-28 Thread Manu
On 28 October 2011 22:16, Dmitry Olshansky wrote: > On 28.10.2011 20:30, Manu wrote: > >> Hi people. >> >> I'd like to propose support for taking the address of code labels, and >> supporting variable goto statements. >> This is a feature I have found extremely useful, implemented as a GCC >> spe

Re: goto [variable], and address of code labels

2011-10-28 Thread Manu
On 28 October 2011 22:30, Dmitry Olshansky wrote: > On 28.10.2011 22:57, ponce wrote: > >> Provided some hairy conditions, the switch instruction will optimize to >> a jump table in GCC and probably most C compilers. >> >> > They do, you have no guaranties. It will either fly or crawl, depending

Re: goto [variable], and address of code labels

2011-10-29 Thread Dmitry Olshansky
On 29.10.2011 3:15, Manu wrote: This is instruction dispatch, the trick in the branch prediction that operates on per branch basis, thus single switch-jump based VM dispatch will mispredict jumps most of the time. I seen claims of up to 99% on average. If you place a whole sw

Re: goto [variable], and address of code labels

2011-10-29 Thread Manu
On 29 October 2011 10:55, Dmitry Olshansky wrote: > On 29.10.2011 3:15, Manu wrote: > >> >>This is instruction dispatch, the trick in the branch prediction >>that operates on per branch basis, thus single switch-jump based VM >>dispatch will mispredict jumps most of the time. I seen c

Re: goto [variable], and address of code labels

2011-10-29 Thread Dmitry Olshansky
On 29.10.2011 15:16, Manu wrote: On 29 October 2011 10:55, Dmitry Olshansky mailto:dmitry.o...@gmail.com>> wrote: On 29.10.2011 3:15, Manu wrote: This is instruction dispatch, the trick in the branch prediction that operates on per branch basis, thus single switch-j

Re: goto [variable], and address of code labels

2011-10-29 Thread bcs
On 10/28/2011 09:30 AM, Manu wrote: Hi people. I'd like to propose support for taking the address of code labels, and supporting variable goto statements. This is a feature I have found extremely useful, implemented as a GCC specific extension. I've used this to get great speedups and simplify