From 0e68d70b7fbf4533d7b5ccd84c439026062b1a0e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 4 Jul 2019 02:20:37 +0000 Subject: compiler: optimize 0,1,2-case select statement For a select statement with zero-, one-, or two-case with a default case, we can generate simpler code instead of calling the generic selectgo. A zero-case select is just blocking the execution. A one-case select is mostly just executing the case. A two-case select with a default case is a non-blocking send or receive. We add these special cases for lowering a select statement. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/184998 From-SVN: r273034 --- libgo/go/runtime/chan.go | 3 +++ libgo/go/runtime/select.go | 1 + 2 files changed, 4 insertions(+) (limited to 'libgo') diff --git a/libgo/go/runtime/chan.go b/libgo/go/runtime/chan.go index 6dfe2f3..6c8d6f7 100644 --- a/libgo/go/runtime/chan.go +++ b/libgo/go/runtime/chan.go @@ -32,6 +32,9 @@ import ( //go:linkname chanrecv1 runtime.chanrecv1 //go:linkname chanrecv2 runtime.chanrecv2 //go:linkname closechan runtime.closechan +//go:linkname selectnbsend runtime.selectnbsend +//go:linkname selectnbrecv runtime.selectnbrecv +//go:linkname selectnbrecv2 runtime.selectnbrecv2 const ( maxAlign = 8 diff --git a/libgo/go/runtime/select.go b/libgo/go/runtime/select.go index d658a34..16de9b8 100644 --- a/libgo/go/runtime/select.go +++ b/libgo/go/runtime/select.go @@ -14,6 +14,7 @@ import ( // themselves, so that the compiler will export them. // //go:linkname selectgo runtime.selectgo +//go:linkname block runtime.block const debugSelect = false -- cgit v1.1 From 4e62f891cdeabc14cf6195a69dc6528aab11e753 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 15 Jul 2019 21:17:16 +0000 Subject: runtime: expose the g variable Currently, getg is implemented in C, which loads the thread-local g variable. The g variable is declared static in C. This CL exposes the g variable, so it can be accessed from the Go side. This allows the Go compiler to inline getg calls to direct access of g. Currently, the actual inlining is only implemented in the gollvm compiler. The g variable is thread-local and the compiler backend may choose to cache the TLS address in a register or on stack. If a thread switch happens the cache may become invalid. I don't know how to disable the TLS address cache in gccgo, therefore the inlining of getg is not implemented. In the future gccgo may gain this if we know how to do it safely. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/186238 From-SVN: r273499 --- libgo/runtime/proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libgo') diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c index 26125cc..523dfd9 100644 --- a/libgo/runtime/proc.c +++ b/libgo/runtime/proc.c @@ -65,7 +65,7 @@ static void gscanstack(G*); #define __thread #endif -static __thread G *g; +__thread G *g __asm__(GOSYM_PREFIX "runtime.g"); #ifndef SETCONTEXT_CLOBBERS_TLS @@ -320,7 +320,7 @@ runtime_mcall(FuncVal *fv) if(gp != nil) { #ifdef USING_SPLIT_STACK - __splitstack_getcontext((void*)(&g->stackcontext[0])); + __splitstack_getcontext((void*)(&gp->stackcontext[0])); #else // We have to point to an address on the stack that is // below the saved registers. -- cgit v1.1