T
TJ Edmister
Guest
Greetings, I have a question about usage of $signed in verilog 2001. I had
thought this could be used for sign extension and I employed it in various
places in my design. But when I simulate with Icarus verilog I find that
it is not doing the sign extension.
cpupc <= cpupc + $signed({branchloc2, 1'b0});
cpupc is a 32-bit value and I wanted the branch offset (which is 10 bits
plus a 0 bit to make it even) to be sign extended so I can branch backward
as well as forward...
Since this failed in the simulation, I replaced that code with this "old"
way of doing sign extension, and this one does work:
cpupc <= cpupc + {{21{branchloc2[9]}}, branchloc2, 1'b0};
I don't like the look of this one quite as much, is it the only way to do
sign extension? How is $signed supposed to be used?
thought this could be used for sign extension and I employed it in various
places in my design. But when I simulate with Icarus verilog I find that
it is not doing the sign extension.
cpupc <= cpupc + $signed({branchloc2, 1'b0});
cpupc is a 32-bit value and I wanted the branch offset (which is 10 bits
plus a 0 bit to make it even) to be sign extended so I can branch backward
as well as forward...
Since this failed in the simulation, I replaced that code with this "old"
way of doing sign extension, and this one does work:
cpupc <= cpupc + {{21{branchloc2[9]}}, branchloc2, 1'b0};
I don't like the look of this one quite as much, is it the only way to do
sign extension? How is $signed supposed to be used?