* Spaghetti stack? @ 2020-10-31 5:58 Qiantan Hong 2020-10-31 17:33 ` David Malcolm 0 siblings, 1 reply; 5+ messages in thread From: Qiantan Hong @ 2020-10-31 5:58 UTC (permalink / raw) To: jit [-- Attachment #1: Type: text/plain, Size: 523 bytes --] Hi, I’m trying to find a way to implement/hack a runtime using spaghetti stack with libgccjit, I think I need to tell libgccjit to use a different calling convention, either implemented by myself, or somehow let it use the “bare” calling convention and generate prologue/ epilogue myself. However, I didn’t find any API about calling convention — neither do I have any idea how to express the prologue/epilogue with libgccjit because they’re at register level. Any idea? Best, Qiantan [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 1858 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Spaghetti stack? 2020-10-31 5:58 Spaghetti stack? Qiantan Hong @ 2020-10-31 17:33 ` David Malcolm 2020-10-31 17:45 ` Basile Starynkevitch 0 siblings, 1 reply; 5+ messages in thread From: David Malcolm @ 2020-10-31 17:33 UTC (permalink / raw) To: Qiantan Hong, jit 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". > I think I need to tell libgccjit to use a different > calling convention, either implemented by > myself, or somehow let it use the “bare” > calling convention and generate prologue/ > epilogue myself. However, I didn’t find > any API about calling convention — neither > do I have any idea how to express the > prologue/epilogue with libgccjit because they’re > at register level. > > Any idea? That sounds lower level that the approach libgccjit takes; libgccjit's API tends to mimic what's expressible by the C frontend. I don't think libgccjit currently exposes a way to set the calling convention, but IIRC the C frontend does. Does an existing GCC frontend exposes a way of implementing any of this? If so, it can probably be exposed by libgccjit, otherwise we'd have to add support to GCC for it, which makes it much harder. Another approach would be to do it "by hand", by implementing the calling convention by injecting calls to dynamically allocate the frame, populate it, and then make a call with the parameters suitably modified - if that makes sense. Hope this is helpful Dave ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Spaghetti stack? 2020-10-31 17:33 ` David Malcolm @ 2020-10-31 17:45 ` Basile Starynkevitch 2020-10-31 19:52 ` Qiantan Hong 0 siblings, 1 reply; 5+ messages in thread From: Basile Starynkevitch @ 2020-10-31 17:45 UTC (permalink / raw) To: David Malcolm, Qiantan Hong, jit 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...) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Spaghetti stack? 2020-10-31 17:45 ` Basile Starynkevitch @ 2020-10-31 19:52 ` Qiantan Hong 2020-11-01 12:52 ` David Malcolm 0 siblings, 1 reply; 5+ messages in thread From: Qiantan Hong @ 2020-10-31 19:52 UTC (permalink / raw) To: Basile Starynkevitch; +Cc: David Malcolm, jit [-- Attachment #1: Type: text/plain, Size: 1001 bytes --] 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? > 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...) > [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 1858 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Spaghetti stack? 2020-10-31 19:52 ` Qiantan Hong @ 2020-11-01 12:52 ` David Malcolm 0 siblings, 0 replies; 5+ messages in thread From: David Malcolm @ 2020-11-01 12:52 UTC (permalink / raw) To: Qiantan Hong, Basile Starynkevitch; +Cc: jit 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...) > > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-01 12:52 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-10-31 5:58 Spaghetti stack? 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 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).