On Monday, 4 November 2013 at 11:21:03 UTC, Iain Buclaw wrote:


For the time being, use gcc-4.9-20131013.tar.bz2 snapshot - that is the last build I've done here (currently all my time is being used up on D
2.064).

Feel free to send patches though (see this two line change here:
http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=02774f2d493655713721ceef4ebfd7d0c8fb1d8d;hp=2043dfcce183f27ffe84a339da8b75aec20d3c33#patch21).
:-)

Ok, I check that later

Meanwhile, a short description of my original problem

I want to send characters of a string to uart
These are member functions of my uart struct. The full source is https://bitbucket.org/timosi/minlibd/src/540e52150644719682f37900db1c298902e4d8c9/tools/main/uart.d?at=default

   // send a byte to the uart
   void send(int t) {
     while ((sr&0x80)==0)
     {
     }
     dr=t;
   }


  // send a string or char buffer
  void sendtext(const char[] p) {

     //if (!p) return;  // null pointer test

     foreach (c;p) {
         //if (c==0) break;
         send (c);
     }
  }

The problem is that send is inlined with -O2 such a way that the write is optimized outside of the foreach loop and only the last character is sent.
This works with -O0.

This is the asm
r0 is this, r1 is p and r2 is length of p

 151 00ac 10B4                  push    {r4}
 152 00ae 83B0                  sub     sp, sp, #12
 153 00b0 02AB                  add     r3, sp, #8
 154 00b2 03E90600              stmdb   r3, {r1, r2}
 155 00b6 009C                  ldr     r4, [sp]
 156 00b8 019A                  ldr     r2, [sp, #4]
 157 00ba 4CB1                  cbz     r4, .L11       zero length test
 158 00bc 4368                  ldr     r3, [r0, #4]
 159 00be 1444                  add     r4, r4, r2
                 At this point r4 = end address
                               r2 = p
                 Foreach begins here
 160                    .L13:
 161 00c0 12F8011B              ldrb    r1, [r2], #1     get c

 162                    .L15:                   First part of send here
 163 00c4 0368                  ldr     r3, [r0]     status reg test
 164 00c6 1B06                  lsls    r3, r3, #24  works now!
 165 00c8 FCD5                  bpl     .L15

 166 00ca A242                  cmp     r2, r4   Here in the middle
 167 00cc F8D1                  bne     .L13     the test for end of the loop

 168 00ce 4160                  str     r1, [r0, #4] Write (dr=t) is here,
 169                    .L11:                        AFTER the loop

 170 00d0 03B0                  add     sp, sp, #12
 171                            

 172 00d2 5DF8044B              ldr     r4, [sp], #4
 173 00d6 7047                  bx      lr


Reply via email to