Shop OBEX P1 Docs P2 Docs Learn Events
Objects sharing Main Ram — Parallax Forums

Objects sharing Main Ram

Bob DruryBob Drury Posts: 236
edited 2008-08-12 22:15 in Propeller 1
Is there an explanation on how Propeller spin code runs multiple objects with the stack space
Thanks for your help

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-30 22:52
    Best place to look is the description of COGNEW / COGINIT in the Propeller Manual. I believe there's also a unit in the tutorials for the Propeller Education Kit which you can download from Parallax.

    Basically, when you do a COGNEW or COGINIT, the Spin interpreter starts a new cog using a COGNEW/COGINIT instruction. The program started is the Spin interpreter from the Propeller's ROM. There's some information passed to the new cog which includes the starting address of the interpretive code to use and the start of a stack space for the interpreter to use.
  • Bob DruryBob Drury Posts: 236
    edited 2008-07-31 03:47
    Thanks Mike
    I have looked at the manual discussing Hub and resources but Iwas just wondering if there
    might be a discussion of how spin interperter waits for the hub time to process spin, it also
    looks like the cogs when running spin are actually clocking at 200khz while the cog assembler
    would be cloking at 80MHZ I will download tutorials
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-31 03:57
    The Spin interpreter has been released in source form, so you can look at it if you want to see exactly what's done.

    The Spin interpreter uses the same hub instructions as any other assembly program (RDxxxx / WRxxxx). These
    wait automatically for the cog to have its access slot.

    The Spin interpreter runs at the same clock speed as everything else (normally 80MHz). It's just that, to process
    one Spin byte code instruction takes several assembly instructions (usually a 20:1 ratio on average ... typical for
    most interpreters). At 80MHz, most assembly instructions take 4 clock cycles or 50ns to execute. On average,
    most Spin byte code instructions should take about 1us to execute (20 x 50ns). Any Spin statement consists
    of several byte code instructions, so the simplest Spin statement may take 5-10us to execute. I may be off a
    little in these times, but they're the right order of magnitude.
  • Bob DruryBob Drury Posts: 236
    edited 2008-08-01 02:50
    Mike
    thanks for the info this propeller chip is very intriguing
    best Regards
    Bob Drury
  • hippyhippy Posts: 1,981
    edited 2008-08-01 12:51
    Is there an explanation on how Propeller spin code runs multiple objects with the stack space

    Fisrtly, an aside for anyone who wants to throw in their two cents : What is the terminology for something which is running in parallel in a Cog - process, task, thread, something else ?

    I'll call them processes here.

    When the first process runs, the main program, it will have memory space allocated for the variables and arrays it uses and there is also a stack space it uses at run time. When the first process launches a second process it will tell that process where the second process's stack space is. This is often an array of longs called "stack[noparse]/noparse" or similar which is part of the first processes memory space. When the new process runs it will use that memory space as its own stack, the stack used by the first process is used only by the first process.

    Another way of looking at it is that any process which launches a sub-process has to have set aside some of its own memory space for each sub-process to use as a stack, that Stack[noparse]/noparse array as is often seen in example code ...

    VAR
      long stack[noparse][[/noparse] 100 ]
    
    PUB FirstProcess
      CogNew( SecondProcess, @stack )
      repeat
        Something
    
    PRI SecondProcess
      repeat
        SomethingElse
    
    
    



    "Stack[noparse]/noparse" is only stack for the second process, it is part of the memory space for the first process.
  • Bob DruryBob Drury Posts: 236
    edited 2008-08-12 22:15
    hop.gifThanks for your reply I will try to download and test my code reading skills
    regards bob drury
Sign In or Register to comment.