- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This feels like it should be a stupid question but does quartus do something strange when compiling if statements using signed signals? As an example, I have some code in the following form:
typedef logic signed [ 3:0] Int4_t;
Int4_t testValue;
...
if (testValue <= 0)
//Do the negative branch
else
//Do the positive branch
Modelsim behaves as I'd expect with this but then the design behaves as if the testValue is always unsigned in hardware so does the wrong thing. Obviously the work around is to just manually do a check of bit 3 but this seems like a weird behaviour to me...
Thanks,
Andy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So after digging through the LRM, it looks like Quartus is actually doing the correct thing per the spec (however I maintain that Modelsim is doing the correct thing per common sense). File it away as a nasty gotcha I guess....
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, should also say (in case it makes a difference) that this is Quartus Prime Pro 16.1, compiling for SystemVerilog, running on Windows 10.
Andy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With only a snippet, cant really comment.
Can you post more code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That may be coz you've used integer values in the if statement. When you use integers, Quartus will treat it as unsigned 32 bit integers during synthesis and truncate the unused bits. I say try specifying the bit values in the if condition
if ( signal < 4'b0000)
else
...
Using the signed values for comparison will or should yield the correct results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure that that would help though - my understanding was that int 0 is effectively the same as 32'd0, no? So surely a comparison to 0 or a comparison to 4'b0000 would behave in the same way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this:
module test
(
input signed [3:0] a,
output eq,
output gt,
output lt
);
localparam x = 4'sb1101; // neg 3
assign eq = (a == x) ? 1'b1:1'b0;
assign gt = (a > x) ? 1'b1:1'b0;
assign lt = (a < x) ? 1'b1:1'b0;
endmodule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just to be clear - I'm really not actually looking for a fix to the code (I've done that by just manually doing a check on the sign bit). I'm just very confused why the Quartus compiler is doing something fundamentally different than the Modelsim compiler. Obviously one of them is doing the correct thing and the other isn't....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So after digging through the LRM, it looks like Quartus is actually doing the correct thing per the spec (however I maintain that Modelsim is doing the correct thing per common sense). File it away as a nasty gotcha I guess....

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page