🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.image.processing
Article #348

Re: image processing loops: a c programming

#348
From: Al Larson, 1-159 Med Sci, 4-4147
Date: Thu, 13 Aug 1992 12:50
47 lines
2012 bytes
In article 92Aug13120523@vulcan.essex.ac.uk, alien@essex.ac.uk ("Adrian F Clark") writes:
>
>In article <1992Aug10.221247.8016@cfa.harvard.edu> alberto@cfa.harvard.edu (Alberto Accomazzi) writes:
>
>> A far as making the loop tight and fast, if you are only accessing your data
>> in a sequential way, the best thing to do is increment the pointer as in:
>> 
>> function (DATATYPE *data, int xsize, int ysize)
>> {
>>   int x, y;
>>   DATATYPE *dp;
>> 
>>   dp = data;
>>   for (y = 0; y < ysize; y++)
>>     for (x = 0; x < xsize; x++, dp++)
>>       *dp = ...
>> }
>> 
>> Inner loops can be written in a similar fashion.  As far as I know, this
>> will be as fast as you can get.
>
>Actually, you can get just a smidgin faster on most machines:
>
>  dp = data;
>  for (y = 0; y < ysize; y++)
>    for (x = 0; x < xsize; x++)
>      *dp++ = ...
>}
>
>but this is probably even less readable than the other examples
>posted.
>
>

If you compared assembler output, I am pretty sure the code would look
identical for both the above cases. If its speed your after, and who isn't.

dp = data;
xy = ysize*xsize;
while(xy--) *dp++ = ...

==============================================================
Al Larson                      Internet:   agl@mayo.edu
Biomedical Imaging Resource      
Mayo Foundation                Talk:       (507)-284-4147
Rochester, MN 55905            FAX:        (507)-284-1632
===============================================================
Technical Details
Message-ID: <1992Aug13.125001.25563@bmw.mayo.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!zazen!doug.cae.wisc.edu!umn.edu!bru!cobra!agl
References: <ALIEN.92Aug13120523@vulcan.essex.ac.uk>

Show Full Headers
Complete Article Headers
Newsgroups: sci.image.processing
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!zazen!doug.cae.wisc.edu!umn.edu!bru!cobra!agl
From: agl@mayo.edu (Al Larson, 1-159 Med Sci, 4-4147)
Subject: Re: image processing loops: a c programming
Message-ID: <1992Aug13.125001.25563@bmw.mayo.edu>
Sender: newsman@bmw.mayo.edu (/home/bmw/usenet)
Reply-To: agl@mayo.edu
Organization: Mayo Foundation
References: <ALIEN.92Aug13120523@vulcan.essex.ac.uk>
Date: Thu, 13 Aug 92 12:50:01 GMT
Lines: 48