JFFS3 & performance

Jörn Engel joern at wohnheim.fh-wedel.de
Wed Dec 22 11:08:10 EST 2004


On Wed, 22 December 2004 15:25:23 +0000, Artem B. Bityuckiy wrote:
> 
> Jorn, Could you please provide adler32r?

I tried.  Hope this is correct.

#define BASE 65521L		/* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */

#define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
#define DO16(buf)   DO8(buf,0); DO8(buf,8);

/* ========================================================================= */
uint32_t adler32r(uint32_t adler, const char *buf, size_t len)
{
	unsigned long s1 = adler & 0xffff;
	unsigned long s2 = (adler >> 16) & 0xffff;
	int k;

	if (!buf)
		return 1L;

	buf += len;
	while (len > 0) {
		k = len < NMAX ? len : NMAX;
		len -= k;
		while (k >= 16) {
			buf -= 16;
			DO16(buf);
			k -= 16;
		}
		if (k != 0)
			do {
				s1 += *--buf;
				s2 += s1;
			} while (--k);
		s1 %= BASE;
		s2 %= BASE;
	}
	return (s2 << 16) | s1;
}


Jörn

-- 
Don't patch bad code, rewrite it.
-- Kernigham and Pike, according to Rusty




More information about the linux-mtd mailing list