bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Displaying Floating Point, Runtime Values in Decimal

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
caclark



Joined: 09 Dec 2015
Posts: 2

PostPosted: Wed Jan 06, 2016 1:34 pm    Post subject: Displaying Floating Point, Runtime Values in Decimal Reply with quote

For debugging purposes, I would like to output some floating point values to the console in decimal form. Is there any way to do that? I haven't been able to find one.
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Wed Jan 06, 2016 2:34 pm    Post subject: Re: Displaying Floating Point, Runtime Values in Decimal Reply with quote

When you say 'floating point', what type are you specifically referring to? The built-in type 'Real' can be printed with $display and any of the floating point format codes. But I assume that you mean the FloatingPoint type defined in the FloatingPoint package in the BSC libraries? That package only defines FShow, which prints the components of the struct. There does not appear to be a function that will print it as a user-friendly number.

If your FloatingPoint sizes match the IEEE 754 double-precision (64-bit) floating point format, then I suspect that you can pack it to Bit#(64) and use the $bitstoreal system function to convert it to Real, and then use $display to print it. (If your parameters do not match IEEE 754, you could use the 'convert' function to convert to that format, for displaying.)

Alternatively, you could write your own function for displaying the value, based on the FShow instance. The source code is in the release, but I'll repeat it here:
Code:
function Fmt fshow( FloatingPoint#(e,m) value );
  return $format("<Float %s%x.%x>", value.sign ? "-" : "+", value.exp, value.sfd);
endfunction

Your function could display in different syntax depending on the exponent:
Code:
function Fmt showFP ( FloatingPoint#(e,m) value );
  String s = (value.sign ? "-" : "");
  if (value.exp > ...)
    return $format("%s%de%d", s, value.sfd, value.exp);
  else begin
    let integer_part = ...;
    let fraction_part = ...;
    return $format("%s%d.%d", s, integer_part, fraction_part);
  end
endfunction
Back to top
View user's profile Send private message
caclark



Joined: 09 Dec 2015
Posts: 2

PostPosted: Wed Jan 06, 2016 6:31 pm    Post subject: Reply with quote

Thanks for the help.

Yes, I do mean the floating point type in the FloatingPoint BSC library.

Your suggestion about using $bitstoreal was actually the first thing that I tried, which I should have mentioned. When I did that, BSC ate all of my available RAM, and did not complete compilation. I found some information somewhere (can't remember where) that said that Reals could only be used for compile time constants. Do you know if that is correct?
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Wed Jan 06, 2016 7:09 pm    Post subject: Reply with quote

Real is a compile-time type, similar to how Integer is a compile-time type. Integer is an unbounded type, so there's a theoretical restriction why it can't be stored in fixed-size state; for Real, the issue is less about the encoding in Bits and more about whether the operations on it have a hardware-time implementation (or only a compile-time implementation). If an operation is only compile-time, that means it can only be applied to a constant. BSC often gives an error if you try to apply a compile-time operator to a dynamic value; but for some compile-time operations, BSC will apply optimizations to try to move the operation into the arms of dynamic expressions, hoping to find constants there that the operation can be applied to (and reduce away). If BSC ran forever on your code, it was probably because it was trying this optimization and not making progress. Looking at the implementation for $bitstoreal, I do see that it only has a compile-time implementation. There is no theoretical reason why this system function cannot have a hardware-time implementation (by using $bitstoreal in the generated Verilog), and in fact we're working on hardware-time support for the Real type (and its operators).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP