Jump to content

Not getting correct result with sc_time_stamp()


Monc

Recommended Posts

I am trying to print the simulation advanced in the units of attosecond, zeptosecond and yoctosecond, but I am getting 0 second in the print messages. It seems like the simulation timing is round off to second and since the number is small it is printing as 0 second. Can someone guide me how to print the actual timing ?
std::cout << "Time: " << sc_time_stamp() << std::endl; // 
wait(10, SC_AS); // attosecond
std::cout << "Time: " << sc_time_stamp()<< std::endl;
wait(10, SC_US); // zeptosecond
std::cout << "Time: " << sc_simulation_time() << std::endl;
wait(10, SC_YS); // yoctosecond
std::cout << "Time: " << sc_simulation_time() << std::endl;

 

 
Output: 
 
Time: 0 s
Time: 0 s
Time: 0 s
Time: 0 s

 

Link to comment
Share on other sites

You need to set the time resolution down to yoctoseconds: 

sc_set_time_resolution(1.0, SC_YS);

This call needs to be done before any sc_time instance would be generated, e.g., at the top of your sc_main().

The example below yields:

        SystemC 3.0.0-Accellera --- Jun 25 2024 13:14:11

        Copyright (c) 1996-2024 by all Contributors,

        ALL RIGHTS RESERVED

Time initially: 0 s

Time after SC_AS wait: 10 as

Time after SC_ZS wait: 10010 zs

Time after SC_YS wait: 10010010 ys

 

Info: /OSCI/SystemC: Simulation stopped by user.

Program completed

The example:

SC_MODULE(DUT)

{

    SC_CTOR(DUT)

    {   

        SC_THREAD(thread);

    }

    void thread()

    {   

        std::cout << "Time initially: " << sc_time_stamp() << std::endl; //

        wait(10, SC_AS); // attosecond

        std::cout << "Time after SC_AS wait: " << sc_time_stamp()<< std::endl;

        wait(10, SC_ZS); // zeptosecond

        std::cout << "Time after SC_ZS wait: " << sc_time_stamp() << std::endl;

        wait(10, SC_YS); // yoctosecond

        std::cout << "Time after SC_YS wait: " << sc_time_stamp() << std::endl;

        sc_stop();

    }

    sc_in<bool> m_clk;

};

 

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

{

    sc_set_time_resolution(1.0, SC_YS);

    sc_clock        clock("clock");

    DUT             dut("dut");

 

    dut.m_clk(clock);

    sc_start();

 

    cout << "Program completed" << endl;

    return 0;

}

 

 

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.

Guest
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...