Skip to content

Commit adde062

Browse files
committed
mask node outputs according to their bit width
closes #44
1 parent 68cfb22 commit adde062

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/logic/blueprints/singleCycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export const singleCycle: Blueprint = {
201201
},
202202
splitterImmediateALUOp: {
203203
type: makeSplitter(2, [
204-
[0, 31],
204+
[0, 15],
205205
[0, 5],
206206
]),
207207
outputs: {

src/logic/nodeTypes/splitter.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ export function makeSplitter(
4141
return values
4242
},
4343
undefined,
44-
bitRanges &&
45-
(() =>
46-
Object.fromEntries(
47-
bitRanges.map((r, i) => [`out${i}`, r[1] - r[0] + 1]),
48-
)),
44+
(get) =>
45+
Object.fromEntries(
46+
// If `bitRanges` is given, the bit width of each output will be calculated according to the bit range.
47+
// Otherwise, it'll be the same width as the input.
48+
bitRanges
49+
? bitRanges.map((r, i) => [`out${i}`, r[1] - r[0] + 1])
50+
: Array.from({ length: numOutputs }, (_, i) => [
51+
`out${i}`,
52+
get("in"),
53+
]),
54+
),
4955
)
5056
}

src/logic/simulation.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,18 @@ export function simulationStep(simulation: Simulation): Simulation {
444444
const outputs = node.type.executeRising(simulation, inputValues)
445445
for (const outputId in outputs) {
446446
// Forward each output value to its target input.
447+
let value = outputs[outputId]
448+
449+
if (node.outputBitWidths) {
450+
const bitWidth = node.outputBitWidths[outputId]
451+
if (bitWidth != 32) {
452+
value = value & ((1 << bitWidth) - 1)
453+
}
454+
}
455+
447456
const [targetNodeId, targetInputId] = getNodeTarget(
448457
node.outputs[outputId],
449458
)
450-
const value = outputs[outputId]
451459
newInputValues[targetNodeId] = {
452460
...newInputValues[targetNodeId],
453461
[targetInputId]: value,

0 commit comments

Comments
 (0)