Shop OBEX P1 Docs P2 Docs Learn Events
simulate P1 with SystemC — Parallax Forums

simulate P1 with SystemC

ReinhardReinhard Posts: 489
edited 2014-08-20 06:34 in Propeller 1
For years I was looking for a larger project to go into SystemC.
Now I have found one;-)

Verilator is an open source software and translated
Verilog by SystemC.
verilator --sc * .v

Thus, one can from the Verilog modules make an executable file.
SystemC files can be re-compiled and synthesized with Verilog or VHDL.

Possibly can anyone enthusiastic about this idea.
Primarily it is intended for learning purposes.

Thank Parallax

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-08-12 01:56
    What a great idea. With P1 translated to C++ just add a GUI for an accurate Propeller simulator for debugging Spin and other code on the PC.

    Compile that into JavaScript with Emscripten and we can run the P1 in the web browser!

    As we already have a Spin IDE running in the browser being able to add a simulator would be great.
  • ReinhardReinhard Posts: 489
    edited 2014-08-12 03:06
    Heater, just something like I have imagined.
    But until then, there is still a long, hard road.
    Right now all I can v-files individually translate
    and get the h and cpp files.
    During compilation of the top files <top.tdf ??> I get error messages.
    Tonight I'm going to have verilator man-pages read accurately;-)
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2014-08-12 04:27
    Reading SystemC now... http://en.wikipedia.org/wiki/SystemC

    Ok, that looks a great idea.

    There probably is a clever way of getting everything to work in parallel. eg in vhdl or Verilog, lots of processes are synchronised to a clock transition. So the clock changes, and other things change, but then they stop changing until a clock changes again. I don't know how systemC solves that. Maybe you go through all the things that change on a clock change and do them one at a time. They tend to be encapsulated in processes. I'm probably not making much sense - in my defence I just spent a whole day coding in vhdl. But I can see how it could be done in something like systemC, and it would be fantastic to get a propeller emulation working in this way.

    I don't know about getting it to run at 80Mhz on javascript though...
  • Heater.Heater. Posts: 21,230
    edited 2014-08-12 06:33
    Dr_A,
    I don't know about getting it to run at 80Mhz on javascript though...
    As far as I can tell Verilator translates Verilog into C++ or SystemC (Which is C++ anyway) which you can then compile and run as a normal executable on your PC. I would be surprised if it can get anywhere near the real speed of a Propeller even if you do have an 8 core 4GH Intel box.

    You would be surprised at the speed of C/C++ compiled to JavaScript and run under the JS engines in Firefox or Chrome. Some examples approach half the speed of natively compiled code on the same machine. The OpenSpin compiler, C++, is plenty fast enough to be usable when compiled to JS.

    If Verilator translated code can make use of multiple cores though JS will have a hard time keeping up as there is no easy way to use more than a single core.

    Still, for a simulator to help with debugging it might still be if use even if it is slow. Sounds like it's going to happen anyway :)



  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2014-08-12 07:54
    Dr_Acula wrote: »
    Reading SystemC now... http://en.wikipedia.org/wiki/SystemC

    Ok, that looks a great idea.

    There probably is a clever way of getting everything to work in parallel. eg in vhdl or Verilog, lots of processes are synchronised to a clock transition. So the clock changes, and other things change, but then they stop changing until a clock changes again. I don't know how systemC solves that. Maybe you go through all the things that change on a clock change and do them one at a time. They tend to be encapsulated in processes. I'm

    probably not making much sense - in my defence I just spent a whole day coding in vhdl. But I can see how it could be done in something like systemC, and it would be fantastic to get a propeller emulation working in this way.

    I don't know about getting it to run at 80Mhz on javascript though...

    re:I don't know about getting it to run at 80Mhz on javascript though

    Maybe:

    asm.js
    is an intermediate programming language consisting of a strict subset of the JavaScript language. It enables significant performance improvements for web applications which are written in statically-typed languages with manual memory management (such as C) and then translated to JavaScript by a source-to-source compiler. Asm.js does not aim to improve the performance of hand-written JavaScript code, nor does it enable anything other than enhanced performance.

    http://en.wikipedia.org/wiki/Asm.js
  • KMyersKMyers Posts: 433
    edited 2014-08-12 10:19
    To show my lack of programming knowledge and skills what is the difference between C++ and Java??:frown:
  • mklrobomklrobo Posts: 420
    edited 2014-08-12 10:39
    :smile: Awesome Idea! I will help you with this, if possible. I needed this emulator for my linux OS.
  • ReinhardReinhard Posts: 489
    edited 2014-08-12 11:10
    1; download SystemC
    With a bit of C / C ++ experience the training period is a few days.

    2; The bottleneck;-(
    download verilator
    Either the classic way:
    ./configure
    make
    make install

    or verilator is in your distribution.

    Unfortunately my verilog translation -> SystemC is not yet
    successful.
  • Heater.Heater. Posts: 21,230
    edited 2014-08-12 12:55
    KMyers,
    ...what is the difference between C++ and Java??
    Oh I love this question:


    C++ is a big and complicated language, derived from C, that no human being will ever live long enough to fully comprehend. It enables object oriented programming if you like. It enables template meta programming if you like. It generally compiles down to native machine code that can give you slim and fast executables and give you as much control of your hardware as a high level language can.


    Java is a big and complicated language, sort of derived from C++, that no human being will ever live long enough to fully understand. It totally insists on the brain dead paradigm of object oriented programming for everything. It generally compiles down to byte codes which then have to be interpreted by some huge and slow virtual machine. It keeps you as far away as possible from control of your machine as a high level language can.


    Not only that. On top of all the inconvenience of Java it has no reason to exist at all. It brings no interesting or useful features to the programming language world.

    Not only that but Java was supposed to be "Write once run anywhere", however it does not run on most machines of interest unlike C++. Java is totally pointless.


    Oh, sorry I forgot to put this at the top "WARNING Language War imminent."


    By the way, who mentioned Java here? There was mention of JavaScript which is a much more interesting and sophisticated language than Java can ever imagine. Which also happens to be more cross platform than Java as a bonus.
  • KMyersKMyers Posts: 433
    edited 2014-08-12 13:34
    Thanks Heater! I can always count on you to set me right:lol:


    Yes I did mean Java Script. Didn't realize there was a difference. Guess I should stick to art and coax but my afpga board just arrived so the learning may start!!:innocent:

    PS got the files downloaded and extracted. Heaven help me...
  • __red____red__ Posts: 470
    edited 2014-08-12 14:11
    Why they called javascript "Java"script is beyond me. It was a misunderstanding waiting to happen.
  • KyeKye Posts: 2,200
    edited 2014-08-12 14:29
    C++ ---> =(

    Qt(C++) ---> =)
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2014-08-12 14:41
    __red__ wrote: »
    Why they called javascript "Java"script is beyond me. It was a misunderstanding waiting to happen.

    Here's the official reason.


    Brendan Eich created JavaScript in 1995 with the aim to provide a "glue language" for Web designers and part time programmers

    Why was JS originally named Mocha and then LiveScript?


    Mocha was Marc Andreessen's code name, but Netscape marketing saw potential trademark conflicts and did not prefer it on other grounds. They had a "live" meme going in their naming (LiveWire, LiveScript, etc.). But the Java momentum of the time (1995-1996) swept these before it.

    http://www.computerworld.com.au/article/255293/a-z_programming_languages_javascript/
  • KMyersKMyers Posts: 433
    edited 2014-08-12 14:51
    Interesting info. Never had a official programming course. Just what I pick up here and in books. In the day RF and coax did not require any programming. Times changed very much and I moved on due to my accident...

    I will be quiet for awhile.........:innocent:
  • Cluso99Cluso99 Posts: 18,069
    edited 2014-08-12 15:15
    Heater. wrote: »
    ...
    C++ is a big and complicated language, derived from C, that no human being will ever live long enough to fully comprehend. It enables object oriented programming if you like. It enables template meta programming if you like. It generally compiles down to native machine code that can give you slim and fast executables and give you as much control of your hardware as a high level language can.


    Java is a big and complicated language, sort of derived from C++, that no human being will ever live long enough to fully understand. It totally insists on the brain dead paradigm of object oriented programming for everything. It generally compiles down to byte codes which then have to be interpreted by some huge and slow virtual machine. It keeps you as far away as possible from control of your machine as a high level language can.
    Sounds a bit like Windows in OSes.
    Not only that. On top of all the inconvenience of Java it has no reason to exist at all. It brings no interesting or useful features to the programming language world.
    Sounds like Windows 8 in OSes.
    Not only that but Java was supposed to be "Write once run anywhere", however it does not run on most machines of interest unlike C++. Java is totally pointless.
    Windows 8 is equally pointless (you have to google the internet to find where they hid all the usual commands, like the simple ones to turn your PC off, or get back to your desktop.
    W 8.1 is not that much better :(
    Oh, sorry I forgot to put this at the top "WARNING Language War imminent."
    Right again!

    Sorry, just had to get the frustration off my chest.

    Back to the topic on hand.....

    Sounds really interesting, but I will have to let you all do this.
  • jazzedjazzed Posts: 11,803
    edited 2014-08-12 15:30
    Geez.

    This thread is about SystemC. It is a hardware tool used mostly in simulation/verification and has little to do with C (much less C++) programming in the usual sense other than similar syntax. Java and Javascript have nothing to do with SystemC.
  • KMyersKMyers Posts: 433
    edited 2014-08-12 15:59
    Sorry Jazzed, it was just my dumb question. Did not mean to hijack this...
    :frown:
  • Heater.Heater. Posts: 21,230
    edited 2014-08-12 16:48
    Jazzed,

    Forgive me if I'm wrong but "SystemC is a set of classes and macros which provide an event-driven simulation interface in C++". According to wikipedia at least.

    Meanwhile: "Verilator compiles synthesizable Verilog into C++ or SystemC code." According to the Verilator web site.

    And as we know C++ can be compiled to JavaScript with LLVM and Emscripten. See OpenSpin.js

    Which gives rise to the chain of thought:

    Verilog -> C++/SystemC -> JavaScript

    That is to say. The Open Source P1 design running in the browser.

    This may be an insane idea, but if someone is mad enough to get the P1 Verilog through Verlator into C++/SystemC then I'm mad enough to get that through Emscripten into the browser.

    It will happen.

    But yes you are right. Java has nothing to do with this:)
  • jazzedjazzed Posts: 11,803
    edited 2014-08-12 16:48
    KMyers wrote: »
    Sorry Jazzed, it was just my dumb question. Did not mean to hijack this...
    :frown:


    Ooops. Didn't realize you innocently started this mess.
  • jazzedjazzed Posts: 11,803
    edited 2014-08-12 17:43
    Heater,

    Yes, SystemC is used for simulation and testing. It has been for about 14 years in various places. It was slowly adopted because of industry momentum in verilog/vhdl.
  • KMyersKMyers Posts: 433
    edited 2014-08-13 08:35
    Jazzed in the future I will research my questions before I ask here....

    Back to the regular thread.
  • ReinhardReinhard Posts: 489
    edited 2014-08-13 10:01
    Sorry, I can still report no success.
    In another thread I read the files top.tdf and tim.tdf are written in AHDL.
    This could be the reason why the verilator gets out.
    I really need a verilog expert, I am not, unfortunately.

    If we have the P1 description in SystemC / C ++,
    then could bring the prop-emulator to run an army of programmers.
  • overclockedoverclocked Posts: 80
    edited 2014-08-13 22:35
    Yes that's correct. The top files are written AHDL.

    While trying to port the whole project to Xilinx ISE development environment I'm also got aware of SystemVerilog parts (SystemVerilog is not suppported in Xilinx ISE) of the code and that the ROM are intialized in a Quartus specific way.

    The things I've already done locally are:

    - Running Xilinx xport.exe command-line tool and tried to auto-convert AHDL => Verilog. Some parts seem to work, some didn't.
    - Convert different syntaxes from SystemVerilog to Verilog. multi-dim syntax, variables declared before use and others..
    - Converted in init parts to "regular" verilog $readmemh() which actually works for both environments. This also included the work of converting the hex-files from Intel-Hex format to simpler one-line format. Done!
    - Xilinx specific re-writes of PLL.

    No code share yet on these but I'll make them public when I have some kind of progress with actually running them in the Xilinx FPGA. I shall try and do that this weekend.

    It seems like one of the key things for several of the small projects here in the forum is to have a perfectly working verilog-only version of the P1.
  • Heater.Heater. Posts: 21,230
    edited 2014-08-14 00:56
    overclocked,
    It seems like one of the key things for several of the small projects here in the forum is to have a perfectly working verilog-only version of the P1.
    You raise a good point. Having an Open Source project, especially one published under the GPL, written in a closed source proprietary language like AHDL is not a very happy situation. Getting rid of that ALTERA dependence is a great idea.
  • overclockedoverclocked Posts: 80
    edited 2014-08-14 03:50
    Heater. wrote: »
    overclocked,

    You raise a good point. Having an Open Source project, especially one published under the GPL, written in a closed source proprietary language like AHDL is not a very happy situation. Getting rid of that ALTERA dependence is a great idea.

    I don't want to be the one to judge AHDL-files, so as I see it, we make a branch from a suitable Github project in which we move away from both AHDL, specific Altera commands and SystemVerilog.

    Anyone know of a github repository that mirrors the release files from Parallax? This would be a good start. Preferebly with the, for now, latest bug fixes.
  • Heater.Heater. Posts: 21,230
    edited 2014-08-14 04:29
    overclocked,

    I have put the P1 design up on github here: https://github.com/ZiCog/P8X32A_Emulation

    It is basically the original code with the tab/space problems fixed.

    It is possible that Chip will take ownership of that repository soon. After he has a while to rest and think about it. Or he might not....

    You could always fork from my repo and do whatever you like in your copy. Perhaps it happens that Parallax takes over my repo and then if your changes are nice they can be pulled from your repo directly in to Parallax's.
  • RamonRamon Posts: 484
    edited 2014-08-20 06:34
    Verilator is working now thanks to the work from Magnus Karlsson.

    1) Download the code from this thread:

    http://forums.parallax.com/showthread.php/157004-Propeller-1-running-on-Pipistrello-(Xilinx-Spartan6-LX45)

    2) Add "/* verilator lint_off WIDTH */" to cog_vid.v, cog_ctr.v, cog.v and hub.v

    (Small changes to the code to avoid this compiler warning)

    3) Substitute line 108 of cog_vid.v with this lines:

    /* verilator lint_off UNOPTFLAT */
    reg [1:0] snc;
    /* verilator lint_on UNOPTFLAT */

    4) Substitute line 52 of cog_vid.v whit this lines:

    /* verilator lint_off UNOPTFLAT */
    reg [31:0] vid;
    /* verilator lint_on UNOPTFLAT */

    5) Now run verilator on dig.v

    $ verilator -cc dig.v

    Enjoy!

    It works, but do not know how to use it, as I don't know anything about C++, SystemC or SystemPerl. But I am sure there will be someone here that knows how to use it :)
Sign In or Register to comment.