OpenCores
no use no use 1/1 no use no use
VHDL efficiency question
by kilianhekhuis on May 2, 2020
kilianhekhuis
Posts: 3
Joined: Feb 28, 2013
Last seen: Apr 3, 2024
Hi, I'm coming from a software background and understand the way compilers produce assembly from a high-level language. But not so for VHDL. I therefore often do not know what VHDL to write that's most efficient. For example, I'm currently creating a graphics card with VGA output, and in 1bpp mode, I want to output white if the bit is set, and black otherwise. I came up with two different approaches (the DAC has 4 bits per RGB). First:
	o_video_r <= s_attr(0) & s_attr(0) & s_attr(0) & s_attr(0);
	o_video_g <= s_attr(0) & s_attr(0) & s_attr(0) & s_attr(0);
	o_video_b <= s_attr(0) & s_attr(0) & s_attr(0) & s_attr(0);
Second:
	if s_attr(0) = '0' then
		o_video_r <= "0000";
		o_video_g <= "0000";
		o_video_b <= "0000";
	else
		o_video_r <= "1111";
		o_video_g <= "1111";
		o_video_b <= "1111";
	end if;

So what would be considered the "best" code? Also are there a bunch of guidelines for writing VHDL to be found somewhere that focusses on best-practices?

RE: VHDL efficiency question
by hno on Jun 16, 2020
hno
Posts: 7
Joined: Dec 17, 2012
Last seen: Oct 4, 2021
I would go for the second. The difference in efficiency is minimal if any, and the second is much more visible on what the purpose of the design is and makes it trivial to change the values if you want it to map to any other values.
no use no use 1/1 no use no use
© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.