Subject: Re: sdpmem(4) reporting DDR2 speed/type incorrectly
To: None <current-users@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: current-users
Date: 09/19/2007 13:51:29
On Wed, 19 Sep 2007, David Brownlee wrote:
> 	if (d_clk & 1)
> 	        d_clk = d_clk / 2 + 1;
> 	else
> 	        d_clk /= 2;

(Ignoring the rest of your message) I'd write this part as:

	d_clk = (d_clk + 1) / 2;

which I find much easier to understand ("divide by 2, rounding up"),
and which is much more likely to compile into code without any branch
instructions.  My version yields a different result from yours in the
case where d_clk + 1 results in an overflow, but choice of suitably wide
data types could probably guarantee that that never happens.

--apb (Alan Barrett)