Shop OBEX P1 Docs P2 Docs Learn Events
C++ for P2? — Parallax Forums

C++ for P2?

Anyone remember who was working on C++ for P2? I downloaded the source code for the Mutable Instruments Eurorack modules and, unfortunately, the code is all in C++. I had hoped it might be possible to get it to run on P2.

Comments

  • RaymanRayman Posts: 13,883
    edited 2020-05-30 00:55
    I would also love to have C++ for P2. GCC is probably still the easiest way.
    I'm sure @"Dave Hein" had something that worked, right?
  • Rayman wrote: »
    I would also love to have C++ for P2. GCC is probably still the easiest way.
    I'm sure @"Dave Hein" had something that worked, right?
    Dave used the P1 GCC compiler and translated its output to run on the P2. I'm not sure he ever got C++ working though.

  • RaymanRayman Posts: 13,883
    Ok, I think you are right.
  • I did look into adding C++ to p2gcc about a year ago. It required adding some startup code, and implementing the libraries needed for C++. I didn't pursue it much after that, and then I quit working on p2gcc altogether after Eric got FlexGUI up and running. FlexGUI is an excellent development system. I hope Parallax is contributing financially to Eric's work. In my opinion, I think FlexGUI will become the primary development system for the P2.

    Hopefully, Parallax will pay Eric enough for his work to motive him to add a useful subset of C++ to FlexGUI.
  • Dave Hein wrote: »
    I did look into adding C++ to p2gcc about a year ago. It required adding some startup code, and implementing the libraries needed for C++. I didn't pursue it much after that, and then I quit working on p2gcc altogether after Eric got FlexGUI up and running. FlexGUI is an excellent development system. I hope Parallax is contributing financially to Eric's work. In my opinion, I think FlexGUI will become the primary development system for the P2.

    Hopefully, Parallax will pay Eric enough for his work to motive him to add a useful subset of C++ to FlexGUI.
    I'm not a big fan of GUIs but I agree that the fastspin languages are fantastic. I've been using FlexC for all of my P2 work so far. The only reason I would consider anything else is if I need C++ support.

  • David Betz wrote: »
    Anyone remember who was working on C++ for P2? I downloaded the source code for the Mutable Instruments Eurorack modules and, unfortunately, the code is all in C++. I had hoped it might be possible to get it to run on P2.

    The only C++ compiler for P2 I'm aware of is riscvp2: https://github.com/totalspectrum/riscvp2.
  • ersmith wrote: »
    David Betz wrote: »
    Anyone remember who was working on C++ for P2? I downloaded the source code for the Mutable Instruments Eurorack modules and, unfortunately, the code is all in C++. I had hoped it might be possible to get it to run on P2.

    The only C++ compiler for P2 I'm aware of is riscvp2: https://github.com/totalspectrum/riscvp2.
    There was someone who was porting GCC but I can't remember who. Anyway, I had forgotten about riscvp2. I did try to install the riscv toolchain on my Mac at one point but it wasn't totally trivial so I never found time to complete the process. Maybe I should install a Linux VM. However, do you think riscvp2 would perform well enough to do DSP-like tasks?

  • David Betz wrote: »
    ersmith wrote: »
    David Betz wrote: »
    Anyone remember who was working on C++ for P2? I downloaded the source code for the Mutable Instruments Eurorack modules and, unfortunately, the code is all in C++. I had hoped it might be possible to get it to run on P2.

    The only C++ compiler for P2 I'm aware of is riscvp2: https://github.com/totalspectrum/riscvp2.
    There was someone who was porting GCC but I can't remember who. Anyway, I had forgotten about riscvp2. I did try to install the riscv toolchain on my Mac at one point but it wasn't totally trivial so I never found time to complete the process. Maybe I should install a Linux VM. However, do you think riscvp2 would perform well enough to do DSP-like tasks?

    In most benchmarks I've run riscvp2 is the highest performing C compiler for the P2. The only case where I've seen it slower is in micropython, where it was a little slower than @rogloh's p2gcc version of micropython (but at least riscvp2 was considerably smaller :)). So yes, I think it would work well for DSP like tasks.

    For example, Heater's old fft-bench benchmark gave the following results when I tested it back in February:
    command lines used:
    
    fastspin -2 -O2 -o fastspin.bin fft_bench.c
    catalina -lci -p2 -O3 -C P2_EVAL -C NATIVE -D PROPELLER fft_bench.c
    p2gcc -D _cnt=getcnt fft_bench.c
    riscv-none-embed-gcc -T riscvp2_lut.ld -specs=nano.specs -Os -o a.elf fft_bench.c
    
    results: time / size of binary loaded to P2
    
    current results 2020-02-01
    riscvp2:  18706 us  33092 bytes
    fastspin: 39634 us  16384 bytes
    catalina: 55876 us  27808 bytes
    p2gcc:    64765 us  21204 bytes
    

    Note that the actual "us" time is bogus, we're actually just reporting elapsed cycles divided by the fixed constant 80 (the original test was on P1 at 80 MHz, so that's how the time is computed). But the relative timings should be valid. I'm surprised at p2gcc's relatively poor result on this particular test. It's not representative, usually p2gcc and fastspin are around the same speed.
  • David Betz wrote: »
    ersmith wrote: »
    David Betz wrote: »
    Anyone remember who was working on C++ for P2? I downloaded the source code for the Mutable Instruments Eurorack modules and, unfortunately, the code is all in C++. I had hoped it might be possible to get it to run on P2.

    The only C++ compiler for P2 I'm aware of is riscvp2: https://github.com/totalspectrum/riscvp2.
    There was someone who was porting GCC but I can't remember who. Anyway, I had forgotten about riscvp2. I did try to install the riscv toolchain on my Mac at one point but it wasn't totally trivial so I never found time to complete the process. Maybe I should install a Linux VM. However, do you think riscvp2 would perform well enough to do DSP-like tasks?

    @ntosme2
  • Tubular wrote: »
    David Betz wrote: »
    ersmith wrote: »
    David Betz wrote: »
    Anyone remember who was working on C++ for P2? I downloaded the source code for the Mutable Instruments Eurorack modules and, unfortunately, the code is all in C++. I had hoped it might be possible to get it to run on P2.

    The only C++ compiler for P2 I'm aware of is riscvp2: https://github.com/totalspectrum/riscvp2.
    There was someone who was porting GCC but I can't remember who. Anyway, I had forgotten about riscvp2. I did try to install the riscv toolchain on my Mac at one point but it wasn't totally trivial so I never found time to complete the process. Maybe I should install a Linux VM. However, do you think riscvp2 would perform well enough to do DSP-like tasks?

    @ntosme2
    That's who I was thinking about. Unfortunately, he hasn't been online since January.

  • @ersmith What Linux distribution do you recommend?
  • David Betz wrote: »
    @ersmith What Linux distribution do you recommend?

    Honestly riscvp2 should install just fine on MacOSX, or at least it'll be no harder than on Linux. Start with a riscvp2 cross compiler for Mac (like: https://github.com/ilg-archived/riscv-none-gcc/releases/download/v8.2.0-2.2-20190521/gnu-mcu-eclipse-riscv-none-gcc-8.2.0-2.2-20190521-0004-macos.tgz), install it someplace convenient (does Mac have /opt? I used /opt/riscv-none-gcc) and then edit the riscvp2 Makefile to reflect where the binaries are and what the prefix for them is. You'll also have to make the FASTSPIN= variable point to your fastspin. Then just do "make install" in the riscvp2 directory.

    The riscvp2 Makefile only adds a few additional files to the existing risc-v toolchain. Basically it's all just linker scripts; from the risc-v compiler's point of view the P2 has a special crt0.o that's the first think linked and executed. But what "really" happens is that crt0.o has P2 code that the P2 executes to start the JIT compiler.
  • ersmith wrote: »
    David Betz wrote: »
    @ersmith What Linux distribution do you recommend?

    Honestly riscvp2 should install just fine on MacOSX, or at least it'll be no harder than on Linux. Start with a riscvp2 cross compiler for Mac (like: https://github.com/ilg-archived/riscv-none-gcc/releases/download/v8.2.0-2.2-20190521/gnu-mcu-eclipse-riscv-none-gcc-8.2.0-2.2-20190521-0004-macos.tgz), install it someplace convenient (does Mac have /opt? I used /opt/riscv-none-gcc) and then edit the riscvp2 Makefile to reflect where the binaries are and what the prefix for them is. You'll also have to make the FASTSPIN= variable point to your fastspin. Then just do "make install" in the riscvp2 directory.

    The riscvp2 Makefile only adds a few additional files to the existing risc-v toolchain. Basically it's all just linker scripts; from the risc-v compiler's point of view the P2 has a special crt0.o that's the first think linked and executed. But what "really" happens is that crt0.o has P2 code that the P2 executes to start the JIT compiler.
    I think I tried building from source and it wanted me to install various packages. The Mac doesn't really have its own package manager so you have to use a third party one and there are several. I ran into trouble once when I installed two different packages that each required a different package manager and the package managers conflicted with each other. I wish Apple would provide its own!

    Maybe I'll try the binary installation.

Sign In or Register to comment.