Shop OBEX P1 Docs P2 Docs Learn Events
cognew return value optimizer error — Parallax Forums

cognew return value optimizer error

Mike PetryMike Petry Posts: 14
edited 2012-05-28 19:34 in Propeller 1
I ran into an issue where the return value of cognew appeared in error. It popped up working on a port of Chip's VGA_HiRes_Text.spin code. I traced it back to an optimizer issue -Os vs. -O0. I simplified it to the attached example of cognewing two instances of a .DAT consisting of a simple loop. In the -O0 case, I get back the expected "1 2" case. In the -Os it gives back "1 1". It seems that the definition of the built-in needs to be marked as being volatile so the optimizer will not try to be so helpful.

extern uint32_t binary_cogcode_dat_start[];


i = cognew((uint32_t) binary_cogcode_dat_start, (uint32_t)0);
printf("%d\n",i);


j = cognew((uint32_t) binary_cogcode_dat_start, (uint32_t)0);
printf("%d\n",j);

cogopt.zip

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2012-05-27 08:14
    I looked at the generated assembly code, and it does look like the optimizer is using the return value from the first cognew for the second cognew. You could work around this issue by putting the cognew in a seperate function as follows:
    int CogNew(uint32_t arg1, uint32_t arg2)
    {
        return cognew(arg1, arg2);
    }
    
  • ersmithersmith Posts: 6,097
    edited 2012-05-28 15:35
    There was indeed a bug in the definition of coginit. Thanks for pointing this out, Mike. Dave's suggested work-around is a good temporary fix, and I've checked in a change so that future builds will not require this.

    Eric
  • Mike PetryMike Petry Posts: 14
    edited 2012-05-28 19:34
    Thanks for checking in a fix.
Sign In or Register to comment.