Skip to content

Commit 6e52a4e

Browse files
grebecopybara-github
authored andcommitted
Clear the temporary register cache after setting a register.
This makes `SetRegister()` calls visible without having to `RunOneCycle()`. PiperOrigin-RevId: 686191961
1 parent 793d3de commit 6e52a4e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

xls/jit/block_jit.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ class BlockContinuationJitWrapper final : public BlockContinuation {
581581
}
582582
absl::Status SetRegisters(
583583
const absl::flat_hash_map<std::string, Value>& regs) final {
584+
temporary_regs_.reset();
584585
return continuation_->SetRegisters(regs);
585586
}
586587

xls/jit/block_jit_test.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,41 @@ TEST_F(BlockJitTest, SetInputsWithViews) {
146146
testing::ElementsAre(Value(UBits(42, 16))));
147147
}
148148

149+
TEST_F(BlockJitTest, SetRegistersImmediatelyVisible) {
150+
auto p = CreatePackage();
151+
BlockBuilder bb(TestName(), p.get());
152+
XLS_ASSERT_OK_AND_ASSIGN(
153+
auto r1, bb.block()->AddRegister("test1", p->GetBitsType(16)));
154+
XLS_ASSERT_OK_AND_ASSIGN(
155+
auto r2, bb.block()->AddRegister("test2", p->GetBitsType(16)));
156+
XLS_ASSERT_OK(bb.block()->AddClockPort("clk"));
157+
bb.RegisterWrite(r1, bb.Literal(UBits(0, 16)));
158+
bb.RegisterWrite(r2, bb.Literal(UBits(0, 16)));
159+
auto read1 = bb.RegisterRead(r1);
160+
auto read2 = bb.RegisterRead(r2);
161+
bb.OutputPort("output", bb.Add(read1, read2));
162+
XLS_ASSERT_OK_AND_ASSIGN(Block * b, bb.Build());
163+
164+
XLS_ASSERT_OK_AND_ASSIGN(auto cont, kJitBlockEvaluator.NewContinuation(b));
165+
166+
XLS_ASSERT_OK(cont->RunOneCycle({}));
167+
EXPECT_THAT(cont->registers(),
168+
testing::UnorderedElementsAre(
169+
testing::Pair("test1", Value(UBits(0, 16))),
170+
testing::Pair("test2", Value(UBits(0, 16)))));
171+
172+
XLS_ASSERT_OK(cont->SetRegisters({
173+
{"test1", Value(UBits(1, 16))},
174+
{"test2", Value(UBits(2, 16))},
175+
}));
176+
177+
// Should be visible without a `RunOneCycle()` call.
178+
EXPECT_THAT(cont->registers(),
179+
testing::UnorderedElementsAre(
180+
testing::Pair("test1", Value(UBits(1, 16))),
181+
testing::Pair("test2", Value(UBits(2, 16)))));
182+
}
183+
149184
TEST_F(BlockJitTest, SetRegistersWithViews) {
150185
auto p = CreatePackage();
151186
BlockBuilder bb(TestName(), p.get());

0 commit comments

Comments
 (0)