Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Function with args of which type is interface #961

Open
taichi-ishitani opened this issue Sep 12, 2024 · 1 comment
Open

[Feature] Function with args of which type is interface #961

taichi-ishitani opened this issue Sep 12, 2024 · 1 comment
Labels
lang Language design

Comments

@taichi-ishitani
Copy link
Contributor

考えがちゃんとまとまっていないので、日本語で。

virtual function であれば関数の引数にすることとができるが、それでは RTL 中で使えない。

  • 合成できるか不明
  • always_comb とかで使う際に、イベントを推定できない(と思う)

Veryl 上で、interface を引数に取る関数を定義した場合、SV に出力する際に interface 中の各信号を引数に取る関数定義に書き換えてやればよい。

例えば、以下のようなコードの場合、

interface foo_if #(
  param WIDTH: u32 = 8.
){
  var ready: logic;
  var valid: logic;
  var data: logic<WIDTH>;

  modport master {
    ready: input,
    valid: output,
    data:  output
  }

  modport slave {
    ready: output,
    valid: input,
    data:  input,
  }
}

function connect_foo_if (
    slave_if:  modport foo_if#(WIDTH)::slave,
    master_if: modport foo_if#(WIDTH)::master,
) {
  slave_if.ready  = master_if.ready;
  master_if.valid = slave_if.valid;
  master_if.data  = slave_if.data;
}

always_comb {
  connect_foo_if(slave_if, master_if);
}

出力はこのようなる。

function void connect_foo_if (
  output logic             slave_if_ready,
  input  logic             slave_if_valid,
  input  logic [WIDTH-1:0] slave_if_data,
  input  logic             master_if_ready,
  output logic             master_if_valid,
  output logic [WIDTH-1:]  master_if_data
);
  // 省略
endfunction

always_comb begin
  connect_foo_if(slave_if.ready, slave_if.valid, slave_if.data, ..);
end
@dalance dalance added the lang Language design label Sep 12, 2024
@taichi-ishitani
Copy link
Contributor Author

引数を展開する際に、幅を決める必要があるので、interface がパラメータを取る場合は、関数定義の際にパラメータを指定してやる必要がある。
また、入出力を決めるために、modport の指定は必須で、素の interface は引数に取れない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang Language design
Projects
None yet
Development

No branches or pull requests

2 participants