#29 testfile for jumptable generation

None
closed-out-of-date
None
5
2015-11-06
2004-11-28
No

Hi,
I don't want to add this file permanently to the
regression tests as it will probably/hopefully just burn
CPU-cycles with no real benefit. Instead I'm providing it
here.

If you want to test jumptable generation in SDCC 2.4.7
#892 (Nov 26 2004) copy this file into
sdcc/support/regression/tests, set the environment
variable SDCC_SJMP_JUMPTABLE, cd to
sdcc/support/regression, and run "make test-mcs51
test-mcs51-large test-mcs51-stack-auto
test-mcs51-xstack-auto" there.

One of the generated source files is f.e.:
sdcc/support/regression/gen/mcs51/switch_tbl/switch_tbl_size_12.asm

Discussion

  • Hubert Sack

    Hubert Sack - 2004-12-05

    Logged In: YES
    user_id=1160854

    Is RFE 970220 affected by this patch?

     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052

    No,
    RFE #970220 is there in case a switch statement does not
    optimize to a jumptable. The conditions then have to be
    tested individually and those being tested first will be
    significantly faster.

    Now the situation falls into at least three cases:
    a) the programmer knows which branch is most likely taken
    (in this case he might sort the cases to ensure that the
    likelier ones are tested first). This is what my #970220 is for.

    Much more dedicated is:
    b) the programmer doesn't know which branch is most likely
    taken (or all are
    equally likely). What to do then? Well if you know nothing
    and want to get the most of each compare you'd have to do a
    binary search.
    The 8032 is surprisingly good prepared for this, look at
    (part of) a test for 16 cases:

    TEST_0x08:
    CJNE A,#0x08,NOT_0x08
    SJMP LABEL_0x08
    NOT_0x08:
    JC TEST_0x04 ; or JNC?
    TEST_0x0c:
    CJNE A,#0x0c,NOT_0x0c
    SJMP LABEL_0x0c
    NOT_0x0c:
    JC TEST_0x0e ; or JNC?
    ... (almost there, proceeding without binary search now)

    c) like b) but the programmer does care more about size than
    speed. The algorithm as SDCC has it now fits this perfectly.
    But switching to a) wouldn't hurt either:^)

     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052

    Ooops, sorry, my statement in c) is not quite true:

    Most compact will be (here testing for 0,4,5,8,9)

    mov a,condition
    jz LABEL_0x00
    add a,#04
    jz LABEL_0x04
    inc a
    jz LABEL_0x05
    add a,#0x03
    jz LABEL_0x08
    inc a
    jz LABEL_0x09

     
  • Philipp Klaus Krause

    We still have

    if (TARGET_IS_MCS51 && !getenv("SDCC_SJMP_JUMPTABLE"))
    return FALSE;

    is there are reason we just don't enable this for mcs51, and do away with the environment var, as it is for the other ports?

    Philipp

     
  • Maarten Brock

    Maarten Brock - 2015-11-06

    I've enabled this optimization for mcs51 as well. And since this case is already covered by switch.c I did not add switch_tbl.c to the regression tests.

     
  • Maarten Brock

    Maarten Brock - 2015-11-06
    • Description has changed:

    Diff:

    
    
    • status: open --> closed-out-of-date
    • assigned_to: Maarten Brock
    • Group: -->
     

Log in to post a comment.