systemverilog 支持链表吗?

发布于 2024-09-28 23:55:02 字数 174 浏览 3 评论 0原文

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

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

有什么想法吗?

I tried implementing a circular doubly-linked list class (with a single sentinel node) in systemverilog. The list itself seems to work as expected but ends up crashing the simulator (corrupting stack?)

This led me to wonder if this is something fundamentally unsupported by the language (in terms of allocation)? SV does have a "queue" construct that can be made to work in the same way (probably more efficient in both access and insertion time).

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋意浓 2024-10-05 23:55:03

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

SystemVerilog is a garbage-collected language. Circularly linked lists have the potential to cause issues if the garbage collection scheme implemented by the simulator you are using is buggy.

拥抱我好吗 2024-10-05 23:55:02

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

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

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

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

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

SystemVerilog does have a queue construct. They're declared a bit like arrays, but use the $ symbol:

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

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

Depending how you use combinations of methods push_front(), push_back(), pop_front() and pop_back(), you can implement stacks & FIFOs and the like. A quick internet search should give you a full list of methods and declaration options.

I doubt that SystemVerilog queues are synthesizable. And I'm not 100% sure how you'd go about making a circular buffer from one without checking indices first...

月下伊人醉 2024-10-05 23:55:02

我所不熟悉的语言本质上没有缺失任何东西。几乎所有内容都是通过引用传递的,所以这是您需要的主要内容。我能想到的唯一问题是要记住 SV 是垃圾收集的,因此当实例从列表中删除时清空对它们的引用非常重要(但无论如何你可能会这样做)

我很确定队列将在内部实现为链表。也就是说,当我想以奇怪而美妙的方式使用队列时,我在不同的模拟器上遇到了一些问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文