Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Mar 2005 00:18:07 -0800
From:      Colin Percival <cperciva@freebsd.org>
To:        Peter Jeremy <PeterJeremy@optushome.com.au>
Cc:        cvs-all@freebsd.org
Subject:   Re: cvs commit: src/lib/libmd Makefile sha256.3 sha256.h sha256c.c shadriver.c src/sbin/md5 Makefile md5.c
Message-ID:  <423002BF.5010202@freebsd.org>
In-Reply-To: <20050310065547.GA16318@cirb503493.alcatel.com.au>
References:  <200503091923.j29JN4Ti063868@repoman.freebsd.org> <422F50A6.907@criticalmagic.com> <422F55C6.3000207@freebsd.org> <20050310065547.GA16318@cirb503493.alcatel.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
Peter Jeremy wrote:
> Three almost,
> but not totally, identical versions of foo() means three times as much
> maintenance effort and a non-zero probability of someone forgetting
> to make a change to one of the versions.

Absolutely -- but this isn't particularly relevant for hash functions,
since hash functions don't get upgraded to newer versions or have new
features added.  (Ok, they do, but they get a new name and the old
versions are left unchanged.)

>> These hash
>>functions are designed for 32-bit processors in a manner which makes it
>>fairly hard for the compiler to get things wrong.
> 
> It's not so much getting things wrong as being able to get the right
> answer quicker.  It may not be obvious to the compiler that
> 	a = (a << 5) | (a >> 27);
> can be replaced by
> 	rotl	a,5

It is obvious to the compiler.  That's a very common idiom and one of
the first things that compilers recognize.  Gcc gets this right, and
I doubt many people are going to be using a compiler which is worse
at optimization than gcc.

Colin Percival



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?423002BF.5010202>