strcpy() is very Low speed!!!

Post your requests and ideas on the future development of mikroC PRO for AVR.
Post Reply
Author
Message
jet_media
Posts: 39
Joined: 18 Apr 2012 09:13
Location: Iran

strcpy() is very Low speed!!!

#1 Post by jet_media » 10 Apr 2015 01:21

in mikrobasic Avr :

program MyProject

main:

dim s as char[5] data
dim s2 as char[5] data
s2="Hello"
s=s2
ddra=0
end.

in mikrobasic all code run in 96 Cpu Clock Cycle
'-------------
But in Mikroc Avr :

void main()
{
char s[6];
char s2[6]="Hello";
strcpy(s,s2);
ddra=0;
}

in mikroC All code run in 187 Cpu Clock Cycle!!!
'------------

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: strcpy() is very Low speed!!!

#2 Post by marina.petrovic » 14 Apr 2015 10:53

Hi,

Indeed for execution of the strcpy() routine compiler "perform" several steps.
If you take a look at listing file, you can see something like:

Code: Select all

;LedBlinking.c,30 ::                 strcpy(s,s2);
0x0094        0x922F            PUSH       R2
0x0096        0x923F            PUSH       R3
0x0098        0x924F            PUSH       R4
0x009A        0x925F            PUSH       R5
0x009C        0xE6B0            LDI        R27, lo_addr(_s2+0)
0x009E        0x2E4B            MOV        R4, R27
0x00A0        0xE0B0            LDI        R27, hi_addr(_s2+0)
0x00A2        0x2E5B            MOV        R5, R27
0x00A4        0xE6B6            LDI        R27, lo_addr(_s+0)
0x00A6        0x2E2B            MOV        R2, R27
0x00A8        0xE0B0            LDI        R27, hi_addr(_s+0)
0x00AA        0x2E3B            MOV        R3, R27
0x00AC        0xDFD8            RCALL      _strcpy+0
I will certainly pass your suggestion to my colleagues from Software Department to consider to implement some quicker routine in our compilers.

Best regards,
Marina

jet_media
Posts: 39
Joined: 18 Apr 2012 09:13
Location: Iran

Re: strcpy() is very Low speed!!!

#3 Post by jet_media » 16 Apr 2015 00:14

HI,

suggestion!


//S=S2
//this is Low speed===>strcpy(s,s2);

//but is fastest... :D :
r30= ((unsigned int)(&s2)); //zl From
r31=((unsigned int)(&s2)) >> 8 ; //zh From
r26=((unsigned int)(&s)); //xl To
r27=((unsigned int)(&s)) >> 8; //xh To
asm {
L_loopCS2Ss2:
LD R0, Z+
ST X+, R0
TST R0
BRNE L_loopCS2Ss2
}

:D


and also

EX)
//Set Default value
//this is Low speed===>char s2[10]="aLI201234";

//but is faster :D
const char a[]= "aLI201234" ;
char s2[10];
r30= ((unsigned int)(&a)); //zl 'from
r31=((unsigned int)(&a)) >> 8 ; //zh 'from
r26=((unsigned int)(&s2)); //xl 'to
r27=((unsigned int)(&s2)) >> 8; //xh 'to
asm {
L_loopCS2Ss3:
LPM R0, Z+
ST X+, R0
TST R0
BRNE L_loopCS2Ss3
}

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: strcpy() is very Low speed!!!

#4 Post by marina.petrovic » 16 Apr 2015 10:57

Hi,

Thank you very much for your suggestions, I will pass it to our software developers.

Best regards,
Marina

Post Reply

Return to “mikroC PRO for AVR Wish List”