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

Vivado shortrealtobits & bitstoshortreal

Jump to solution

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

 

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
1 Solution

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

Re: Vivado shortrealtobits & bitstoshortreal

Jump to solution

Hi,

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

It should fix your issue.

 

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

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.

View solution in original post

0 Kudos
3 Replies
Highlighted
Moderator
Moderator
6,025 Views
Registered: ‎04-17-2011

Re: Vivado shortrealtobits & bitstoshortreal

Jump to solution
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)
http://www.xilinx.com/support/documentation/sw_manuals/xilinx2014_2/ug900-vivado-logic-simulation.pdf
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

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

Re: Vivado shortrealtobits & bitstoshortreal

Jump to solution
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.
0 Kudos
Highlighted
Teacher
Teacher
9,058 Views
Registered: ‎03-31-2012

Re: Vivado shortrealtobits & bitstoshortreal

Jump to solution

Hi,

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

It should fix your issue.

 

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

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.

View solution in original post

0 Kudos