Skip to content

Commit

Permalink
MPILIB: Deobfuscate mpi_cmp
Browse files Browse the repository at this point in the history
The condition preceding 'return 1;' makes my head hurt. At this point,
we know that u and v have the same sign; if they are negative, they
compare opposite to how their absolute values compare (which
mpihelp_cmp found for us), otherwise cmp itself is the
answer. Negating cmp is ok since mpihelp_cmp returns {-1,0,1};
-INT_MIN==INT_MIN won't bite us.

Signed-off-by: Rasmus Villemoes <[email protected]>
Signed-off-by: David Howells <[email protected]>
Acked-by: Dmitry Kasatkin <[email protected]>
  • Loading branch information
Villemoes authored and dhowells committed Jan 14, 2015
1 parent b2d1965 commit 7fe2129
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/mpi/mpi-cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ int mpi_cmp(MPI u, MPI v)
if (!usize)
return 0;
cmp = mpihelp_cmp(u->d, v->d, usize);
if (!cmp)
return 0;
if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0))
return 1;
return -1;
if (u->sign)
return -cmp;
return cmp;
}
EXPORT_SYMBOL_GPL(mpi_cmp);

0 comments on commit 7fe2129

Please sign in to comment.