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
|
wait bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newParFor(nthrmax uint32) *ParFor
|
var (
|
||||||
func parForSetup(desc *ParFor, nthr, n uint32, ctx *byte, wait bool, body func(*ParFor, uint32))
|
newparfor_m,
|
||||||
func parForDo(desc *ParFor)
|
parforsetup_m,
|
||||||
func parForIters(desc *ParFor, tid uintptr) (uintptr, uintptr)
|
parfordo_m,
|
||||||
|
parforiters_m mFunction
|
||||||
|
)
|
||||||
|
|
||||||
var NewParFor = newParFor
|
func NewParFor(nthrmax uint32) *ParFor {
|
||||||
var ParForSetup = parForSetup
|
mp := acquirem()
|
||||||
var ParForDo = parForDo
|
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) {
|
func ParForIters(desc *ParFor, tid uint32) (uint32, uint32) {
|
||||||
begin, end := parForIters(desc, uintptr(tid))
|
mp := acquirem()
|
||||||
return uint32(begin), uint32(end)
|
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
|
//go:noescape
|
||||||
|
|
|
||||||
|
|
@ -192,8 +192,47 @@ exit:
|
||||||
|
|
||||||
// For testing from Go.
|
// For testing from Go.
|
||||||
void
|
void
|
||||||
runtime·parforiters(ParFor *desc, uintptr tid, uintptr *start, uintptr *end)
|
runtime·newparfor_m(void)
|
||||||
{
|
{
|
||||||
*start = (uint32)desc->thr[tid].pos;
|
g->m->ptrarg[0] = runtime·parforalloc(g->m->scalararg[0]);
|
||||||
*end = (uint32)(desc->thr[tid].pos>>32);
|
}
|
||||||
|
|
||||||
|
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