Menu

#922 s51 return from recursive call considered jump to self

None
pending
None
5
2024-11-14
2023-08-24
No

The (s51) simulator thinks that returning from a recursive function to itself is a "Jump to itself" and thus stops when "set opt selfjump_stop 1" is used. This makes the tcc/25_quicksort regression test fail with an abnormal stop when --no-peep is used.

_quicksort:
[...]
       lcall   _quicksort
00103$:
;       cases/../tcc/25_quicksort.c:45: }
        ret

With peephole optimizations enabled this becomes

_quicksort:
[...]
       ljmp   _quicksort

which prevents the stop and thus also prevents the false negative.

Is this the intended behaviour of selfjump_stop? If so, the regression tests should not use.
If not, then maybe it should also test for stack usage reduction.

Discussion

  • Maarten Brock

    Maarten Brock - 2023-08-24
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -17,7 +17,7 @@
            ljmp   _quicksort
     ~~~
    
    -which prevents the stop and thus the false negative.
    +which prevents the stop and thus also prevents the false negative.
    
     Is this the intended behaviour of selfjump? If so, the regression tests should not use.
     If not, then maybe it should also test for stack usage reduction.
    
     
  • Maarten Brock

    Maarten Brock - 2023-08-24
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -19,5 +19,5 @@
    
     which prevents the stop and thus also prevents the false negative.
    
    -Is this the intended behaviour of selfjump? If so, the regression tests should not use.
    +Is this the intended behaviour of selfjump_stop? If so, the regression tests should not use.
     If not, then maybe it should also test for stack usage reduction.
    
     
  • Daniel Drotos

    Daniel Drotos - 2023-08-29

    Selfjump_stop option is used in MCS51 tests only. Is there any reason for it, or can it be turned off?

    I'm going to introduce a new run mode in uCsim which is called "emulation", instead of "simulation". It skips some debugging features, including event breaks and selfjump_stop option, so it can be a little bit faster. The whole regtest stuff was able to run in this mode on my machine, so I think that selfjump-stop option is not really needed.

     
  • Maarten Brock

    Maarten Brock - 2023-08-29

    Well, you introduced it yourself in [r13426] to speed up the exit of broken programs:
    "Faster exit from broken mcs51-xstack-auto program simulation"

    The peephole optimizer which is normally used during compilation of the regression tests changes the problematic program flow and thus prevents triggering the selfjump_stop condition.

    But the question is more if you really want to stop when a recursive call returns to itself while properly unwinding the stack.

    I have not checked, but would it also stop on a DJNZ to itself? This is also a jump to itself, but not indefinitely. It's a perfect way to introduce some delay.

    And then there are JB/JNB and CJNE direct/CJNE @Ri which could be used to wait for a volatile flag from an interrupt or for an sbit/sfr change.

    So in my opinion this option of the simulator should not trigger on a RET or DJNZ instruction.
    I am not certain about those flag situations.
    And it seems valid for all other call and jump instructions.

     

    Related

    Commit: [r13426]


    Last edit: Maarten Brock 2024-11-14
  • Daniel Drotos

    Daniel Drotos - 2024-05-30

    Ticket moved from /p/sdcc/bugs/3637/

    Can't be converted:

    • _category: Simulator
     
  • Daniel Drotos

    Daniel Drotos - 2024-11-02
    • status: open --> pending
    • assigned_to: Daniel Drotos
    • Group: -->
     
  • Maarten Brock

    Maarten Brock - 2024-11-14

    I see that you have set this to pending. But what is it pending on?
    Have you modified anything that I should test?
    Should I clarify more what I think needs to be changed?

    The whole regtest stuff was able to run in this mode on my machine, so I think that selfjump-stop option is not really needed.

    But have you also run them with --no-peep ?

    Or do you mean that the selfjump_stop option will disappear and that a real selfjump bug will have to be detected by the timeout mechanism?

     

Log in to post a comment.

MongoDB Logo MongoDB