Compare squares instead of square roots.
AbandonedPublic

Authored by marcus on Jul 5 2017, 2:13 PM.

Details

Reviewers
neal
Summary
  • g10/Makefile.am (tofu_source) [USE_TOFU]: Remove sqrtu32.h and sqrtu32.c.
  • g10/sqrtu32.h, g10/sqrtu32.c: Removed files.
  • g10/tofu.c: Compare squares instead of square roots. --

I am not sure you measured the performance of the original code,but I'd think that even using floats and real square root are faster than all thosebranch points.tofu: Compare squares instead of square roots.

I made a quick test: The original code is a factor 11.5 slower than using libm's sqrt(), which in turn is a factor 3.5 slower than using one multiplication on the other side of the comparison. So, all in all this patch microoptimized by a factor of 40, but more importantly, it simplifies the code by a lot.

Test Plan

Stare at the code.

Diff Detail

Repository
rG GnuPG
Branch
arcpatch-D437
Lint
No Linters Available
Unit
No Unit Test Coverage
marcus created this revision.Jul 5 2017, 2:13 PM
marcus updated this revision to Diff 1289.Jul 5 2017, 2:15 PM

Make the variable name more expressive.

Updating D437: How about this? I am not sure you measured the performance of the original code,

but I'd think that even using floats and real square root are faster than all those
branch points.

tofu: Compare squares instead of square roots.

marcus retitled this revision from How about this? I am not sure you measured the performance of the original code, but I'd think that even using floats and real square root are faster than all those branch points. tofu: Compare squares instead of square roots. to Compare squares instead of square roots..Jul 5 2017, 2:16 PM
marcus edited the summary of this revision. (Show Details)
marcus edited the summary of this revision. (Show Details)Jul 5 2017, 5:01 PM
neal added a comment.Jul 6 2017, 1:49 PM

Hi marcus, the original motivation for the separate file was to avoid the use of floats, which, IIRC, Werner didn't want, because floats don't belong in a system tool. Nevertheless, your approach of avoiding a square root all together solves the problem quite nicely.

Did you actually test this? Just looking at the code, I don't see a declaration for the days_sq variable.

marcus updated this revision to Diff 1291.Jul 6 2017, 1:53 PM

Declare days_sq.