SystemC中定点溢出的自动警告

Automatic warning on fixed point overflow in SystemC

有什么方法可以在定点变量溢出时为我的 SystemC 仿真启用自动警告?

我已经发现了 overflow_flag() 函数,但是每次我在代码中写入信号时都必须手动检查该函数。此外,在我解释文档时,此标志无法区分溢出和精度损失?

Is there a way i can enable an automatic warning for my SystemC simulation whenever a fixed point variable overflows?

不是集中的、标准的方式。

如果您想监控一组固定的 变量,您可以使用某些 SystemC 实现中可用的 sc_fxnum_observer 扩展。

要使用它,您必须 #define SC_ENABLE_OBSERVERS 在包含 SystemC 之前(最好从您的编译器命令行)。这允许您 "attach" 您的 sc_fixed<...>(及相关)类 的观察者,它会在以下事件时收到通知:

class sc_fxnum_observer
{
public:

    virtual void construct( const sc_fxnum& );
    virtual void  destruct( const sc_fxnum& );
    virtual void      read( const sc_fxnum& );
    virtual void     write( const sc_fxnum& );
};

例如,您可以在自定义观察者的 write 函数中检查 overflow_flag

struct overflow_observer : sc_dt::sc_fxnum_observer
{
  virtual void write( const sc_fxnum& v )
  {
    if( v.overflow_flag() )
      // ...
  }
};

构造变量的过程中,您可以将指针传递给观察者,然后:

  overflow_observer my_overflow_observer;
  sc_dt::sc_fixed<...> f( &my_overflow_observer );

对于 信号,最简单的解决方案是派生一个专用信号并检查覆盖的 update 函数中的 overflow 标志。

template <int W, int I,
      sc_q_mode Q = SC_DEFAULT_Q_MODE_,
      sc_o_mode O = SC_DEFAULT_O_MODE_, int N = SC_DEFAULT_N_BITS_>
class fixed_signal : public sc_core::sc_signal< sc_dt::sc_fixed<W,I,Q,O,N> >
{
  typedef sc_core::sc_signal< sc_dt::sc_fixed<W,I,Q,O,N> > base_type;
public:
  // constructor, etc.
  // ...
  using base_type::operator=;
protected:
  void update()
  {
    base_type::update();
    if( read().overflow_flag() )
      // ...
  }
};

Also, as I interpret the documentation, this flag does not discern between overflowing and precision loss?

是的。