Shop OBEX P1 Docs P2 Docs Learn Events
GEAR does not seem to emulate SUBS correctly. (Now resolved/fixed) — Parallax Forums

GEAR does not seem to emulate SUBS correctly. (Now resolved/fixed)

Bob AndersonBob Anderson Posts: 122
edited 2009-10-25 23:31 in Propeller 1
If "answer"·contains 00000005

and GEAR executes the instruction:···· SUBS answer,#1

answer then contains FFFFFFFC· (which is -4)

instead of 00000004.

Is this a GEAR emulation problem, or am I misinterpreting how SUBS is supposed to operate?



Post Edited (Bob Anderson) : 10/30/2009 6:05:40 AM GMT

Comments

  • LeonLeon Posts: 7,620
    edited 2009-10-21 00:15
    It looks wrong so I checked it with this assembler program and Simple Debug, and got 4:

    DAT
            org             0   
    
    Entry
            mov             x, #5
            subs            x, #1
            wrlong          x, par
            
    x       res   1
    
    



    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-21 00:45
    Thanks for the test.· That's how subs is supposed to work.· I'm afraid Gear has a problem.· I'll have to correspond directly with the developer.
  • mirrormirror Posts: 322
    edited 2009-10-21 07:51
    Hi,
    I just had a look at the source code, and the bug may affect a number of instructions:
    SUBX, SUBS, SUBSX, CMPX, CMPSX
    All of them seem to have the source and destination registers swapped around (when compared with SUB, SUBABS and CMP).
    Unless there was some "magic" that was used in the calculation, my proposal would be to swap all of these instructions.
    Unfortunately, I'm not the original author, but have been maintaining (fixing, improving) the code for the last 18 months.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • LeonLeon Posts: 7,620
    edited 2009-10-21 09:28
    It's strange that it hasn't been picked up before. Perhaps those instructions don't get much use. smile.gif

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • mirrormirror Posts: 322
    edited 2009-10-21 10:38
    It is possible that the instructions affected are not used all that often.

    I've attached a "fixed" version of GEAR. It "fixes" all the instructions indicated. Hopefully nothing gets broken!

    Could you please test it before I repackage it for upload at: http://forums.parallax.com/showthread.php?p=701256
    Gear.zip 113.2K
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-21 16:24
    mirror:

    That took care of SUBS. I don't have a test for the others yet. I'll be away for a couple of hours, but when I return, I'll gen up some.

    Bob
  • mirrormirror Posts: 322
    edited 2009-10-21 21:45
    Hi Bob,

    A bunch of test cases for these instructions would be appreciated. I don't mind fixing GEAR, I'm just a bit short of time at the moment.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-21 22:04
    Bad news.· I did a more thorough test of SUBS by trying each of the cases that are given in the Concise Truth Table for the SUBS instruction in the Propeller Manual.· There are 8 cases.· If you number them 1 to 8, in all 8 cases, the destination value was correct and the Z flag was correct.· In cases 1·.. 4, the C flag was also correct.· But, in cases 5..8, the carry flag is inverted.

    I have attached a snap of the SUBS manual.

    I have also attached the test code that I stepped through.· The comment on the SUBS commands is what the result should have been.

    I'll continue developing test cases using the same protocol of testing all the cases from the Concise Truth Table.
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-21 22:17
    Oops.· I attached the wrong test file.· Here's the right one.
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-22 06:52
    mirror:

    Here are the test files I used for SUBS.

    The file with the extension spin-aac will not be familiar to you.· I am working on a tool to help people (like me) that are writing assembly code.· AAC stands for Augmented Assembly Code.· I hope to find a few beta testers in about a week.· The code is done, but I have not completed the built in Manual.

    'Gear gen test.spin' is the output of my tool.· 'Gear gen test.spin-aac' is the input to the tool.

    'Gear gen test.binary' is the output of Propeller Tool v1.2.6

    It now fairly easy to generate test code for any instructions that you wish me to test.·
  • mirrormirror Posts: 322
    edited 2009-10-22 07:05
    Ooooh, I still have the original Propeller Manual (Ink 'n Paper version) which doesn't have either the "new" or "improved" stuff. It looks great for figuring out how the PASM emulation should operate.

    Now I just have to find some time...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-22 07:16
    Here are pictures from running the 'Gear gen test.binary' on GEAR.

    You should be able to load the binary into GEAR and press run.· Switch to cog 1 and navigate to the ans[noparse]/noparse array.· This process is documented by the attached pictures.
    890 x 509 - 88K
    879 x 571 - 92K
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-22 16:46
    I have completed testing SUBX.· I did all the cases shown in the Concise Truth Table for the instruction.· In addition, I added cases for the "don't cares" (this occurs for the Z and C flags) so that both values of the flag are tested if it was a don't care.

    Attached are the relevant files.

    SUBX passes all 4 test cases!
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-22 16:49
    I have completed testing the CMPX instruction.· There are 18 cases to test plus an additional 8 to cover the "don't cares" on the Z flag initial value.

    Attached are the relevant files.

    CMPX passes all 18 + 8 cases.
  • lonesocklonesock Posts: 917
    edited 2009-10-22 16:59
    Would you mind testing the rev instruction? I seem to recall the bits parameter was mis-interpreted.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-22 21:13
    lonesock:

    I tested REV.· There where 9 case in the Concise Truth Table.

    Cases 1..9 all got an incorrect result.· Majorly wrong actually.

    Case 1 also had an incorrect Z flag (because the result was wrong and would have been 0)

    Cases 1..9 had correct C flags.· A bit of a surprise since case 6..9 had C = 1.· So much else seemed to wrong, it's a wonder the C flag turned out right.

    Attached are relevant files.
  • SapiehaSapieha Posts: 2,964
    edited 2009-10-22 23:54
    Hi Bob Anderson.


    Can I use Yours program snipets in my Stress program for Propeller/COG's

    Regards
    ChJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-22 23:58
    Certainly.

    Would you explain your "Stress program" a little more?
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-23 00:38
    mirror:

    I tested the SUBSX instruction.· There are 10 cases in the Concise Truth Table.

    There are a number of cases where the input Z flag is shown as an x (don't care).· I entered these cases as Z = 0 and did NOT test the corresponding case with Z = 1

    Summary: Cases 1..10 are correct as to dest value and Z flag output.· Cases 1..6 are correct for C flag output.· Cases 7..10 have inverted C flag outputs.
  • SapiehaSapieha Posts: 2,964
    edited 2009-10-23 00:54
    Hi Bob Anderson.

    I work on program to stress Propeller with overclocking.
    In all posible way from simple COG to entire Propeller.
    And must test every instruction/Flag in COG and every Counter with possibility to place results in HUB to send them to VGA else Simple terminal
    That can give me possibility to real test Frequency Propeller fail its stable state.

    Regards

    ChJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-23 01:01
    mirror:

    I have tested the CMPSX instruction emulation.· There are 20 cases in the Concise Truth Table.· I treated Z = x as Z = 0

    Summary: Cases 1..20 are correct for dest value and Z flag.· But cases 9..12 have inverted C flags.
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-24 15:26
    ALE:

    Here are all the files involved in testing CMPSX, REV, SUBS, SUBSX, SUBX, and CMPX.

    I hope this helps you with pPropellerSim.

    Bob
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-25 21:17
    ALE:

    The attached zip takes care of the empty 'Gear SUBS test.spin' file.

    It also changes all org statements from:

    entry·· ORG· 0

    to:

    ········· ORG· 0
    entry

    I found that the first version sometimes gave problems.
  • mirrormirror Posts: 322
    edited 2009-10-25 22:00
    Okay, I've been away for the weekend (no internet connection) but am now back. Hopefully I can look into the emulation of the faulty instructions.
    I'm reasonably certain that there will be simple fixes for the majority of the issues raised. I'll post again once I have a release candidate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • mirrormirror Posts: 322
    edited 2009-10-25 23:14
    I think that I've interpreted the results of the test case files correctly...

    I would love third party verification of the results for SUBX, CMPX, SUBS, SUBSX, CMPSX and REV before I turn this into an official release.
    Gear.zip 113.2K
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-25 23:20
    mirror:

    I did run all the test files on a real chip to validate the test code itself. I assume that you're asking me to run Gear on the test files and verify that all cases worked.

    Will do.

    Bob
  • Bob AndersonBob Anderson Posts: 122
    edited 2009-10-25 23:31
    mirror:

    I reran the tests on CMPSX, CMPX, REV, SUBS, SUBSX, and SUBX.

    All ran perfectly through all the cases.

    I was gratified at how quickly this could be done.

    Congrats to you on the fixes.

    Bob
Sign In or Register to comment.