Jump to content
sc_fox

How to output float from sc_fixed type class, using sc_trace?

Recommended Posts

How to output "float (double)" from sc_fixed type class using sc_trace?

 

I have an existing model (all in floating point design, using "sc_signal<double>"), and am trying to convert it to its fixed point one (i.e. using sc_signal<sc_fixed< ,,,, > >").

 

sc_signal<double> ch_a;

sc_signal<sc_fixed<16,8, SC_RND, SC_SAT> > ch_a_fix;

 

sc_trace(tf,  ch_a, "ch_a" );  // floating point channel tracing, it traces signal in "double".

sc_trace(tf,  ch_a_fix, "ch_a_fix );  // fixed point channel tracing: it traces signal in "integer numbers".

 

The question is, how can I trace the sc_fixed type class (sc_signal<sc_fixed<...:> >) in floating point numbers?

For waveform viewer-wise, I'm using gtkwave for now.

 

I have found one posting that has the same question that I have now. But it doesn't have any replies there.

 

 

http://www.accellera.org/Discussion_Forums/helpforum/archive/msg/msg?list_name=help_forum&monthdir=200802&msg=msg00035.html

 

 

Many thanks in advance.

Share this post


Link to post
Share on other sites

I'm afraid there is no builtin way to do this. You can't just trace the value returned from ch_a_fix.to_double() as this is returned as a temporary double (and you can only trace persistent objects).

You may need to use a helper process doing the translation. Something like (untested):

  double ch_a_fix_tr;
  void update_ch_a_fix() {
    ch_a_fix_tr = ch_a_fix.to_double();
  }
  // in constructor ...
  SC_METHOD(update_ch_a_fix);
    sensitive << ch_a_fix;
and then trace ch_a_fix_tr instead.

Of course, you can wrap all of this in a helper class and implement your own sc_trace_fixed_as_double function based on it.

hth,

Philipp

Share this post


Link to post
Share on other sites

Thank you, Philipp, for your answer. I appreciate it.

 

Just one more thing,

 

Because "ch_a_fix" is "channel" defined as:

sc_signal<sc_fixed<...> > ch_a_fix;

 

"sc_signal" class doesn't have "to_double()" as its member function. So I had compile error with the code in your message.

So I have modified your code slightly as follows:

 

 

double ch_a_fix_tr;
void update_ch_a_fix() {
  ch_a_fix_tr = ch_a_fix.read().to_double();  // just added sc_signal<T>.read(), to get the value.
}
// in constructor ...
SC_METHOD(update_ch_a_fix);
sensitive << ch_a_fix;

 

 

I'm not sure if that is the right way to do, but it looks working. 

 

Philipp, do you have any comments on this?

Thanks, again.

Share this post


Link to post
Share on other sites

"sc_signal" class doesn't have "to_double()" as its member function. So I had compile error with the code in your message.

... 

  ch_a_fix_tr = ch_a_fix.read().to_double();  // just added sc_signal<T>.read(), to get the value.

Your solution is correct. That's why my example said "untested". Sorry.

/Philipp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×