'如果'与“何时”相比用于制作多路复用器

发布于 2024-08-24 03:06:59 字数 100 浏览 6 评论 0原文

我被告知使用“when”语句来制作多路复用器,但不要使用“if”语句,因为它会导致计时错误... 我不明白这个... 那么“如果”和“何时”有什么区别?它们在硬件中映射到相同的东西吗?

i have been told to use 'when' statement to make multiplexer but not use 'if' statement as it will cause timing errors...
i don't understand this ...
so what is the difference between 'if' and 'when' ? and do they map to the same thing in hardware ?

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

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

发布评论

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

评论(3

山色无中 2024-08-31 03:06:59

好的,让我们首先讨论一下 if 和when 语句之间的区别:

  • 两者都称为数据流设计元素。

When 语句

  • 并发语句
  • 不在进程中使用,仅在体系结构中使用,因为进程是顺序执行的

if 语句

  • 顺序语句
  • 在进程中使用,因为它是顺序语句,并且不在进程外部使用

并且您知道多路复用器是一个不需要进程块的组件,因为它的行为不会随着输入的改变而改变,所以它将在进程之外,所以你必须使用when语句来编写它,因为它是并发语句。如果你用if语句编写它,可能会出现计时错误。此外,所有参考资料以及 Xilinx 帮助(如果您使用的是 Xilinx)都使用 when 语句而不是 if 语句编写多路复用器块

参考:数字设计原则与方法《实践》,约翰·F·韦克利,第三版

OK, lets discuss some points at first on the difference between if and when statements:

  • Both are called Dataflow Design Elements.

when statement

  • concurrent statement
  • not used in process, used only in architecture as process is sequential execution

if statement

  • sequential statement
  • used in process as it is sequential statement, and not used outside the process

And you know multiplexer is a component don't need process block, as its behavior doesn't change with changing its input, so it will be outside process, so you have to write it using when statement as it is concurrent statement.. And if you wrote it with if statement, timing errors may occur. Also all the references and also Xilinx help (if you are using Xilinx) are writing the Multiplexer block using when statement not if statement

Reference: Digital Design Priciples & Practices, John F. Wakerly, 3rd Edition

流云如水 2024-08-31 03:06:59

看看这些:

基本上,if 是顺序的,when 是并发的。它们不会映射到硬件中的同一事物... 此页面描述,在底部,合成 if 语句所需的一些特殊注意事项。

See these:

Basically, if is sequential, and when is concurrent. They do not map to the same thing in hardware... This page describes, at the bottom, some of the special considerations needed to synthesize an if statement.

腻橙味 2024-08-31 03:06:59

两种编码风格都是完全有效的。

让我们回忆一下一些元素。从HDL开始,综合分两个主要步骤完成:

  1. 首先,分析VHDL以检测RTL模板(包括RTL元素:触发器、算术表达式、多路复用器、控制逻辑)。我们说这些元素是“推断的”(即,您必须使用正确的模板进行编码才能获得最初想要的内容。在编码之前,您必须想象这些元素是如何连接的)。
  2. 第二步是真正的逻辑综合,它考虑特定的目标技术参数(可用门的类型、时序、面积、功率)。

这两个步骤清楚地将 RTL 功能需求(控制逻辑、计算)与技术意外事件(时序等)分开。

让我们回到第一步(RTL):

关于多路复用器,可以使用多种编码风格:

  • 使用并发分配:

    y<= a1 when cond1 else a2 when cond2 else cond3;

  • 在流程中使用 if 语句:

    进程(a1,a2,a3,cond1,cond2)
    开始
    如果(条件1)那么
    y≤a1;
    elsif(cond2) 那么
    y≤a2;
    别的
    y≤a3;
    结束如果;
    end;

  • 使用另一个并发分配
    形式,适合通用
    描述:如果 sel 是一个整数
    并 muxin 一个信号数组,然后:

    muxout <= muxin(sel); 推断多路复用器

请注意,3 种编码风格始终有效。还要注意,它们比简单的多路复用器“多一点”,因为编码风格强制存在优先级编码(if elsif,when else),这不是基于简单方程的多路复用器的情况,真正对称。

  • 使用案例陈述

    进程(a1,a2,a3,cond1,cond2)
    变量 cond : std_logic(1 降到 0);
    开始
    条件 := 条件2 &条件1;
    情况条件是
    当“01”=>时y<=a1;
    当“10”=>时y≤a2;
    当别人=> y≤a3;
    最终情况;
    end;

  • 使用 select 语句(在我们的
    例如,两个并发作业
    需要):

    sel <= cond2 &条件1;
    带选择
    y <= a1 当“01”时,
    a2 当“10”时,
    a3 当其他人时;

最后一点是关于抽象的兴起,即使对于 RTL 设计也是如此:合成器现在已经非常成熟了。例如,看看 Jiri Gaisler 的 LEON2 开源处理器编码风格,以及他的编码风格 (参见此处)。他采用了一种与经典书籍截然不同但完全有效的方法。

您应该始终了解 RTL 合成器将推断出什么。

相反,行为综合可以让您(部分)忘记合成器将推断出的内容。但那是另一个故事了。

Both coding styles are totally valid.

Let's recall some elements. Starting from HDL, synthesis is done in two main steps :

  1. first, the VHDL is analyzed in order to detect RTL templates (consisting in RTL elements : flip-flops, arithmetic expressions, multiplexers , control logic ). We say that these elements are "infered" (i.e you must code using the right template to get what you wanted initially. You must imagine how these elements are connected, before coding ).
  2. The second step is real logic synthesis, that takes a particular target technology parameters into account (types of gates available, timing, area, power).

These two steps clearly separates RTL functional needs (steering logic, computations) from technology contingencies (timing etc).

Let's come back to the first step (RTL) :

Concerning multiplexers, several coding styles are possible :

  • using concurrent assignement :

    y<= a1 when cond1 else a2 when cond2 else cond3;

  • using if statement within a process :

    process(a1,a2,a3,cond1,cond2)
    begin
    if(cond1) then
    y<=a1;
    elsif(cond2) then
    y<=a2;
    else
    y<=a3;
    end if;
    end;

  • using another concurrent assignment
    form, suitable for generic
    descriptions : if sel is an integer
    and muxin an array of signals, then :

    muxout <= muxin(sel); --will infer a mux

Note that the 3 coding styles always work. Note also that they are "a bit more" than simple multiplexer as the coding style force the presence of a priority encoding (if elsif, when else), which is not the case of a simple equation-based multiplexer, really symmetric.

  • using a case statement

    process(a1,a2,a3,cond1,cond2)
    variable cond : std_logic(1 downto 0);
    begin
    cond := cond2 & cond1;
    case cond is
    when "01" => y<= a1;
    when "10" => y<= a2;
    when others => y<=a3;
    end case;
    end;

  • using a select statement (in our
    example, two concurrent assignements
    needed) :

    sel <= cond2 & cond1;
    WITH sel SELECT
    y <= a1 WHEN "01",
    a2 WHEN "10",
    a3 WHEN OTHERS;

A final remark is about the rising of abstraction, even for RTL design : the synthesizers are now really mature. Have a look at Jiri Gaisler coding styles for LEON2 open source processor for example, as well as his coding styles (see here). He prones a very different approach, yet perfectly valid, from classical books.

You should always understand what the RTL synthesizer will infer.

In the contrary, behavioral synthesis allows you to forget (partially) what the synthesizer will infer. But that's another story.

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