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

Subscripting of a function return value. #372

Open
zhuanhao-wu opened this issue Oct 24, 2022 · 0 comments
Open

Subscripting of a function return value. #372

zhuanhao-wu opened this issue Oct 24, 2022 · 0 comments
Labels

Comments

@zhuanhao-wu
Copy link
Collaborator

Code in SystemC may exhibit the following pattern (see here), where the returned value is indexed.

bhdr.set_zb(!(get_window(b_wrk,w_wordoff) [0]));

Currently, the generated SystemVerilog code is as follows.
The code will work under simulation but will not work for synthesis.

zhw__block_headerfp_t11_52__set_zb_func_4(
	bhdr_ms_proc_local_10_zb__ref_0,bhdr_ms_proc_local_10_exp__ref_0,
	!(zhw__get_window_func_3(
			b_wrk_ms_proc_local_6_f__ref_0,
			b_wrk_ms_proc_local_6_w__ref_0,
			w_wordoff_ms_proc_local_8,
			b_wrk_ms_proc_local_6_f__ref_0,
			b_wrk_ms_proc_local_6_w__ref_0
		)[(0)]
	),
	bhdr_ms_proc_local_10_zb__ref_0,
	bhdr_ms_proc_local_10_exp__ref_0
);

One tentative solution is to generate a local variable that holds the function return value.

logic res;
// ...
res = zhw__get_window_func_3(
			b_wrk_ms_proc_local_6_f__ref_0,
			b_wrk_ms_proc_local_6_w__ref_0,
			w_wordoff_ms_proc_local_8,
			b_wrk_ms_proc_local_6_f__ref_0,
			b_wrk_ms_proc_local_6_w__ref_0
		);

zhw__block_headerfp_t11_52__set_zb_func_4(
	bhdr_ms_proc_local_10_zb__ref_0,bhdr_ms_proc_local_10_exp__ref_0,
	!res[(0)],
	bhdr_ms_proc_local_10_zb__ref_0,
	bhdr_ms_proc_local_10_exp__ref_0
);

However, this is not general enough. For example, if we have func1_call()[0] || func2_call()[1], due to short circuit evaluation, func2_call[1] may not be executed. Hence, func2_call()[1] should be guarded by the result of the first condition to avoid any side effects in func2_call().
The most general way would be to expand all logical expressions and explicitly embed the short-circuit evaluation semantics.

logic[7:0] res1, res2;
res1= func1_call();
if(!res1) begin
  res2= func2_call();
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant