From: Dmitriy Vyukov Date: Sun, 24 Aug 2014 07:47:06 +0000 (+0400) Subject: runtime: convert parfor to Go X-Git-Tag: go1.4beta1~740 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=98bebcc90a4e50e3fd458585744829f2065f2b09;p=gostls13.git runtime: convert parfor to Go LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews, khr https://golang.org/cl/132100043 --- diff --git a/src/pkg/runtime/export_test.go b/src/pkg/runtime/export_test.go index 9d25cafebb..f75b742b61 100644 --- a/src/pkg/runtime/export_test.go +++ b/src/pkg/runtime/export_test.go @@ -66,18 +66,54 @@ type ParFor struct { wait bool } -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_m, + parforsetup_m, + parfordo_m, + parforiters_m mFunction +) + +func NewParFor(nthrmax uint32) *ParFor { + mp := acquirem() + mp.scalararg[0] = uint(nthrmax) + onM(&newparfor_m) + desc := (*ParFor)(mp.ptrarg[0]) + mp.ptrarg[0] = nil + releasem(mp) + return desc +} + +func ParForSetup(desc *ParFor, nthr, n uint32, ctx *byte, wait bool, body func(*ParFor, uint32)) { + mp := acquirem() + mp.ptrarg[0] = unsafe.Pointer(desc) + mp.ptrarg[1] = unsafe.Pointer(ctx) + mp.ptrarg[2] = **(**unsafe.Pointer)(unsafe.Pointer(&body)) + mp.scalararg[0] = uint(nthr) + mp.scalararg[1] = uint(n) + mp.scalararg[2] = 0 + if wait { + mp.scalararg[2] = 1 + } + onM(&parforsetup_m) + releasem(mp) +} -var NewParFor = newParFor -var ParForSetup = parForSetup -var ParForDo = parForDo +func ParForDo(desc *ParFor) { + mp := acquirem() + mp.ptrarg[0] = unsafe.Pointer(desc) + onM(&parfordo_m) + releasem(mp) +} func ParForIters(desc *ParFor, tid uint32) (uint32, uint32) { - begin, end := parForIters(desc, uintptr(tid)) - return uint32(begin), uint32(end) + mp := acquirem() + mp.ptrarg[0] = unsafe.Pointer(desc) + mp.scalararg[0] = uint(tid) + onM(&parforiters_m) + begin := uint32(mp.scalararg[0]) + end := uint32(mp.scalararg[1]) + releasem(mp) + return begin, end } //go:noescape diff --git a/src/pkg/runtime/parfor.c b/src/pkg/runtime/parfor.c index 1073dfa394..6023193b5c 100644 --- a/src/pkg/runtime/parfor.c +++ b/src/pkg/runtime/parfor.c @@ -192,8 +192,47 @@ exit: // For testing from Go. void -runtime·parforiters(ParFor *desc, uintptr tid, uintptr *start, uintptr *end) +runtime·newparfor_m(void) { - *start = (uint32)desc->thr[tid].pos; - *end = (uint32)(desc->thr[tid].pos>>32); + g->m->ptrarg[0] = runtime·parforalloc(g->m->scalararg[0]); +} + +void +runtime·parforsetup_m(void) +{ + ParFor *desc; + void *ctx; + void (*body)(ParFor*, uint32); + + desc = g->m->ptrarg[0]; + g->m->ptrarg[0] = nil; + ctx = g->m->ptrarg[1]; + g->m->ptrarg[1] = nil; + body = g->m->ptrarg[2]; + g->m->ptrarg[2] = nil; + + runtime·parforsetup(desc, g->m->scalararg[0], g->m->scalararg[1], ctx, g->m->scalararg[2], body); +} + +void +runtime·parfordo_m(void) +{ + ParFor *desc; + + desc = g->m->ptrarg[0]; + g->m->ptrarg[0] = nil; + runtime·parfordo(desc); +} + +void +runtime·parforiters_m(void) +{ + ParFor *desc; + uintptr tid; + + desc = g->m->ptrarg[0]; + g->m->ptrarg[0] = nil; + tid = g->m->scalararg[0]; + g->m->scalararg[0] = desc->thr[tid].pos; + g->m->scalararg[1] = desc->thr[tid].pos>>32; }