Am 20.02.2018 um 20:14 schrieb Eric Rullens: > Long time MCS51 and more recently STM8 user here. > > For STM8 I've noticed that "random" code is generated for the following: > > -------------------------------- > int sum(int a, int b, unsigned long d) > { > return a + b / d; > } > > int main(void) > { > return sum(1, 2, 4); > } > -------------------------------- > > This is using the 3.7.0 #10228 snapshot on Windows 10.0.16299.125. > > Compiling ten times as follows, and generating a checksum on the resulting > images: > > -------------------------------- > sdcc -mstm8 test.c > md5sum test.ihx > -------------------------------- > > 034855cad4e8eb12209ad31c9ccd7f9b *test.ihx 034855cad4e8eb12209ad31c9ccd7f9b > *test.ihx > 069a62e6676bd940cb01a36ab3a7f787 *test.ihx > 069a62e6676bd940cb01a36ab3a7f787 *test.ihx 034855cad4e8eb12209ad31c9ccd7f9b > *test.ihx 034855cad4e8eb12209ad31c9ccd7f9b *test.ihx > 069a62e6676bd940cb01a36ab3a7f787 *test.ihx 034855cad4e8eb12209ad31c9ccd7f9b > *test.ihx 034855cad4e8eb12209ad31c9ccd7f9b *test.ihx > 069a62e6676bd940cb01a36ab3a7f787 *test.ihx > > The differences occur just after the call to divulong, as can be seen in the > assembly code from runs 2 and 3. > > The assembly code for "sum" from run 2: > > -------------------------------- > ; test.c: 1: int sum(int a, int b, unsigned long d) > ; ----------------------------------------- > ; function sum > ; ----------------------------------------- > _sum: > sub sp, #6 > ; test.c: 3: return a + b / d; > ldw y, (0x0b, sp) > clrw x > tnzw y > jrpl 00103$ > decw x > 00103$: > ld a, (0x10, sp) > push a > ld a, (0x10, sp) > push a > ld a, (0x10, sp) > push a > ld a, (0x10, sp) > push a > pushw y > pushw x > call __divulong > addw sp, #8 > ldw (0x03, sp), y > ldw y, (0x09, sp) > ldw (0x01, sp), y > addw x, (0x01, sp) > ; test.c: 4: } > addw sp, #6 > ret > -------------------------------- > > The assembly code for "sum" from run 3: > > -------------------------------- > ; test.c: 1: int sum(int a, int b, unsigned long d) > ; ----------------------------------------- > ; function sum > ; ----------------------------------------- > _sum: > sub sp, #6 > ; test.c: 3: return a + b / d; > ldw y, (0x0b, sp) > clrw x > tnzw y > jrpl 00103$ > decw x > 00103$: > ld a, (0x10, sp) > push a > ld a, (0x10, sp) > push a > ld a, (0x10, sp) > push a > ld a, (0x10, sp) > push a > pushw y > pushw x > call __divulong > addw sp, #8 > ldw (0x01, sp), y > ldw y, (0x09, sp) > ldw (0x05, sp), y > addw x, (0x05, sp) > ; test.c: 4: } > addw sp, #6 > ret > -------------------------------- > > It looks like this may have been reported before for MCS51 as well: > > https://sourceforge.net/p/sdcc/mailman/message/35171634/ > > But for the example above I don't see the issue for MCS51. > > Any thoughts? > > Eric Rullens >
I suggest to file a bug report. Having sich a relatively small reproducer could help track down the issue. Philipp ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user