1

我在 SystemC 中通过四个 NAND 门的绑定制作了一个异或门。我希望模块接收 N 位向量,其中 N 作为参数传递。我应该能够执行&不是按位运算(对于与非门)。

最好的解决方案可能是使用sc_bv_base类型,但我不知道如何在构造函数中对其进行初始化。

如何使用自定义长度创建位向量?

4

1 回答 1

2

参数化模块的一种方法是为模块创建一个新的 C++ 模板。

在这个例子中,输入向量的宽度可以设置在这个模块的实例化级别

#ifndef MY_XOR_H_
#define MY_XOR_H_

#include <systemc.h>       

template<int depth>
struct my_xor: sc_module {
    sc_in<bool > clk;
    sc_in<sc_uint<depth> > din;
    sc_out<bool > dout;

    void p1() {                                                           
        dout.write(xor_reduce(din.read()));
    }

    SC_CTOR(my_xor) {
        SC_METHOD(p1);
        sensitive << clk.pos();
    }

};
#endif /* MY_XOR_H_ */

请注意,struct my_xor: sc_module使用 isoSC_MODULE宏。(参见IEEE Std 1666-2011SC_MODULE第40 页,5.2.5 )。

您可以使用以下测试平台对此进行测试:

//------------------------------------------------------------------
// Simple Testbench for xor file
//------------------------------------------------------------------

#include <systemc.h>
#include "my_xor.h"

int sc_main(int argc, char* argv[]) {

    const int WIDTH = 8;

    sc_signal<sc_uint<WIDTH> > din;
    sc_signal<bool> dout;

    sc_clock clk("clk", 10, SC_NS, 0.5);   // Create a clock signal

    my_xor<WIDTH> DUT("my_xor");           // Instantiate Device Under Test

    DUT.din(din);                          // Connect ports
    DUT.dout(dout);
    DUT.clk(clk);

    sc_trace_file *fp;                  // Create VCD file
    fp = sc_create_vcd_trace_file("wave");     // open(fp), create wave.vcd file
    fp->set_time_unit(100, SC_PS);      // set tracing resolution to ns
    sc_trace(fp, clk, "clk");             // Add signals to trace file
    sc_trace(fp, din, "din");
    sc_trace(fp, dout, "dout");

    sc_start(31, SC_NS);                // Run simulation
    din = 0x00;
    sc_start(31, SC_NS);                // Run simulation
    din = 0x01;
    sc_start(31, SC_NS);                // Run simulation
    din = 0xFF;
    sc_start(31, SC_NS);                // Run simulation

    sc_close_vcd_trace_file(fp);        // close(fp)

    return 0;
}

请注意,我使用的是 astruct而不是 a class。Aclass也是可以的。

class my_xor: public sc_module{
public:

此代码中的 XOR 只是xor_reduce. 您可以在第 197 页的IEEE Std 1666-2011中找到更多信息(7.2.8 归约运算符)。但我认为这不是您想要的解决方案。

于 2013-07-22T12:22:19.363 回答