The first commit is a rebased version of Hal's feb 2011 patch. The second commit improves the code a bit (precalculate constants, and use BN_CTX_get for temporary values).
This reduces reindexing time for the first 210k blocks (script checks enabled everywhere, 4 verification threads, -dbcache=900) from 1h14m to 1h1m on my system.