Skip to content

Commit

Permalink
Using faster code for addition of paral branches
Browse files Browse the repository at this point in the history
  • Loading branch information
pachanga committed Jan 8, 2025
1 parent f2f2447 commit 03abe8b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/vm/vm.exec.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace bhl {
Expand Down Expand Up @@ -885,16 +886,16 @@ Coroutine ProcBlockOpcode(
IDeferSupport defer_scope
)
{
var (block_coro, block_paral, block_defer_scope) = _ProcBlockOpcode(
var (block_coro, block_paral_branches, block_defer_scope) = _ProcBlockOpcode(
ref exec.ip,
curr_frame, exec,
out var block_size,
defer_scope,
null
false
);

//NOTE: let's process paral block (add branches and defers)
if(block_paral != null)
if(block_paral_branches != null)
{
int tmp_ip = exec.ip;
while(tmp_ip < (exec.ip + block_size))
Expand All @@ -907,34 +908,34 @@ IDeferSupport defer_scope
exec,
out var tmp_size,
block_defer_scope,
block_paral
true
);

if(branch_coro != null)
{
block_paral.Attach(branch_coro);
block_paral_branches.Add(branch_coro);
tmp_ip += tmp_size;
}
}
}
return block_coro;
}

(Coroutine, IBranchyCoroutine, IDeferSupport) _ProcBlockOpcode(
(Coroutine, List<Coroutine>, IDeferSupport) _ProcBlockOpcode(
ref int ip,
Frame curr_frame,
ExecState exec,
out int size,
IDeferSupport defer_scope,
IBranchyCoroutine paral_scope
bool is_paral
)
{
var type = (BlockType)Bytecode.Decode8(curr_frame.bytecode, ref ip);
size = (int)Bytecode.Decode16(curr_frame.bytecode, ref ip);

if(type == BlockType.SEQ)
{
if(paral_scope != null)
if(is_paral)
{
var br = CoroutinePool.New<ParalBranchBlock>(this);
br.Init(curr_frame, ip + 1, ip + size);
Expand All @@ -951,19 +952,19 @@ IBranchyCoroutine paral_scope
{
var paral = CoroutinePool.New<ParalBlock>(this);
paral.Init(ip + 1, ip + size);
return (paral, paral, paral);
return (paral, paral.branches, paral);
}
else if(type == BlockType.PARAL_ALL)
{
var paral = CoroutinePool.New<ParalAllBlock>(this);
paral.Init(ip + 1, ip + size);
return (paral, paral, paral);
return (paral, paral.branches, paral);
}
else if(type == BlockType.DEFER)
{
var d = new DeferBlock(curr_frame, ip + 1, ip + size);
defer_scope.RegisterDefer(d);
//NOTE: we need to skip defer block
//NOTE: we need to skip the defer block
ip += size;
return (null, null, null);
}
Expand Down

0 comments on commit 03abe8b

Please sign in to comment.