Spaghetti stack?
David Malcolm
dmalcolm@redhat.com
Sun Nov 1 12:52:09 GMT 2020
On Sat, 2020-10-31 at 19:52 +0000, Qiantan Hong wrote:
> Ah, that’s a great hint. I want to use
> it to get better call/cc, but that’s kind of similar to
> stackless coroutines.
>
> Any idea how Go did it using GCC?
Caveat: I'm not an expert at go
GCC's go frontend is split into two parts:
* gcc/go/gofrontend is shared with the golang and is C++ code that
implements parsing Go to an AST representation
* gcc/go implements a GCC frontend for go using the above, calling it
in the correct place within GCC's framework, and converting the AST
into GCC's IR so that the rest of GCC can optimize it and generate
assembler.
Looking at gcc/go/gofrontend and grepping for "routine" I see there are
Go_statement and Thunk_statement classes that seem to implement
goroutines and these non-trivial calling conventions in terms of
lowering to a more typical to C level of IR - if I'm reading it right.
For example, runtime.def has:
// Start a new goroutine.
DEF_GO_RUNTIME(GO, "__go_go", P2(UINTPTR, POINTER), R1(POINTER))
// Defer a function.
DEF_GO_RUNTIME(DEFERPROC, "runtime.deferproc", P3(BOOLPTR, UINTPTR,
POINTER),
R0())
// Defer a function, with stack-allocated defer structure.
DEF_GO_RUNTIME(DEFERPROCSTACK, "runtime.deferprocStack",
P4(POINTER, BOOLPTR, UINTPTR, POINTER), R0())
which would seem to be relevant.
So I *think* the gofrontend code shared with golang is doing this in a
go-specific way.
Hope this is helpful
Dave
> > On Oct 31, 2020, at 1:45 PM, Basile Starynkevitch <
> > basile@starynkevitch.net> wrote:
> >
> >
> > On 10/31/20 6:33 PM, David Malcolm via Jit wrote:
> > > On Sat, 2020-10-31 at 05:58 +0000, Qiantan Hong wrote:
> > > > Hi,
> > > >
> > > > I’m trying to find a way to implement/hack
> > > > a runtime using spaghetti stack with libgccjit,
> > > I have to confess that I wasn't familiar with the term "spaghetti
> > > stack".
> >
> > IIRS, the Go language and execution model has it. This is how you
> > could have millions of goroutines with only a few dozen threads
> > (and call stacks)
> >
> >
> > Regards.
> >
> > --
> > Basile STARYNKEVITCH == http://starynkevitch.net/Basile
> > opinions are mine only - les opinions sont seulement miennes
> > Bourg La Reine, France; <basile@starynkevitch.net>
> > (mobile phone: cf my web page / voir ma page web...)
> >
More information about the Jit
mailing list