Altifigence Academy

11 / 24 · Lab

Lab: trace two stages and bubbles

Calculate next state from old state and compare output tags, values, and edges.

Model registers that update together

Build a cycle model of the two-stage function f(a,b)=3(a+b). Each iteration represents one rising edge. First consume old s2. Next calculate the new second stage from old s1, then update both stages. Updating s1 before calculating s2 incorrectly allows an input to cross two registers at one edge.

Manually add pipeline-model.mjs to your project, save it, and run node pipeline-model.mjs in a Node.js terminal. Accept four inputs at edges 0 through 3, then drain at edges 4 and 5. All inputs are accepted under this always-ready contract. Null means an empty stage; it is not numeric zero. A valid zero result still represents a transaction.

javascript
import assert from 'node:assert/strict';
const inputs = [[1,2], [250,10], [100,0], [255,255]];
let s1 = null, s2 = null;
const seen = [];
for (let edge = 0; edge < 6; edge++) {
  if (s2 !== null) seen.push({ edge, ...s2 });
  const next2 = s1 === null ? null : {
    tag: s1.tag, y: (s1.sum * 3) % 256
  };
  const next1 = edge < inputs.length ? {
    tag: edge, sum: inputs[edge][0] + inputs[edge][1]
  } : null;
  s1 = next1;
  s2 = next2;
}
assert.deepEqual(seen, [
  { edge: 2, tag: 0, y: 9 },
  { edge: 3, tag: 1, y: 12 },
  { edge: 4, tag: 2, y: 44 },
  { edge: 5, tag: 3, y: 250 }
]);
assert.equal(s1, null);
assert.equal(s2, null);
console.log('PIPELINE PASS: 4 ordered results, latency=2');
EdgeAccepted inputDelivered output
0tag0:1+2None
1tag1:250+10None
2tag2:100+0tag0:y9
3tag3:255+255tag1:y12
4Bubbletag2:y44
5Bubbletag3:y250

The second transaction preserves sum 260 and narrows 780 to 12. The last narrows 1530 to 250. Comparing explicit edge, tag, and value catches timing errors as well as arithmetic errors. Drain bubbles clear both stages so old outputs cannot repeat.

To explore missing inputs, insert null at selected acceptance edges and increment tags only for accepted transactions. Output gaps follow the bubbles while valid transactions retain two-edge latency. This model has no output backpressure. The next chapter adds elastic behavior. Passing Node checks validates this state model, not HDL compilation or a DDS simulation run.

Try it yourself

If edge 1 has no input, and B,C,D are accepted at edges 2,3,4, what are delivery edges for tags 0 through 3?

Read the explanation

A transfers at edge 2. B,C,D transfer at edges 4,5,6. Edge 3 is an output bubble. Assign tags by acceptance order, 0,1,2,3, rather than using the physical edge number.

Lesson files

pipeline-model.mjs ↓

Your choice applies to this browser. Change it any time using the footer.