Skip to content

Commit a998964

Browse files
committed
Complete generateComputeFun.
1 parent ae54422 commit a998964

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

compiler/generator/instructions.hh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,6 +2616,15 @@ struct IB {
26162616
return genForLoopInst(dec, end, inc);
26172617
}
26182618

2619+
static ForLoopInst* genForLoopInst(const std::string& index, int init, ValueInst* size,
2620+
int step = 1)
2621+
{
2622+
DeclareVarInst* dec = genDecLoopVar(index, genInt32Typed(), genInt32NumInst(init));
2623+
ValueInst* end = genLessThan(dec->load(), size);
2624+
StoreVarInst* inc = dec->store(genAdd(dec->load(), step));
2625+
return genForLoopInst(dec, end, inc);
2626+
}
2627+
26192628
// Used for Rust backend
26202629
static SimpleForLoopInst* genSimpleForLoopInst(const std::string& name, ValueInst* upperBound,
26212630
ValueInst* lowerBound = new Int32NumInst(0),
@@ -3373,15 +3382,21 @@ struct IB {
33733382

33743383
static DeclareFunInst* generateComputeFun(const std::string& name, const std::string& obj,
33753384
bool ismethod, bool isvirtual,
3376-
BlockInst* compute_block)
3385+
BlockInst* control_block, BlockInst* sample_block)
33773386
{
33783387
Names args = genMethod(obj, ismethod);
33793388
args.push_back(genNamedTyped("count", Typed::kInt32));
33803389
args.push_back(genNamedTyped("inputs", Typed::kFloatMacro_ptr_ptr));
33813390
args.push_back(genNamedTyped("outputs", Typed::kFloatMacro_ptr_ptr));
33823391

3383-
// Explicit return
3384-
compute_block->pushBackInst(genRetInst());
3392+
// Control rate code
3393+
BlockInst* compute_block = genBlockInst();
3394+
compute_block->pushBackInst(control_block);
3395+
3396+
// Sample rate code
3397+
ForLoopInst* loop = genForLoopInst("i", 0, genLoadFunArgsVar("count"), 1);
3398+
loop->pushBackInst(sample_block);
3399+
compute_block->pushBackInst(loop);
33853400

33863401
// Creates function
33873402
return IB::genVoidFunction(name, args, compute_block, isvirtual);

compiler/generator/instructions_compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Tree InstructionsCompiler::prepare(Tree LS)
109109
throw faustexception("Dump signal type finished...\n");
110110
} else if (gGlobal->gDumpNorm == 3) {
111111
SignalFIRCompiler fir_compiler(fContainer->inputs(), fContainer->outputs(), L1);
112-
dump2FIR(fir_compiler.genFIRModule());
112+
// dump2FIR(fir_compiler.genFIRModule());
113113
ModuleInst* fir_module = fir_compiler.genFIRModule();
114114

115115
std::stringstream cpp_stream;

compiler/transform/signalFIRCompiler.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,16 @@ void SignalFIRCompiler::visit(Tree sig)
110110
if (xtended* xt = (xtended*)getUserData(sig)) {
111111
list<ValueInst*> args;
112112
vector<Typed::VarType> atypes;
113-
// Compile all arguments then compile the function call
113+
int rtype = getCertifiedSigType(sig)->nature();
114+
// Compiles all arguments
114115
for (Tree b : sig->branches()) {
115116
self(b);
116117
args.push_back(popRes());
117118
atypes.push_back(convert2FIRType(getCertifiedSigType(b)->nature()));
118119
}
119-
120-
// ValueInst* res = xt->compute(args);
121-
122-
// HACK: for 'min/max' res may actually be of type kInt
123-
int rtype = getCertifiedSigType(sig)->nature();
124-
125-
// Compile the function declaration
120+
// Compiles the function declaration
126121
fGlobalBlock->pushBackInst(IB::genFunction(xt->name(), convert2FIRType(rtype), atypes));
127-
// pushRes((rtype == kInt) ? Node(int(res.getDouble())) : res);
128-
// Compile the function call
122+
// Compiles the function call
129123
pushRes(IB::genFunCallInst(xt->name(), args));
130124

131125
} else if (isSigInt(sig, &i_val)) {
@@ -376,6 +370,7 @@ void SignalFIRCompiler::compile()
376370
while (!isNil(output_list)) {
377371
// Compile each output
378372
Tree out_sig = hd(output_list);
373+
// std::cerr << "compile " << ppsig(out_sig) << std::endl;
379374
self(out_sig);
380375
// Get compiled value and sotre in the output
381376
ValueInst* res = popRes();
@@ -465,8 +460,9 @@ void SignalFIRCompiler::initTables()
465460
*/
466461
ModuleInst* SignalFIRCompiler::genFIRModule()
467462
{
468-
// Compile ouputs signals to FIR
463+
// Compile tables
469464
initTables();
465+
// Compile outputs signals to FIR
470466
compile();
471467

472468
// Create the FIR module using the generated FIR blocks
@@ -490,7 +486,10 @@ ModuleInst* SignalFIRCompiler::genFIRModule()
490486
IB::generateInstanceClear("instanceClear", "", true, true, fClearBlock));
491487

492488
// Compute
493-
fir_module->pushFunction(IB::generateComputeFun("compute", "", true, true, fComputeBlock));
489+
dump2FIR(fControlBlock);
490+
dump2FIR(fSampleBlock);
491+
fir_module->pushFunction(
492+
IB::generateComputeFun("compute", "", true, true, fControlBlock, fSampleBlock));
494493

495494
return fir_module;
496495
}

compiler/transform/signalFIRCompiler.hh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ inline BasicTyped* genBasicTyped(Tree sig)
6767
* **fResetBlock** — code executed once in the instanceResetUserInterface
6868
* **fClearBlock** — code executed once in the instanceClear
6969
* **fControlBlock** — per‑block computations done in `compute` function before the DSP loop
70-
* **fComputeBlock** — the per‑sample DSP body done in `compute`function
70+
* **fSampleBlock** — the per‑sample DSP body done in `compute`function
7171
*
7272
* During construction the compiler:
7373
* 1. Runs a `SignalBuilder` pass that allocates every resource
@@ -629,7 +629,7 @@ struct SignalFIRCompiler : public SignalVisitor {
629629
BlockInst* fResetBlock; // Code executed to reset DSP state (delays, tables, etc.)
630630
BlockInst* fClearBlock; // Code for clearing memory (if required by certain data structures)
631631
BlockInst* fControlBlock; // Code executed to update UI controls (sliders, buttons, etc.)
632-
BlockInst* fComputeBlock; // Main compute block executed at every sample frame
632+
BlockInst* fSampleBlock; // Main compute block executed at every sample frame
633633

634634
std::stack<ValueInst*> fValueStack; // Compiler's value stack used during signal traversal
635635
std::map<Tree, DelayedSig> fDelays; // Mapping between signals and their delay buffers
@@ -652,8 +652,8 @@ struct SignalFIRCompiler : public SignalVisitor {
652652
fResetBlock = IB::genBlockInst();
653653
fClearBlock = IB::genBlockInst();
654654
fControlBlock = IB::genBlockInst();
655-
fComputeBlock = IB::genBlockInst();
656-
655+
fSampleBlock = IB::genBlockInst();
656+
657657
// Prepare the signal compilation context
658658
// The SignalBuilder populates:
659659
// - Delay lines (fDelays)
@@ -673,7 +673,7 @@ struct SignalFIRCompiler : public SignalVisitor {
673673
* @brief Dispatch a write statement to the appropriate DSP code block.
674674
*
675675
* This method routes a generated `StatementInst` (such as an assignment or store)
676-
* to the correct code block (`fInitBlock`, `fControlBlock`, or `fComputeBlock`)
676+
* to the correct code block (`fInitBlock`, `fControlBlock`, or `fSampleBlock`)
677677
* based on the variability (lifetime) of the signal associated with `x`.
678678
*
679679
* Variability levels:
@@ -697,7 +697,7 @@ struct SignalFIRCompiler : public SignalVisitor {
697697
fControlBlock->pushBackInst(val);
698698
break;
699699
case kSamp:
700-
fComputeBlock->pushBackInst(val);
700+
fSampleBlock->pushBackInst(val);
701701
break;
702702
default:
703703
faustassert(false);

0 commit comments

Comments
 (0)