]> bbs.cooldavid.org Git - net-next-2.6.git/commit - drivers/staging/dream/camera/s5k3e2fx.c
Staging: s5k3e2fx.c: simplify complexity by factoring
authorJustin Madru <jdm64@gawab.com>
Fri, 18 Dec 2009 23:52:53 +0000 (15:52 -0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 4 Mar 2010 00:42:33 +0000 (16:42 -0800)
commit8c172dde41db666f7a5f3bb62205da017e23c0ec
treeee8f478264aa66e738df8b92cccedecb309816af
parent096417e087a391dc78780cc1843369a521635522
Staging: s5k3e2fx.c: simplify complexity by factoring

the code was looping, setting s_move[i] to the following calculations

if (actual_step>= 0)
         s_move[i] = ((((i + 1) * gain + 0x200) - (i * gain + 0x200)) / 0x400);
else
         s_move[i] = ((((i + 1) * gain - 0x200) - (i * gain - 0x200)) / 0x400);

but, this code reduces to the expression
s_move[i] = gain>>  10;

The reason for the complexity was to generate a step function with
integer division and rounding to land on specific values. But these calculations
can be simplified to the following code:

gain = ((actual_step<<  10) / 5)>>  10;
for (i = 0; i<= 4; i++)
s_move[i] = gain;

Signed-off-by: Justin Madru<jdm64@gawab.com>
Reviewed-by: Ray Lee<ray-lk@madrabbit.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/dream/camera/s5k3e2fx.c