|
38 | 38 | #include "xls/ir/op.h" |
39 | 39 | #include "xls/ir/package.h" |
40 | 40 | #include "xls/ir/proc_elaboration.h" |
| 41 | +#include "xls/ir/value.h" |
41 | 42 | #include "xls/scheduling/pipeline_schedule.h" |
42 | 43 | #include "xls/scheduling/run_pipeline_schedule.h" |
43 | 44 | #include "xls/scheduling/scheduling_options.h" |
@@ -244,6 +245,60 @@ TEST_P(SynchronousProcsTest, ChainedProc) { |
244 | 245 | absl_testing::IsOkAndHolds(outputs)); |
245 | 246 | } |
246 | 247 |
|
| 248 | +TEST_P(SynchronousProcsTest, DecoupledNextProc) { |
| 249 | + Package package(TestBaseName()); |
| 250 | + |
| 251 | + TokenlessProcBuilder pb(NewStyleProc(), "my_proc", "tkn", &package); |
| 252 | + Type* u32 = package.GetBitsType(32); |
| 253 | + BReceiveChannel in = pb.AddInputChannel("top_in", u32); |
| 254 | + BSendChannel out = pb.AddOutputChannel("top_out", u32); |
| 255 | + BStateElement st_elem = pb.UnreadStateElement("accum", Value(UBits(0, 32)), |
| 256 | + /*non_synthesizable=*/false); |
| 257 | + BValue st = pb.StateRead(st_elem); |
| 258 | + BValue received = pb.Receive(in); |
| 259 | + BValue next_st = pb.Add(st, received); |
| 260 | + |
| 261 | + pb.Next(st_elem, next_st); |
| 262 | + pb.Send(out, next_st); |
| 263 | + |
| 264 | + XLS_ASSERT_OK_AND_ASSIGN(Proc * top, pb.Build({})); |
| 265 | + XLS_ASSERT_OK(package.SetTop(top)); |
| 266 | + |
| 267 | + ASSERT_TRUE(top->uses_decoupled_next()); |
| 268 | + |
| 269 | + XLS_ASSERT_OK_AND_ASSIGN(ProcElaboration elab, |
| 270 | + ProcElaboration::Elaborate(top)); |
| 271 | + |
| 272 | + XLS_ASSERT_OK_AND_ASSIGN(PackageSchedule package_schedule, |
| 273 | + RunSynchronousPipelineSchedule( |
| 274 | + &package, TestDelayEstimator(), |
| 275 | + SchedulingOptions().clock_period_ps(1), elab)); |
| 276 | + |
| 277 | + ResetProto reset_proto; |
| 278 | + reset_proto.set_name("rst"); |
| 279 | + reset_proto.set_asynchronous(false); |
| 280 | + reset_proto.set_active_low(false); |
| 281 | + |
| 282 | + XLS_ASSERT_OK_AND_ASSIGN( |
| 283 | + CodegenResult result, |
| 284 | + ToPipelineModuleText( |
| 285 | + package_schedule, &package, |
| 286 | + BuildPipelineOptions() |
| 287 | + .reset(reset_proto.name(), reset_proto.asynchronous(), |
| 288 | + reset_proto.active_low(), reset_proto.reset_data_path()) |
| 289 | + .use_system_verilog(UseSystemVerilog()) |
| 290 | + .emit_as_pipeline(false))); |
| 291 | + |
| 292 | + ModuleSimulator simulator = |
| 293 | + NewModuleSimulator(result.verilog_text, result.signature, {}); |
| 294 | + absl::flat_hash_map<std::string, std::vector<Bits>> inputs = { |
| 295 | + {"top_in", {UBits(3, 32), UBits(10, 32), UBits(42, 32)}}}; |
| 296 | + absl::flat_hash_map<std::string, std::vector<Bits>> outputs = { |
| 297 | + {"top_out", {UBits(3, 32), UBits(13, 32), UBits(55, 32)}}}; |
| 298 | + EXPECT_THAT(simulator.RunInputSeriesProc(inputs, {{"top_out", 3}}), |
| 299 | + absl_testing::IsOkAndHolds(outputs)); |
| 300 | +} |
| 301 | + |
247 | 302 | INSTANTIATE_TEST_SUITE_P(PipelineGeneratorTestInstantiation, |
248 | 303 | SynchronousProcsTest, |
249 | 304 | testing::ValuesIn(kDefaultSimulationTargets), |
|
0 commit comments