Skip to content

Instantly share code, notes, and snippets.

@taichi-ishitani
Created October 20, 2019 14:34
Show Gist options
  • Save taichi-ishitani/cec6acc29ec3c1801590d49c1cd91753 to your computer and use it in GitHub Desktop.
Save taichi-ishitani/cec6acc29ec3c1801590d49c1cd91753 to your computer and use it in GitHub Desktop.
module top (
input logic [1:0] i_a,
input logic [1:0] i_b,
output logic [1:0] o_c
);
function automatic logic [1:0] add();
return i_a + i_b;
endfunction
always_comb begin
o_c = add();
end
endmodule
@taichi-ishitani
Copy link
Author

普通の always の場合、always 文中で直接参照されている信号の変化のタイミングでしか、always 文が評価されない。

always @* begin
  o_c = add();
end

上記の場合、直接参照している信号がないので、上記の always 文は一切評価されない。
よって、合成とシミュレーションで不一致が出てしまう。

しかし、always_comb の場合、function で使用している信号の変化のタイミングでも評価される。
上記の場合だと、i_a/i_b が変化すれば、o_d = add() が実行される。
なので、合成とシミュレーションで不一致が起きない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment