Shop OBEX P1 Docs P2 Docs Learn Events
COG vs LMM — Parallax Forums

COG vs LMM

User NameUser Name Posts: 1,451
edited 2013-03-26 19:22 in Propeller 1
I gave Propellergcc a spin for the first time today and was totally impressed with all that has been done!

I apologize if this question has already been addressed ad nauseum.... Given that the COG memory model has severe space limitations, is there a document detailing what can and can't be done in COG mode?

I was puzzled when the use of the sprintf command produced an error message. Couldn't see anything wrong with the code, so I switched to LMM memory model (what else was there to try?) and it compiled like a champ. Nothing in the error message indicated (to me anyway) that the problem was one of space limitation.

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2013-03-26 13:49
    When I tried this I got an undefined reference to sprintf from the the linker. I'm assuming that sprintf is not included in the COG version of the libraries. The full implementation of sprintf would require more memory than a cog has, which is probably why it's not in the library.
  • jazzedjazzed Posts: 11,803
    edited 2013-03-26 15:10
    AFAIK printf is the only library item available in COG mode, and it is very limited (integer only).
    https://code.google.com/p/propgcc/source/browse/lib/cog/miniprintf.c
  • User NameUser Name Posts: 1,451
    edited 2013-03-26 16:21
    Thanks for the answers!

    Just a couple follow-up comments:

    * I noticed that on some simple port toggling experiments I got identical speeds with COG and LMM settings, which means to me that both tests were using the same mode, despite the setting.

    * On a side-by-side comparison with an ARM Cortex M0 (LPC1114FN28) clocking at 48MHz (50 MHz is max for the device) running identical pin toggling C code, the Prop was more than 3.2x faster. This actually surprises me, since the ARM Cortex architecture was tailored around the needs of a C compiler. Clearly there are far faster ARM chips than the one I'm using, but they're not available in convenient-to-use DIPs.

    Anyway, I'm quickly warming to gcc on the Prop. I applaud the effort and genius that went into this project. Suddenly I can understand the enthusiasm for gcc on the P2!
  • ersmithersmith Posts: 6,054
    edited 2013-03-26 18:04
    User Name wrote: »

    * I noticed that on some simple port toggling experiments I got identical speeds with COG and LMM settings, which means to me that both tests were using the same mode, despite the setting.

    You're seeing the effect of FCACHE ("fast cache"), an idea Bill Henning came up with. In LMM mode, small loops are compiled with a prefix that loads them into COG memory, and they run from there. So a small loop can run as fast in LMM mode as in COG mode. Simple programs like pin toggling tend to run at almost the same speed both ways.

    Eric
  • SRLMSRLM Posts: 5,045
    edited 2013-03-26 18:30
    User Name wrote: »
    * I noticed that on some simple port toggling experiments I got identical speeds with COG and LMM settings, which means to me that both tests were using the same mode, despite the setting.

    You might try the flag "-mno-fcache" to see if that slows things down.
  • User NameUser Name Posts: 1,451
    edited 2013-03-26 19:22
    Yup. That was exactly it. Thanks for the explanations and suggestions.

    This is intriguing. It demands another bunch of tests to explore the boundaries of the feature. I like it a lot, and I want to write code in a way that makes the most of it.
Sign In or Register to comment.