develooper Front page | perl.perl6.internals | Postings from November 2001

RE: Yet another switch/goto implementation

Thread Previous | Thread Next
From:
Daniel Grunblatt
Date:
November 5, 2001 07:07
Subject:
RE: Yet another switch/goto implementation
Message ID:
Pine.BSO.4.33.0111050916540.27990-100000@trinity.mali.com.ar


On Mon, 5 Nov 2001, Brent Dax wrote:

> Michael Fischer:
> # On Nov 04, Brent Dax <brentdax@cpan.org> took up a keyboard
> # and banged out
> # > Michael Fischer:
> # > # In the goto case, we spin. And perhaps I am broken there. End
> # > # really wants to return, not just set the pc, but I hadn't thought
> # > # of a clever way to do that corner case, and wanted to see what
> # > # the behavior would be without it. I suspect I need it.
> # >
> # > Can't you just break()?
> #
> # Out of a function?
>
> Isn't the win in computed goto that you inline the sub bodies and can
> loop implicitly instead of explicitly, thus saving a jump or two?

Exactly, that's why I suggested not to use computed goto when tracing,
checking bounds or profiling, there is no way , I think, to use it without
loosing speed.

Daniel Grunblatt.

>
> 	goto *lookup[*pc];
>
> 	op0:
> 		return;
> 	op1:
> 		pc += 1;
> 		goto *lookup[*pc];
> 	op2:
> 		/* whatever */
> 		pc += size_of_op_2;
> 		goto lookup[*pc];
> 	op3:
> 		/* this one may halt */
> 		if(whatever) {
> 			pc += size_of_op_3;
> 			goto lookup[*pc];
> 		}
> 		else {
> 			return;
> 		}
>
> vs.
>
>
> 	while(pc) {
> 		goto *lookup[*pc];
>
> 		op0:
> 			pc=Parrot_op_end(pc, interp);
> 			continue;
> 		op1:
> 			pc=Parrot_op_noop(pc, interp);
> 			continue;
> 		op2:
> 			pc=Parrot_op_whatever(pc, interp);
> 			continue;
> 		op3:
> 			pc=Parrot_op_whatever_else(pc, interp);
> 			continue;
> 		...
> 	}
>
> The second example really is no better than a switch (and perhaps worse,
> since the compiler can't get a high-level view of things and maybe come
> up with a better way to do it).
>
> --Brent Dax
> brentdax@cpan.org
> Configure pumpking for Perl 6
>
> When I take action, I'm not going to fire a $2 million missile at a $10
> empty tent and hit a camel in the butt.
>     --Dubya
>
>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About