1

我尝试在 systemverilog 中实现一个循环双向链表类(带有一个哨兵节点)。该列表本身似乎按预期工作,但最终导致模拟器崩溃(损坏堆栈?)

这让我想知道这是否是语言根本不支持的东西(在分配方面)?SV 确实有一个“队列”结构,它可以以相同的方式工作(在访问和插入时间上可能更有效)。

有任何想法吗?

4

3 回答 3

6

SystemVerilog 确实有一个队列结构。它们的声明有点像数组,但使用$符号:

int myqueue[$];   // $ indicates a queue

myqueue.push_front(14);
some_int = myqueue.pop_back();

根据您使用方法组合的方式push_front()、和push_back(),您可以实现堆栈和 FIFO 等。快速的互联网搜索应该会为您提供方法和声明选项的完整列表。pop_front()pop_back()

我怀疑 SystemVerilog 队列是可合成的。而且我不是 100% 确定你将如何在不先检查索引的情况下从一个循环缓冲区中创建一个循环缓冲区......

于 2010-10-26T16:47:12.753 回答
1

SystemVerilog 是一种垃圾收集语言。如果您使用的模拟器实现的垃圾收集方案有问题,则循环链接列表可能会导致问题。

于 2012-08-11T20:13:16.630 回答
1

Nothing inherently missing from the language that I'm away of. Pretty much everything is pass by reference, so that's the main thing you need. Only gotcha I can think of is to remember that SV is garbage collected, so it's important to null out your references to instances when they're removed from your list (but you'd probably do that anyway)

I'm pretty sure the queue would be implemented as a linked list internally. That said I've had some issues on different simulators when I've wanted to use queues in weird and wonderful ways.

于 2010-11-08T13:21:58.103 回答