modulus optimization
Summary:
Test optimization for `x % y` when y is `2^n`.
Reuse the hhmeasure for microbenchmarking.
I'm not sure if this is the right way to do microbenchmarking. If not, please let me know.
Some benchmark result:
* Run with `/home/ylo/fbsource/fbcode/buck-out/gen/hphp/hhvm/hhvm`
For y = 2048 | 4096, skip optimization. Using the same binary to compare the performance result between y = 2048|4096 and y = 1024|8192.
For 10000 iterations,
Operation Name Median (ms) Mean Max Min
run_modulus_1 10.235521 23.030888 136.837838 9.501931
run_modulus_optimization_1 7.621622 20.401544 135.416988 7.575290
run_modulus_2 9.629344 23.462162 145.359073 9.474903
run_modulus_optimization_2 7.664093 20.894595 136.158301 7.555985
In conclusion, we make 1 modulus op into 3 logical op (`(x & (y - 1)) | (-y & (x >> 63))`).
We can still see some performance improvement.
Reviewed By: paulbiss
Differential Revision:
D10117485
fbshipit-source-id:
a7d94b4f21f8e748722bf189ae1b3acead31096e