Jump to content

How to use range() with sc_signal?


Recommended Posts

Below is a snippet of the stimulus I am giving to my design. I want all of the assignments to be non-blocking and so I have declared everything as sc_signal. However, the problem arises with the need to use range()

Here ACC, B and Y use range(). Since range() cannot be used with sc_signal, I used a copy of them as a sc_bv. I think because of this, the statements are becoming blocking assignments in between and these signals are always 0 in my waveform.

Please suggest ways to deal with this problem.


    sc_signal<sc_bv<M> >A;
    sc_signal<sc_bv<M> >B;
    sc_signal<sc_bv<1<<M> > FUNC;
    constexpr static int size = ceil(log2(M));
    sc_signal<sc_uint<size> > FUNC_ADDR;
    sc_signal<sc_bv<N> > LOAD_CORE;

    constexpr static int size_addr = ceil(log2(2*(N-1)));
    sc_signal<sc_bv<N*size_addr> > AIN_ADDR;
    sc_signal<sc_bv<N*size_addr> > BIN_ADDR;

    sc_signal<sc_bv<2*N> > SRC_MODE;
    sc_signal<sc_bv<2*N> > IN_MODE;

    sc_signal<sc_bv<N> > RUN;
    //sc_clock clk("clock", 6, SC_NS);
    //sc_signal<bool> clk;
    sc_in_clk clk;
    sc_signal<bool> reset;
    constexpr static int size_y_addr = ceil(log2(N));
    sc_signal<sc_bv<size_y_addr> > Y_ADDR;
    sc_signal<sc_bv<M> > Y;
    sc_signal <sc_bv<16> > Accumulator;

    sc_bv<16> ACC = 0;
    sc_bv<M> B_copy;









                B_copy = B.read();
                B_copy.range(3,0) = ACC.range(3,0);

                Y_copy = Y.read();
                B_copy.range(3,0) = ACC.range(7,4);

                  B_copy.range(3,0) = ACC.range(11,8);

                Y_copy = Y.read();
                ACC.range(7,4) = Y_copy.range(3,0);
                B_copy.range(3,0) = ACC.range(15,12);


                wait(clk.posedge_event()); //7
                  ACC.range(11,8) = Y_copy.range(3,0);


                  ACC.range(15,12) = Y_copy.range(3,0);


Link to comment
Share on other sites

SystemC has no comcept of blocking or non-blocking assignments. If you write to a signal you write to the signal immediatly and the result becomes visible in the next delta cycle.

So you parts like

Y_copy = Y.read();
ACC.range(7,4) = Y_copy.range(3,0);

are correct. You may shortern this to

ACC.range(7,4) = Y.read().range(3,0);

So you may have an issue in other parts of your code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...