Comment 2 for bug 1502611

Revision history for this message
Strntydog (strntydog) wrote :

Hmm,

I was playing with test6, which just assigns values consecutively to a byte array. If i make the base address low, 0x10 in my test case, M0 suddenly compiles code which I would think it should :

00000134 <test7>:
 134: 2310 movs r3, #16
 136: 22ff movs r2, #255 ; 0xff
 138: 701a strb r2, [r3, #0]
 13a: 3a01 subs r2, #1
 13c: 705a strb r2, [r3, #1]
 13e: 3a01 subs r2, #1
 140: 709a strb r2, [r3, #2]
 142: 3a01 subs r2, #1
 144: 70da strb r2, [r3, #3]
 146: 3a0e subs r2, #14
 148: 711a strb r2, [r3, #4]
 14a: 3a11 subs r2, #17
 14c: 721a strb r2, [r3, #8]
 14e: 3a11 subs r2, #17
 150: 731a strb r2, [r3, #12]
 152: 4770 bx lr

But strangely M3 code generation goes bad :

000000b8 <test7>:
  b8: 22ff movs r2, #255 ; 0xff
  ba: 2310 movs r3, #16
  bc: 701a strb r2, [r3, #0]
  be: 22fe movs r2, #254 ; 0xfe
  c0: 2311 movs r3, #17
  c2: 701a strb r2, [r3, #0]
  c4: 22fd movs r2, #253 ; 0xfd
  c6: 2312 movs r3, #18
  c8: 701a strb r2, [r3, #0]
  ca: 22fc movs r2, #252 ; 0xfc
  cc: 2313 movs r3, #19
  ce: 701a strb r2, [r3, #0]
  d0: 22ee movs r2, #238 ; 0xee
  d2: 2314 movs r3, #20
  d4: 701a strb r2, [r3, #0]
  d6: 22dd movs r2, #221 ; 0xdd
  d8: 2318 movs r3, #24
  da: 701a strb r2, [r3, #0]
  dc: 22cc movs r2, #204 ; 0xcc
  de: 231c movs r3, #28
  e0: 701a strb r2, [r3, #0]
  e2: 4770 bx lr

BUT, if i move the start address further down in memory to say 0x200:

The M0 code generation changes to this :
00000134 <test7>:
 134: 2380 movs r3, #128 ; 0x80
 136: 22ff movs r2, #255 ; 0xff
 138: 009b lsls r3, r3, #2
 13a: 701a strb r2, [r3, #0]
 13c: 4b07 ldr r3, [pc, #28] ; (15c <test7+0x28>)
 13e: 3a01 subs r2, #1
 140: 701a strb r2, [r3, #0]
 142: 4b07 ldr r3, [pc, #28] ; (160 <test7+0x2c>)
 144: 3a01 subs r2, #1
 146: 701a strb r2, [r3, #0]
 148: 4b06 ldr r3, [pc, #24] ; (164 <test7+0x30>)
 14a: 3a01 subs r2, #1
 14c: 701a strb r2, [r3, #0]
 14e: 3a0e subs r2, #14
 150: 705a strb r2, [r3, #1]
 152: 3a11 subs r2, #17
 154: 715a strb r2, [r3, #5]
 156: 3a11 subs r2, #17
 158: 725a strb r2, [r3, #9]
 15a: 4770 bx lr
 15c: 00000201 .word 0x00000201
 160: 00000202 .word 0x00000202
 164: 00000203 .word 0x00000203

And suddenly the code generator can calculate address 0x200 without the literal table, but cant calculate 0x201, 0x202 or 0x203 but once its got 0x203, it can calculate 0x204, 0x208 and 0x20C.

Something very strange is going on with the M0 code generation for these sequences.