Shop OBEX P1 Docs P2 Docs Learn Events
Expletives withheld — Parallax Forums

Expletives withheld

mirrormirror Posts: 322
edited 2007-10-26 23:52 in Propeller 1
Searching for a bug through 600 lines of assembly...

My project uses all 8 cogs, of which 7 are assembly.

Two of the assembly cogs are in the same spin file - they consist of a low level (high speed) scanning cog, and a higher level (lower speed) processing cog. The cogs share various resources, which is why they're grouped.

There was just simply some instability in the algorithm·that I could not make sense of, but I finally tracked down the cause. It is essentially as follows:
DAT
    'code for cog 1 - about 30 lines
    'including references to varA
varA   long   0
 
DAT
    'code for cog 2 - about 600 lines
    'including a reference to varA   <- NOT GOOD.
 

The location being written to by the reference to varA in the second cog·is the same offset into the second cog as varA is offset into the first cog.

So you think you're writing a variable ... BUT you're not ... you're modifying your own code.

No warnings from the compiler about the incestuous relationship between the two DAT sections. I know it's an error! It's obvious once you find such a thing that it's an error!

What a waste of a day.



·

Comments

  • BaggersBaggers Posts: 3,019
    edited 2007-10-26 11:35
    mirror,

    I guess you know now, but you have to have vars / dat in hubram and have pointers in cogram and wrlong/wrword/wrbyte rdlong/rdword/rdbyte them for you to have intercog communication.

    Baggers.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-10-26 16:30
    Mirror, commiseration granted. I gather you didn't smoketest each on its own.

    Baggers, I'll bet it was just a standard working register name for Mirror, not meant for cog to cog use.
  • BaggersBaggers Posts: 3,019
    edited 2007-10-26 16:38
    oh well at least he caught it, this should probably be added to the Tricks and Traps thread.
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-26 17:05
    It is very well known issue. One of the many "traps" due to the inability of the SPIN IDE to issue warnings.
    DAT
     x byte 500
    
    


    is another one. The reason is mainly a typo, rarely a misunderstanding: "Oh, I thought a byte could hold 500 values. Oh, I thought I could address into another COG."

    It's a simple bug/typo as difficult to catch as any any other bug or typo in your program. So no need to get excited about smile.gif
  • mirrormirror Posts: 322
    edited 2007-10-26 21:49
    Fred Hawkins said...
    Mirror, commiseration granted. I gather you didn't smoketest each on its own.

    Baggers, I'll bet it was just a standard working register name for Mirror, not meant for cog to cog use.
    Fred, 1 out of 2.

    Wrong guess:
    The smoketest was done. The original had a short fast assembly section (about 1_000_000 iterations per second), and I thought that the longer slower processing would be OK in spin. Unfortunately I missed by about a factor of 3. I used several FIFO's,·did a pile of clock counting and optimisation to get the spin faster, but just couldn't get it over the line. The "slow" process needs to execute about 15000 times a second (under maximum load), but may only need to execute 1000·times a second under light load. The quickest I got was about 6000 iterations.

    Correct guess:
    The fast assembly section had the following bit of code:
    DAT   . . .
       mov  CFlag,#0
       rcr  CFlag,#1  wc  'Clear the carry flag
       . . .
    CFlag   long  0
    

    In the midst of the conversion process (spin to pasm), I realised again that I needed to clear and set the carry flag, so copied the code across from one DAT section to the other.

    The rest, as they say, is history . . .

    Now the reality of life is that the conversion of the code took a whole day - due to the quantity and complexity. Testing was started on day 2. The lines in question were copied across at some fuzzy point in the·middle of the day.

    Without warnings, we often·fly blind.

    I've seen the frustrations expressed as others on this forum debate whether to write their code as one large spin file - beware, that path also has traps!
    ·
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-10-26 23:06
    Mirror, 1 for 2 is at least a whole day for me.
  • rjo_rjo_ Posts: 1,825
    edited 2007-10-26 23:28
    mirror,

    Remember, you are a genius, so things can't be all bad.

    At moments like these one is tempted to blame someone for not doing something that would make our lives easier.

    Let's blame deSilva[noparse]:)[/noparse] He could easily write a parser that looks for stuff like this and spits out clean Spin/Assembly.

    Rich
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-26 23:41
    I'm looking for the day when deSilva writes to the forum asking for help with something that deSilva can't explain! smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • rjo_rjo_ Posts: 1,825
    edited 2007-10-26 23:52
    Don't hold your breath[noparse]:)[/noparse]
Sign In or Register to comment.