mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: convert parfor to Go
LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews, khr https://golang.org/cl/132100043
This commit is contained in:
parent
48452a276d
commit
98bebcc90a
2 changed files with 87 additions and 12 deletions
|
|
@ -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
|
||||
)
|
||||
|
||||
var NewParFor = newParFor
|
||||
var ParForSetup = parForSetup
|
||||
var ParForDo = parForDo
|
||||
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)
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue