Menu

#2672 sdcc revision 10077 mcs51 problem

open
nobody
None
MCS51
5
2018-01-06
2017-10-17
No

Hi there!

There is something very wrong with the last commit.

The AT89LP51 that I'm using resets after executing the following code:

exp = ((float)curr_max_val - data->cfg.inv.ovl.step1) / data->cfg.inv.ovl.exp_div;
ovl_acc += expf(exp);

I can provide the whole project (it is quite big) and it is compiled like this:

/opt/sdcc/bin/sdcc -I./include -I../c51_core_libs/include -DSINE33_SFC -c -mmcs51 --verbose --model-large --opt-code-speed -c source/sp_sfc_process_analog_data.c -o obj/sp_sfc_process_analog_data.rel
sdcc: Calling preprocessor...
sdcc: sdcpp -nostdinc -Wall -std=c11 -I./include -I../c51_core_libs/include -DSINE33_SFC -obj-ext=.rel -D__SDCC_CHAR_UNSIGNED -D__SDCC_MODEL_LARGE -D__SDCC_FLOAT_REENT -D__SDCC=3_6_9 -D__SDCC_VERSION_MAJOR=3 -D__SDCC_VERSION_MINOR=6 -D__SDCC_VERSION_PATCH=9 -DSDCC=369 -D__SDCC_REVISION=10070 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__=1 -D__STDC_NO_THREADS__=1 -D__STDC_NO_ATOMICS__=1 -D__STDC_NO_VLA__=1 -D__STDC_ISO_10646__=201409L -D__STDC_UTF_16__=1 -D__STDC_UTF_32__=1 -isystem /opt/sdcc/bin/../share/sdcc/include/mcs51 -isystem /usr/local/share/sdcc/include/mcs51 -isystem /opt/sdcc/bin/../share/sdcc/include -isystem /usr/local/share/sdcc/include source/sp_sfc_process_analog_data.c
sdcc: Generating code...

The same code, compiled with a yesterday sdcc snapshot, works flawless.

Discussion

  • Philipp Klaus Krause

    While there have been lots of changes in SDCC recently, most shouldn't affect mcs51 at all.
    After the 11th of October until now I only see two changes ([r10073] and [r10070], both on the 16th of October) that would affect mcs51.

    Philipp

    P.S.: [r10073] affects floating-point comparisons. Does your program use float?

     

    Last edit: Philipp Klaus Krause 2017-10-18
    • Cristiano Rodrigues

      I was thinking that it was "Improve handling of variables on stack in return." fault (because the code is big, it is compiled with the large memory model and I could be in the stack size limit)
      but now that you mention the float comparison...

      yes, I'm using floats

      exp = ((float)curr_max_val - data->cfg.inv.ovl.step1) / data->cfg.inv.ovl.exp_div;
      ovl_acc += expf(exp);
      printf("exp: %u acc: %u\n", (uint16_t)(exp * 10), (uint16_t)ovl_acc);
      if(ovl_acc >= 24192.0)  //it is for 50ms Cycle
      {
                  ovl_acc = 0;
                  data->flags.log_error.last = ERROR_INV_OVL;
                  data->flags.log_error.save = true;
      
                  data->flags.gpu_state = SFC_ERROR;
                  break;
      }
      

      almost everything is float in there. I'm able to print the printf, that is precisely before a float comparasion, and right after that,
      the cpu resets... at least, that printf is the last one that I see before the reset.

       

      Last edit: Cristiano Rodrigues 2017-10-18
      • Maarten Brock

        Maarten Brock - 2017-10-18

        You're not compiling with --stack-auto so there are hardly any variables on the stack.

         
      • Philipp Klaus Krause

        [r10074] "Improve handling of variables on stack in return." does not affect not mcs51. The main impact is on gbz80; to a lesser degree z80, z180, tlcs90, r2k and r3ka are affected.

        Philipp

         
    • Maarten Brock

      Maarten Brock - 2017-10-18

      Philipp,

      In [r10073] you also removed LE_OP and GE_OP from SDCCopt.c. Was that intentional?

       
      • Philipp Klaus Krause

        Yes. I found that SDCC does not emit them for float (and even though the infrastructure for converting them to support function calls was there in SDCCopt.c, there were no such support functions in the library, so it wouldn't have worked anyway).

        Philipp

         
  • Philipp Klaus Krause

    Can you provide a small, compileable example that reproduces the issue?

    Philipp

     
  • Cristiano Rodrigues

    I'm trying to create a small example but in that small example I'm not being able to recreate what is happening in the big project.

     
  • Cristiano Rodrigues

    Hi there!
    It is just to say the problem still occurs.
    As soon as the following condition is true, bad things happen:

                    else if(data->in_data.an_data.curr_out.A > data->cfg.inv.ovl.step1 || data->in_data.an_data.curr_out.B > data->cfg.inv.ovl.step1 || data->in_data.an_data.curr_out.C > data->cfg.inv.ovl.step1)
                    {
                        curr_max_val = data->in_data.an_data.curr_out.A;
    
                        if(data->in_data.an_data.curr_out.B > curr_max_val)
                        {
                            curr_max_val = data->in_data.an_data.curr_out.B;
                        }
                        if(data->in_data.an_data.curr_out.C > curr_max_val)
                        {
                            curr_max_val = data->in_data.an_data.curr_out.C;
                        }
    
                        //printf("div: %u\n", (uint16_t)(data->cfg.inv.ovl.exp_div * 10));
                        if(curr_max_val > data->cfg.inv.ovl.step2)
                        {
                            exp = (((float)curr_max_val - data->cfg.inv.ovl.step1) / data->cfg.inv.ovl.exp_div) * 1.145;
                        }
                        else
                        {
                            exp = ((float)curr_max_val - data->cfg.inv.ovl.step1) / data->cfg.inv.ovl.exp_div;
                        }
    
                        ovl_acc += expf(exp);
    
                        //printf("exp:%u acc:%u\n", (uint16_t)(exp * 10), (uint16_t)ovl_acc);
    
                        if(ovl_acc >= 24192.0)  //it is for 50ms Cycle
                        {
                            data->flags.log_error.last = ERROR_INV_OVL;
                            data->flags.log_error.save = true;
    
                            data->flags.sfc_state = SFC_ERROR;
                            break;
                        }
                        else if(data->flags.sfc_state != SFC_INV_RUNNING_OVL)
                        {
                            data->flags.last_event = EVENT_INV_RUN_OVL_START;
                            data->flags.sfc_state = SFC_INV_RUNNING_OVL;
                        }
                    }
    

    BUT if compile without --opt-code-speed, it works again.

    I have all the code attached, in case you want to have a look

     

    Last edit: Cristiano Rodrigues 2018-01-06

Log in to post a comment.

MongoDB Logo MongoDB