mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Add check for interleaved coroutines
It's not an optimization per se, but it seems to help: name old speed new speed delta wuffs_deflate_decode_1k/clang5 138MB/s ± 1% 150MB/s ± 1% +8.96% (p=0.008 n=5+5) wuffs_deflate_decode_10k/clang5 223MB/s ± 0% 243MB/s ± 0% +9.25% (p=0.008 n=5+5) wuffs_deflate_decode_100k_just_one_read/clang5 263MB/s ± 2% 289MB/s ± 0% +10.19% (p=0.008 n=5+5) wuffs_deflate_decode_100k_many_big_reads/clang5 220MB/s ± 1% 243MB/s ± 0% +10.42% (p=0.008 n=5+5) wuffs_deflate_decode_1k/gcc7 158MB/s ± 0% 157MB/s ± 0% ~ (p=0.056 n=5+5) wuffs_deflate_decode_10k/gcc7 268MB/s ± 0% 268MB/s ± 0% ~ (p=1.000 n=5+5) wuffs_deflate_decode_100k_just_one_read/gcc7 312MB/s ± 0% 320MB/s ± 0% +2.62% (p=0.008 n=5+5) wuffs_deflate_decode_100k_many_big_reads/gcc7 254MB/s ± 0% 253MB/s ± 0% -0.48% (p=0.016 n=5+5)
This commit is contained in:
1 parent
d076b6e800
commit
ecccafab09
5 files changed
+131
No files matched your search
@@ -325,6 +325,8 @@ type gen struct {
|
||||
|
||||
currFunk funk
|
||||
funks map[t.QQID]funk
|
||||
|
||||
numPublicCoroutines uint32
|
||||
}
|
||||
|
||||
func (g *gen) generate() ([]byte, error) {
|
||||
@@ -712,6 +714,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
||||
b.writes("struct {\n")
|
||||
if n.Classy() {
|
||||
b.writes("uint32_t magic;\n")
|
||||
b.writes("uint32_t active_coroutine;\n")
|
||||
b.writes("\n")
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ type funk struct {
|
||||
|
||||
astFunc *a.Func
|
||||
cName string
|
||||
coroID uint32
|
||||
returnsStatus bool
|
||||
|
||||
varList []*a.Var
|
||||
@@ -174,9 +175,14 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error {
|
||||
}
|
||||
|
||||
func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error {
|
||||
if n.Public() && n.Effect().Coroutine() {
|
||||
g.numPublicCoroutines++
|
||||
}
|
||||
|
||||
g.currFunk = funk{
|
||||
astFunc: n,
|
||||
cName: g.funcCName(n),
|
||||
coroID: g.numPublicCoroutines,
|
||||
|
||||
returnsStatus: n.Effect().Coroutine() ||
|
||||
((n.Out() != nil) && n.Out().IsStatus()),
|
||||
@@ -256,6 +262,17 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
if err := g.writeFuncImplArgChecks(b, g.currFunk.astFunc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// For public coroutines, check that we are not suspended in an active
|
||||
// coroutine.
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
b.printf("if ((self->private_impl.active_coroutine != 0) && "+
|
||||
"(self->private_impl.active_coroutine != %d)) {\n", g.currFunk.coroID)
|
||||
b.writes("self->private_impl.magic = WUFFS_BASE__DISABLED;\n")
|
||||
b.writes("return wuffs_base__error__interleaved_coroutine_calls;\n")
|
||||
b.writes("}\n")
|
||||
b.writes("self->private_impl.active_coroutine = 0;\n")
|
||||
}
|
||||
}
|
||||
|
||||
if g.currFunk.astFunc.Effect().Coroutine() ||
|
||||
@@ -325,6 +342,9 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
|
||||
b.printf("self->private_impl.%s%s[0].coro_susp_point = coro_susp_point;\n",
|
||||
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
if g.currFunk.astFunc.Public() {
|
||||
b.printf("self->private_impl.active_coroutine = %d;\n", g.currFunk.coroID)
|
||||
}
|
||||
if err := g.writeResumeSuspend(b, &g.currFunk, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user