modulus optimization
commitade0868dcce3a48d9d581321af46317a17d99ae5
authorYu-Jung Lo <ylo@fb.com>
Fri, 5 Oct 2018 22:52:15 +0000 (5 15:52 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Fri, 5 Oct 2018 22:59:30 +0000 (5 15:59 -0700)
tree0b335064126f871e2900f2e9be7ec05070b5a652
parent7c42cd9127de026cf50c8665062493dede03643d
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
hphp/runtime/vm/jit/simplify.cpp
hphp/test/quick/ops.php
hphp/test/quick/ops.php.expectf
hphp/tools/benchmarks/hhmeasure/BasicOps.php
hphp/tools/benchmarks/hhmeasure/MeasureBasicOps.php
hphp/tools/benchmarks/hhmeasure/hhmeasure