Shop OBEX P1 Docs P2 Docs Learn Events
[resolved][puzzle] Carry on! — Parallax Forums

[resolved][puzzle] Carry on!

kuronekokuroneko Posts: 3,623
edited 2010-12-12 17:15 in Propeller 1
What am I after this time? Find a way of determining whether you ran out of cogs using as little resources as possible. This includes s/w as well as h/w.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-11 22:37
    if (cognew(@test, 0) < 0)
      sio.str(string("Oh dang! I'm out of cogs!"))
    
    ...
    DAT
    
    test    cogid    test
            cogstop  test
    
    I somehow have a feeling you were after more (i.e. less). :)

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-11 23:20
    I somehow have a feeling you were after more (i.e. less). :)

    This time you're right. That's way too heavy. But at least that gives us something to work on.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-11 23:30
    You didn't specify whether the test was to be carried out in Spin or PASM. Which is it to be? I think it's also important to stipulate that if a cog is started because of the test, its effects must be nil, and it must be stopped. I think you also need to stipulate that the test be independent of anything that happens in the cogs that are running. IOW, they should not need to contribute to -- or be aware of -- the test.

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-11 23:51
    I think it's also important to stipulate that if a cog is started because of the test, its effects must be nil, and it must be stopped. I think you also need to stipulate that the test be independent of anything that happens in the cogs that are running. IOW, they should not need to contribute to -- or be aware of -- the test.
    You'd think I learnt something regarding how much info I must include to keep you happy ;) OK, for this exercise I might as well demand PASM.

    As for the other two criterias, admittedly I was afraid of stating the obvious. Not much good if you tear down the whole system by doing a simple test.
    • minimal to no impact on the running system, as stealthily as possible
    • no resource leaks (rogue cogs)
    Did I miss anything?

    Note, the test is done as part of your normal code so the PASM cog isn't started for the sake of the test.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-12 00:34
    One instruction (with undocumented carry behavior):
            cogid   $ nr,wc     'Set carry iff no more free cogs.
    

    Here's my test code:
    CON
    
       _clkmode       = xtal1 + pll16x
       _xinfreq       = 5_000_000
    
    PUB  Start
    
      repeat 5 'or 6
        cognew(@dummy, 0)
      cognew(@tester, 0)
      repeat
    
    DAT
    
                  org       0
    
    dummy         jmp #$
    
                  org       0
    
    tester        mov       dira,#1
                  cogid     $ nr,wc
            if_c  or        outa,#1
                  jmp       #$
    

    -Phil

    BTW, I'm guessing that, due to symmetry, clkset exhibits the same carry behavior, but I've not tested it.
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-12 00:50
    Well done! That's what I had in mind. Either of rdxxxx/wrxxxx, cogid and clkset can be used. coginit and cogstop exhibit the same behaviour but have unwanted side effects.

    That said, the latest manual specifies carry cleared for most of them. Go figure.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-12 01:08
    Among that group of instructions, only cogid can be completely neutralized with the nr setting.
    That said, the latest manual specifies carry cleared for most of them. Go figure.
    The documenters must've felt it was not important enough to note -- or else they just didn't know about it. But yes, saying "0" is different than saying "-". In any event, this is useful enough to deserve being a separate instruction: cogtest. Now where's that macro assembler? :)

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-12 01:25
    Among that group of instructions, only cogid can be completely neutralized with the nr setting.

    Fair enough. I was thinking more like that if you do a hub access anyway (as part of your code) you might as well force wc and look at it later.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-12 01:34
    kuroneko wrote:
    I was thinking more like that if you do a hub access anyway (as part of your code) you might as well force wc and look at it later.
    Hmm, that's true, which effectively reduces the number of instructions required for the actual test to zero! :)

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-12 01:44
    Out of curiosity, how did you arrive at your solution? I had mov[dis] and jmp[ret] figured out [post=864343]a while back[/post] and rdxxxx/wrxxxx were on my list for today.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-12 09:21
    kuroneko wrote:
    Out of curiosity, how did you arrive at your solution?
    The biggest clue, of course, was that it was you posing the question. That immediately suggested undocumented behavior. :) From there, I went to the instruction cheat sheet that I keep handy. With that, it's easy to spot instructions with similar bit patterns. The four hub instructions with S.bit2 == 0 (cogx's and clkset) stood out as a group, so it seemed natural to think they might all treat the carry flag the same if it wasn't committed to some other purpose -- and it's not. Among those, cogid is the only one that can be completely neutralized with nr, so it's the only one I tested.

    I'm surprised that rdxxxx and wrxxxx behave that way, too, since they're not in that group. But I would almost bet that if bit 2 of S in those instructions is a one, the carry flag will return lock status instead.

    Now, here's a follow-on puzzle: Is there an easy, non-destuctive way to tell if a particular cog is being used? (I haven't come up with an answer, BTW, and suspect it can't be done without cognewing the remaining cogs and eliminating their IDs from a pre-populated list.)

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-12 16:56
    The biggest clue, of course, was that it was you posing the question. That immediately suggested undocumented behavior. :)

    Touch
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-12-12 17:09
    Another great find. I agree, shame we do not have macros to expand the compiler.

    Now, what do the unimplemented instructions MUL (000100), MULS, ENC, ONES do?
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-12 17:15
    Cluso99 wrote: »
    Now, what do the unimplemented instructions MUL (000100), MULS, ENC, ONES do?

    IIRC they clear the destination register and therefore set Z if you wish (on my demoboard that is). But that was only from a quick test.
Sign In or Register to comment.