Does VHDL have a ternary operator?

为君一笑 提交于 2019-12-05 00:21:40

No. It was discussed for VHDL-2008, but didn't get in. You've got a couple of options. If your tools support VHDL-2008, conditional assignments are now supported as sequential statements (they were previously just concurrent), so you can write something like:

process(clock)
begin
  if rising_edge(clock) then
    q <= '0' when reset else d; -- ie. much like q <= reset? '0':d;
  end if;
end process;

If you haven't got 2008, just write a function (q <= sel(reset, '0', d)). You have to write it for every type you're interested in, though.

Not the one like you know from C/C++ but you can use:

destination <= signal1 when condition else signal2;

In my utility package, I have these 2 function. For me, they're very handy

  function ternu(cond : boolean; res_true, res_false : unsigned) return unsigned is
  begin
     if cond then return res_true;
     else      return res_false;
     end if;
  end function;

  function terni(cond : boolean; res_true, res_false : integer) return integer is
  begin
     if cond then return res_true;
     else      return res_false;
     end if;
  end function;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!