Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/06/09 20:47
Read: times


 
#163179 - re-written the loop in C
Responding to: ???'s previous message
This is the code generated by the RealView compiler for a re-written loop. It takes 43.57us at 58.9MHz

   165:         unsigned char *pport, *pbuf; 
   166:         unsigned int i; 
   167:         for (i = 256, pport = &FIO_PIN[3], pbuf = buf; i--; ) 
0x00000610  E3A09C01  MOV       R9,#0x00000100
0x00000614  E59F73BC  LDR       R7,[PC,#0x03BC]
0x00000618  E28D8000  ADD       R8,R13,#0x00000000
0x0000061C  EA000001  B         0x00000628
   168:             *pport = *pbuf++; 
   169:  
0x00000620  E4D80001  LDRB      R0,[R8],#0x0001
0x00000624  E5C70000  STRB      R0,[R7]
0x00000628  E1B00009  MOVS      R0,R9
0x0000062C  E2499001  SUB       R9,R9,#0x00000001
0x00000630  1AFFFFFA  BNE       0x00000620

 


This is the output from the Keil compiler. It takes 61.02us so does not satisfy Richard's criterion.

   165:         unsigned char *pport, *pbuf; 
   166:         unsigned int i; 
   167:         for (i = 256, pport = &FIO_PIN[3], pbuf = buf; i--; ) 
   168:             *pport = *pbuf++; 
0x000003F0  4BB1      LDR       R3,[PC,#0x02C4]
0x000003F2  4AB2      LDR       R2,[PC,#0x02C8]
0x000003F4  A900      ADD       R1,SP,#0x0000
0x000003F6  1C08      ADD       R0,R1,#0
0x000003F8  E004      B         0x00000404
0x000003FA  1C05      ADD       R5,R0,#0
0x000003FC  3001      ADD       R0,#0x01
0x000003FE  782E      LDRB      R6,[R5,#0x00]
0x00000400  1C15      ADD       R5,R2,#0
0x00000402  702E      STRB      R6,[R5,#0x00]
0x00000404  1C1D      ADD       R5,R3,#0
0x00000406  3B01      SUB       R3,#0x01
0x00000408  2D00      CMP       R5,#0x00
0x0000040A  D1F6      BNE       0x000003FA

 


As a comparison this code takes 5641 cycles with the C51 compiler (169us with Richards super 8051). So I can quite see why Richard is so disparaging about 8051 C compilers.

    unsigned char xdata buf[256], *pbuf; 
    unsigned int i; 
    for (i = 0; i < 256; ) 
        P1 = buf[i++]; 

 


Using pointers is incredibly slow. Which reinforces the comments about bit manipulations being good on an 8051, and strings, arithmetic etc better on other mcus.

David.


List of 76 messages in thread
TopicAuthorDate
NXP P89LPC936 Auxilary RAM            01/01/70 00:00      
   Compiler Cannot Save the Day At Runtime            01/01/70 00:00      
      I found it.....            01/01/70 00:00      
         Incorrect!            01/01/70 00:00      
            To be fair,...            01/01/70 00:00      
               Its good info to know...            01/01/70 00:00      
   how is it done in C?            01/01/70 00:00      
   Maybe you should try doing it ASM!            01/01/70 00:00      
      You should start a new thread on that!            01/01/70 00:00      
      Not in this case!            01/01/70 00:00      
         A compiler should support ALL MCU features ...            01/01/70 00:00      
            A compiler should translate the language            01/01/70 00:00      
               Still C - just not strict.            01/01/70 00:00      
            I didn't say that!            01/01/70 00:00      
               It is not that clean and clear            01/01/70 00:00      
                  Deviants are deviant            01/01/70 00:00      
                     Keil and SDCC need no macros ...            01/01/70 00:00      
                        Are you sure?            01/01/70 00:00      
                     That's probably correct, but ...            01/01/70 00:00      
                        A C compiler can map the hardware quite well            01/01/70 00:00      
                           compiler vendors are looking at the new processors            01/01/70 00:00      
                              I once mentioned that ...            01/01/70 00:00      
                           It's not what I'd choose, but it is a matter of perefernce            01/01/70 00:00      
                              As flash gets bigger, the code steps do too.            01/01/70 00:00      
                              Still not needed for other architectures            01/01/70 00:00      
                                 We will have to agree to disagree ... I guess            01/01/70 00:00      
                                    Which single-clocker is cheaper than an ARM?            01/01/70 00:00      
                                       RE: Which single-clocker is cheaper than an ARM?            01/01/70 00:00      
                                       differs considerably from the classic microcontroller?            01/01/70 00:00      
                                       Horses for courses            01/01/70 00:00      
                                          Always start each project by scanning the market            01/01/70 00:00      
                                             On that we can agree            01/01/70 00:00      
                                          Maybe, but what are they comparing?            01/01/70 00:00      
                                             Did you actually look?            01/01/70 00:00      
                                                Yes, I did.            01/01/70 00:00      
                                       it's a tradeoff            01/01/70 00:00      
                                          Is it 2006 already?            01/01/70 00:00      
                                             Really?            01/01/70 00:00      
                                                that's outright silly            01/01/70 00:00      
                                                   Maybe ... which is why it is not yet the case            01/01/70 00:00      
                                                      the eyes of the beholder            01/01/70 00:00      
                                                         Look at it from another viewpoint for a moment            01/01/70 00:00      
                                          RE: I'm not the one to ask about IC prices            01/01/70 00:00      
                                             doesn't mean I'm totally in the dark            01/01/70 00:00      
                                                Richard Erlacher has left the planet            01/01/70 00:00      
                                                   Maybe Andy's the one who's lost            01/01/70 00:00      
                                                      I cannot believe you even looked at ARM            01/01/70 00:00      
                                                         It's all relative            01/01/70 00:00      
                                                            Price doesn't directly follow processor size            01/01/70 00:00      
                                                            What about performance?            01/01/70 00:00      
                                                         Be specific please.            01/01/70 00:00      
                                                            You can use your own supplier            01/01/70 00:00      
                                                               Your test simulates as 41.04us            01/01/70 00:00      
                                                                  RE: ARM compiles do not like byte-addressing            01/01/70 00:00      
                                                                     A typo on my part            01/01/70 00:00      
                                                                        Case of full unroll            01/01/70 00:00      
                                                                           ... and what does THAT ARM MCU cost?            01/01/70 00:00      
                                                                              WHO CARES            01/01/70 00:00      
                                                                                 Absolutely true!            01/01/70 00:00      
                                                                              $5 or lower            01/01/70 00:00      
                                                                                 My Simulation times were wrong.            01/01/70 00:00      
                                                                                    67% of your loop was your loop            01/01/70 00:00      
                                                                                    re-written the loop in C            01/01/70 00:00      
                                                                                       Try without loop counter            01/01/70 00:00      
                                                                                          You're right!            01/01/70 00:00      
                                                                                             Similar trick with ARM7 would require 66.67MHz            01/01/70 00:00      
                                                                                             60ns with no store instruction.            01/01/70 00:00      
                                                                                                25% speedup            01/01/70 00:00      
                                                                                                   Actually, I found the for loop faster.            01/01/70 00:00      
                                                                                                      Compiler setting?            01/01/70 00:00      
                                                                                                         I made NO optimisation            01/01/70 00:00      
                                                                                                            Avoid variable aliasing if you like high optimization levels            01/01/70 00:00      
                                                                                                               The RealView compiler is very competent            01/01/70 00:00      
                                                                                                                  Yes, caching            01/01/70 00:00      
                                                                                                                  Yes, caching            01/01/70 00:00      
                                                                                                It's much easier with the 8-bit single-clocker            01/01/70 00:00      

Back to Subject List