Code VHDL - [expand] 1 2 3 4 5 6 7 8 [code] signal d : signed( 31 downto 0 ); signal a:signed (15 downto 0); signal b :signed (15 downto 0); signal p:signed (15 downto 0); ........... d<=(a+b)*p; [/code]
Code Verilog - [expand] 1 2 3 4 5 6 [code] wire signed[15:0]a,b,p; wire signed[31:0]d; ........ assign d=(a+b)*p; [/code]
signal d : signed(32 downto 0);
d <= ( resize(a, 17) + resize(b, 17) ) * p;
The difference between VHDL and Verilog is that Verilog uses context-determined expression bit length in some cases. I'm not quite sure how it works in a composite expression like the present, apparently the left-hand side bit length is affecting the evaluation of the inner term. See Std 1800, Paragraph 11.6 Expression bit lengthsIIRC, Verilog does length extension automatically when you do addition or subtraction.
The difference between VHDL and Verilog is that Verilog uses context-determined expression bit length in some cases. I'm not quite sure how it works in a composite expression like the present, apparently the left-hand side bit length is affecting the evaluation of the inner term
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 entity sim_vhd is Port ( a : in signed (15 downto 0); b : in signed (31 downto 0); c : out signed (15 downto 0)); end sim_vhd; architecture Behavioral of sim_vhd is begin c<= resize ((a+b/2**5),16); end Behavioral;
Code Verilog - [expand] 1 2 3 4 5 6 7 8 module sim_ver( input signed[15:0] a, input signed[31:0] b, output signed[15:0] c ); assign c=(a+b/2**5); endmodule
architecture Behavioral of sim_vhd is
signal t:signed (31 downto 0);
begin
t<= (a+b/2**5);
c<=t(15 downto 0);
end Behavioral;
c<= (a+b(15 downto 0)/2**5);
assign c=a + (b>>>5)
//when i used above expression the fallowing warning comes
//Result of 28-bit expression is truncated to fit in 16-bit target
Thanks for your interest.....when i used shift_right function in vhdl code is synthesized to 32 bit adder only (i got rid off 27 bit adder).Similarly when i used arithmetic shift operator in verilog code is synthesized to 32 bit adder only.I came to know that /(division operator) is expensive in resource utilization than shifting operator..but still i have a doubt in verilog code
why not expression length 32 bits according to context determined expression rules...Code:assign c=a + (b>>>5) //when i used above expression the fallowing warning comes //Result of 28-bit expression is truncated to fit in 16-bit target
I got your point.Initially i thought that according this statement in ieee reference manual The arithmetic right shift shall fill the vacated bit positions with zeroes if the result type is unsigned.It shall fill the vacated bit positions with the value of the most-significant (i.e., sign) bit of the left operand if the result type is signed. I think After filling with sign bit,it is discarding that many number of bits.For a signed number it would give the same meaning(like if -2 can be 1110 for 4 bit,111110 for 6bit are same..etc).For a curiosity i just changed arithmetic shift to logical shift then bit expression length become 29 bits.logical shift fills with 0 which make the number unsigned ,32 bit being reduced to 28 bits(it is preserving only one extra 0 to indicate it is a unsigned number) then + results in 29 bit result.Am i thinking in the right direction?(b>>>5) results in a 32-bit being reduced to 27-bit then the + results in a 28-bit result. Nothing odd about the way Verilog handles this.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?