public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Qiantan Hong <qhong@mit.edu>,
	Basile Starynkevitch <basile@starynkevitch.net>
Cc: "jit@gcc.gnu.org" <jit@gcc.gnu.org>
Subject: Re: Spaghetti stack?
Date: Sun, 01 Nov 2020 07:52:09 -0500	[thread overview]
Message-ID: <e1792a0e9011def083c907ee99d7ef7f627f54cf.camel@redhat.com> (raw)
In-Reply-To: <703E2E58-FF64-4A72-904C-820ECCAD2930@mit.edu>

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...)
> > 


      reply	other threads:[~2020-11-01 12:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-31  5:58 Qiantan Hong
2020-10-31 17:33 ` David Malcolm
2020-10-31 17:45   ` Basile Starynkevitch
2020-10-31 19:52     ` Qiantan Hong
2020-11-01 12:52       ` David Malcolm [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e1792a0e9011def083c907ee99d7ef7f627f54cf.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=basile@starynkevitch.net \
    --cc=jit@gcc.gnu.org \
    --cc=qhong@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).