runtime: use goc2c as much as possible

Package runtime's C functions written to be called from Go
started out written in C using carefully constructed argument
lists and the FLUSH macro to write a result back to memory.

For some functions, the appropriate parameter list ended up
being architecture-dependent due to differences in alignment,
so we added 'goc2c', which takes a .goc file containing Go func
declarations but C bodies, rewrites the Go func declaration to
equivalent C declarations for the target architecture, adds the
needed FLUSH statements, and writes out an equivalent C file.
That C file is compiled as part of package runtime.

Native Client's x86-64 support introduces the most complex
alignment rules yet, breaking many functions that could until
now be portably written in C. Using goc2c for those avoids the
breakage.

Separately, Keith's work on emitting stack information from
the C compiler would require the hand-written functions
to add #pragmas specifying how many arguments are result
parameters. Using goc2c for those avoids maintaining #pragmas.

For both reasons, use goc2c for as many Go-called C functions
as possible.

This CL is a replay of the bulk of CL 15400047 and CL 15790043,
both of which were reviewed as part of the NaCl port and are
checked in to the NaCl branch. This CL is part of bringing the
NaCl code into the main tree.

No new code here, just reformatting and occasional movement
into .h files.

LGTM=r
R=dave, alex.brainman, r
CC=golang-codereviews
https://golang.org/cl/65220044
This commit is contained in:
Russ Cox 2014-02-20 15:58:47 -05:00
parent 258c278e12
commit 67c83db60d
30 changed files with 711 additions and 958 deletions

View file

@ -31,11 +31,11 @@ type LFNode struct {
Pushcnt uintptr
}
func lfstackpush(head *uint64, node *LFNode)
func lfstackpop2(head *uint64) *LFNode
func lfstackpush_go(head *uint64, node *LFNode)
func lfstackpop_go(head *uint64) *LFNode
var LFStackPush = lfstackpush
var LFStackPop = lfstackpop2
var LFStackPush = lfstackpush_go
var LFStackPop = lfstackpop_go
type ParFor struct {
body *byte
@ -48,17 +48,17 @@ type ParFor struct {
wait bool
}
func parforalloc2(nthrmax uint32) *ParFor
func parforsetup2(desc *ParFor, nthr, n uint32, ctx *byte, wait bool, body func(*ParFor, uint32))
func parfordo(desc *ParFor)
func parforiters(desc *ParFor, tid uintptr) (uintptr, uintptr)
func newParFor(nthrmax uint32) *ParFor
func parForSetup(desc *ParFor, nthr, n uint32, ctx *byte, wait bool, body func(*ParFor, uint32))
func parForDo(desc *ParFor)
func parForIters(desc *ParFor, tid uintptr) (uintptr, uintptr)
var NewParFor = parforalloc2
var ParForSetup = parforsetup2
var ParForDo = parfordo
var NewParFor = newParFor
var ParForSetup = parForSetup
var ParForDo = parForDo
func ParForIters(desc *ParFor, tid uint32) (uint32, uint32) {
begin, end := parforiters(desc, uintptr(tid))
begin, end := parForIters(desc, uintptr(tid))
return uint32(begin), uint32(end)
}
@ -80,11 +80,13 @@ var BytesHash = bytesHash
var Int32Hash = int32Hash
var Int64Hash = int64Hash
func GogoBytes() int32
var hashLoad float64 // declared in hashmap.c
var HashLoad = &hashLoad
func memclrBytes(b []byte)
var MemclrBytes = memclrBytes
func gogoBytes() int32
var GogoBytes = gogoBytes