[WIP] Optimize literal truncation
AbandonedPublic

Authored by bgamari on Dec 4 2017, 2:39 PM.

Details

Reviewers
AndreasK
Summary

An idea that came up while discussing D4218 with @AndreasK

bgamari created this revision.Dec 4 2017, 2:39 PM
alexbiehl added inline comments.
compiler/basicTypes/Literal.hs
296

This should be wrapTo64Bits?

wrapToBits seems to be slower on all optimization levels then the current implementation.

At -O2 for a value in 64 Bit range

benchmarking intStuff/wrapTo32Bits
time                 6.708 ns   (6.696 ns .. 6.736 ns)
                     0.999 R²   (0.997 R² .. 1.000 R²)
mean                 6.798 ns   (6.719 ns .. 7.136 ns)
std dev              439.3 ps   (100.4 ps .. 969.4 ps)
variance introduced by outliers: 83% (severely inflated)

benchmarking intStuff/truncTo32
time                 5.567 ns   (5.565 ns .. 5.569 ns)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 5.561 ns   (5.556 ns .. 5.573 ns)
std dev              23.75 ps   (10.83 ps .. 46.25 ps)

benchmarking intStuff/wrapTo64Bits
time                 9.155 ns   (9.154 ns .. 9.156 ns)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 9.132 ns   (9.128 ns .. 9.135 ns)
std dev              12.95 ps   (11.26 ps .. 15.54 ps)

benchmarking intStuff/truncTo64
time                 6.868 ns   (6.858 ns .. 6.882 ns)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 6.883 ns   (6.875 ns .. 6.891 ns)
std dev              26.77 ps   (22.88 ps .. 31.26 ps)

For a value out of 64Bit range:

benchmarking intStuff/wrapTo32Bits
time                 40.76 ns   (40.76 ns .. 40.77 ns)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 40.69 ns   (40.68 ns .. 40.71 ns)
std dev              57.64 ps   (34.38 ps .. 110.7 ps)

benchmarking intStuff/truncTo32
time                 6.291 ns   (6.290 ns .. 6.292 ns)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 6.278 ns   (6.275 ns .. 6.280 ns)
std dev              8.402 ps   (6.652 ps .. 10.93 ps)

benchmarking intStuff/wrapTo64Bits
time                 14.54 ns   (14.44 ns .. 14.65 ns)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 14.43 ns   (14.41 ns .. 14.51 ns)
std dev              127.3 ps   (63.15 ps .. 251.9 ps)

benchmarking intStuff/truncTo64
time                 8.033 ns   (8.030 ns .. 8.037 ns)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 8.026 ns   (8.021 ns .. 8.032 ns)
std dev              16.83 ps   (13.11 ps .. 23.53 ps)
bgamari added inline comments.Dec 8 2017, 4:45 PM
compiler/basicTypes/Literal.hs
296

Yep.

AndreasK abandoned this revision.Jan 7 2018, 12:10 PM

Slower as the current version