cancel
Showing results for
Did you mean:
Highlighted
Teacher
6,043 Views
Registered: ‎03-31-2012

It seems that Vivado SV simulator doesn't support these two system functions. I quickly wrote replacements. In case they are helpful for others I am attaching them here. Use at your own risk; no guarantees, waranties etc. etc. etc.

```function shortreal bitstoshortreal;
input logic [31:0] bits;

logic sign;
logic [7:0] exp;
logic [22:0] frac;

sign = bits[31];
exp  = bits[30:23];
frac = bits[22: 0];

bitstoshortreal = {1'b1, frac};
bitstoshortreal = bitstoshortreal / 8388608.0;
if (exp >= 8'h7F) begin
exp  = bits[30:23] - 8'h7F;
bitstoshortreal = bitstoshortreal * (1 << exp);
end
else begin
exp = 8'h7F - bits[30:23];
bitstoshortreal = bitstoshortreal / (1 << exp);
end

return sign ? -1 * bitstoshortreal : bitstoshortreal;
endfunction

function logic [31:0] shortrealtobits;
input shortreal r;

logic sign;
integer iexp;
logic [7:0] exp;
logic [22:0] frac;
shortreal temp, ffrac;

sign = 1 ? r < 0 : 0;
temp = sign ? -1*r : r;
iexp  = \$floor(\$ln(temp) / \$ln(2));
ffrac = temp / \$pow(2, iexp);
ffrac = ffrac - 1;
frac = ffrac * 8388608.0;
exp = 127 + iexp;

shortrealtobits = {sign, exp, frac};
endfunction```

Give Kudos to a post which you think is helpful and reply oriented.
1 Solution

Accepted Solutions
Highlighted
Teacher
9,057 Views
Registered: ‎03-31-2012

## Re: Vivado shortrealtobits & bitstoshortreal

Hi,

I have made some changes and pushed the code to github here: https://github.com/muzafferkal/shortreal

It's been a while since I needed this code. I moved to VCS soon after this post.

Give Kudos to a post which you think is helpful and reply oriented.
3 Replies
Highlighted
Moderator
6,025 Views
Registered: ‎04-17-2011

## Re: Vivado shortrealtobits & bitstoshortreal

Thanks for posting this.
For other visitors the list of SV constructs currently supported by Vivado Simulator 2014.2 are listed in table D-1 (Page 177)
Regards,
Debraj
----------------------------------------------------------------------------------------------

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
Highlighted
Explorer
4,927 Views
Registered: ‎02-16-2014

## Re: Vivado shortrealtobits & bitstoshortreal

muzaffer, your version of \$shortrealtobits converts float "0.0" to 1. I understand its a special case along with +/- infinity and NaN. I wrote my own conversion functions, but looking for something I can trust, something standard. You wrote this post a year ago. What do you use today? Do you have an updated version of such functions? Best regards.
Highlighted
Teacher
9,058 Views
Registered: ‎03-31-2012