• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. C++ Object life cycle through SV DPI

Stats

  • Locked Locked
  • Replies 11
  • Subscribers 64
  • Views 18973
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C++ Object life cycle through SV DPI

archive
archive over 18 years ago

Hi all,

I have a C++ Object life cycle through SV DPI problem.

For example, I have a C++ reference model class named ALU.  Only one public function revealed to client (e.g. ALU::ALU_EXEC) and was encapsulated in DPI(ALU_EXEC_DPI) . And there are two types of ALU commands was entered to ALU::ALU_EXEC. One is setup ALU parameters (i.e. setup the ALU class private member) , the other is calculating the result.
 
The question is when I leave DPI, the ALU object is eliminated and all the setup parameter is cleared, right? So can I keep a C++ Object even after I leave DPI (i.e. is the C++ Object life cycle only as long as DPI call life cycle).

My friend suggest me to return all the ALU parameter out to SV and re-enter these parameters to ALU through ALU_EXEC_DPI when I call the ALU reference model. But it may break the model encapsulation :(

May be my question is not very clear and any suggestions are welcome!
Davy




Originally posted in cdnusers.org by davyzhu
  • Cancel
Parents
  • archive
    archive over 18 years ago

    Ok,

    Now, do not use the task. Use function instead.

    You will have one more input to your input argument list, e.g. status.

    //---SV file
    import “DPI-C” context alu_run = function int alu_run(...);
    always @(status)
    alu_run(clk, opcode,a, b, result,$realtime, status);
    //---

    Now, untill and unless you pass status value '2' the C++ shouldn't exit. This way the C++ would be alive and you can continue the simulation. At the time you want to exit, pass the value '2' to the C++. For the normal sim, you can pass the value '1'.

    Also, i would like to suggest you to use two tasks for "constructor" and "destructor" and a function for the alu_run. But one thing is clear that even you are out of the alu_run function the values would still be retained, unless you enter it again and initialize the same.

    I guess, i am showing you the right path.

    -Vivek


    Originally posted in cdnusers.org by prasad_vc
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 18 years ago

    Ok,

    Now, do not use the task. Use function instead.

    You will have one more input to your input argument list, e.g. status.

    //---SV file
    import “DPI-C” context alu_run = function int alu_run(...);
    always @(status)
    alu_run(clk, opcode,a, b, result,$realtime, status);
    //---

    Now, untill and unless you pass status value '2' the C++ shouldn't exit. This way the C++ would be alive and you can continue the simulation. At the time you want to exit, pass the value '2' to the C++. For the normal sim, you can pass the value '1'.

    Also, i would like to suggest you to use two tasks for "constructor" and "destructor" and a function for the alu_run. But one thing is clear that even you are out of the alu_run function the values would still be retained, unless you enter it again and initialize the same.

    I guess, i am showing you the right path.

    -Vivek


    Originally posted in cdnusers.org by prasad_vc
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information