Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Optimization of Capture Routine

Optimization of Capture Routine

2004-01-31 by capiman@t-online.de

Hello,
i want to read in 1 byte multiple times from the port pins as fast as possible:
Currently i have the following C code:
unsigned char Data[60000];
void CaptureBuffer()
{
unsigned char *ptr = &Data[0];
unsigned char *ptrend = &Data[60000];

while(ptr < ptrend)
{
(*ptr) = (IOPIN >> LA_D0_BIT) & 0xff;
ptr++;
; }
}
When i compile it with gcc and option -O3, i can capture with around 3,9 MBytes/sec.
Avoiding the shift (by using P0.0 - P0.7) gives me 4,2 MBytes/sec.
Leaving out the (*ptr) = (IOPIN...) instruction gives me 11,8 MBytes/sec, but no more functionality :-)
Can i improve the speed with inline assembler ? Produced assembler code already looks very compact...
.L142:
ldr ip, [r0, #0]
strb ip, [r2], #1
cmp r2, r1
bcc .L142
Are there any other tricks ?
Environment: LPC2106, with 14,745 MHz, M = 4, P = 2, VPBDIV = 1, MAMTIM = 3 (same with not allowed value 2), MAMCR = 1 or 2
I tried overclocking with M = 5 (should give me around 75 MHz), but even there speed doesn't increase anymore ???
UART speed was changed, but not CPU speed.
BTW: Is the time distance between the measured bytes always the same ? Or are e.g. odd addresses slower then even addresses ?
Greetings,
Martin

Re: [lpc2100] Optimization of Capture Routine

2004-02-01 by Ben Dooks

On Sat, Jan 31, 2004 at 09:01:05PM +0100, capiman@... wrote:
> Hello,
> 
> i want to read in 1 byte multiple times from the port pins as fast as possible:
> Currently i have the following C code:
> 
> unsigned char Data[60000];
> 
> void CaptureBuffer()
> {
>     unsigned char *ptr = &Data[0];
>     unsigned char *ptrend = &Data[60000];
>     
>     while(ptr < ptrend)
>     {
>         (*ptr) = (IOPIN >> LA_D0_BIT) & 0xff;
>         ptr++;
>     }
> }
> 
> When i compile it with gcc and option -O3, i can capture with around 3,9 MBytes/sec.
> Avoiding the shift (by using P0.0 - P0.7) gives me 4,2 MBytes/sec. 
> Leaving out the (*ptr) = (IOPIN...) instruction gives me 11,8 MBytes/sec, but no more functionality :-)
> 
> Can i improve the speed with inline assembler ? Produced assembler code already looks very compact...
> 
> .L142:
>  ldr ip, [r0, #0]
>  strb ip, [r2], #1
>  cmp r2, r1
>  bcc .L142
> 
> Are there any other tricks ?

unrolling the loop a bit may help, as it reduces the number of branch
instructions needed.

-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

Re: [lpc2100] Optimization of Capture Routine

2004-02-03 by James Dabbs

With something this tight, perhaps locating this routine in RAM could also
help a little bit?  The FLASH is "near 0 waitstate" but it is more like
burst ROM and not quite 0 waitstate..particularly with that branch.  I don't
have a feel yet for how this translates into practical application, but it's
an idea.

----- Original Message -----
From: "Ben Dooks" <ben@...>
To: <lpc2100@yahoogroups.com>
Sent: Sunday, February 01, 2004 5:55 AM
Subject: Re: [lpc2100] Optimization of Capture Routine


> On Sat, Jan 31, 2004 at 09:01:05PM +0100, capiman@... wrote:
> > Hello,
> >
> > i want to read in 1 byte multiple times from the port pins as fast as
possible:
> > Currently i have the following C code:
> >
> > unsigned char Data[60000];
> >
> > void CaptureBuffer()
> > {
> >     unsigned char *ptr = &Data[0];
> >     unsigned char *ptrend = &Data[60000];
> >
> >     while(ptr < ptrend)
> >     {
> >         (*ptr) = (IOPIN >> LA_D0_BIT) & 0xff;
> >         ptr++;
> >     }
> > }
> >
> > When i compile it with gcc and option -O3, i can capture with around 3,9
MBytes/sec.
> > Avoiding the shift (by using P0.0 - P0.7) gives me 4,2 MBytes/sec.
> > Leaving out the (*ptr) = (IOPIN...) instruction gives me 11,8
MBytes/sec, but no more functionality :-)
> >
> > Can i improve the speed with inline assembler ? Produced assembler code
already looks very compact...
Show quoted textHide quoted text
> >
> > .L142:
> >  ldr ip, [r0, #0]
> >  strb ip, [r2], #1
> >  cmp r2, r1
> >  bcc .L142
> >
> > Are there any other tricks ?
>
> unrolling the loop a bit may help, as it reduces the number of branch
> instructions needed.
>
> --
> Ben
>
> Q:      What's a light-year?
> A:      One-third less calories than a regular year.
>
>
>
>
> Yahoo! Groups Links
>
> To visit your group on the web, go to:
>  http://groups.yahoo.com/group/lpc2100/
>
> To unsubscribe from this group, send an email to:
>  lpc2100-unsubscribe@yahoogroups.com
>
> Your use of Yahoo! Groups is subject to:
>  http://docs.yahoo.com/info/terms/
>
>
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.