Improve accuracy of get/setAllocationCounter
ClosedPublic

Authored by bgamari on Jan 31 2018, 11:24 PM.

Details

Summary

get/setAllocationCounter didn't take into account allocations in the
current block. This was known at the time, but it turns out to be
important to have more accuracy when using these in a fine-grained
way.

Test Plan

New unit test to test incrementally larger allocaitons. Before I got
results like this:

+0
+0
+0
+0
+0
+4096
+0
+0
+0
+0
+0
+4064
+0
+0
+4088
+4056
+0
+0
+0
+4088
+4096
+4056
+4096

Notice how the results aren't always monotonically increasing. After
this patch:

+344
+416
+488
+560
+632
+704
+776
+848
+920
+992
+1064
+1136
+1208
+1280
+1352
+1424
+1496
+1568
+1640
+1712
+1784
+1856
+1928
+2000
+2072
+2144

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
bgamari created this revision.Jan 31 2018, 11:24 PM
bgamari added a comment.EditedJan 31 2018, 11:26 PM

@simonmar, this appears to compile on i386 with D4362. I haven't tested it for correctness yet. I'm also not entirely sure what the status of the other 32-bit architectures is. In short, this requires MO_UU_Conv W32 W64 which appears to be poorly supported.

simonmar accepted this revision.Feb 1 2018, 3:03 AM

Thanks for taking care of this! Nothing is ever simple :-/

This revision is now accepted and ready to land.Feb 1 2018, 3:03 AM
bgamari added subscribers: jrtc27, trommler.

Adding @jrtc27 and @trommler for input on the other architectures.

@simonmar, this appears to compile on i386 with D4362. I haven't tested it for correctness yet. I'm also not entirely sure what the status of the other 32-bit architectures is. In short, this requires MO_UU_Conv W32 W64 which appears to be poorly supported.

Do you mean MO_SS_Conv W32 W64? Unsigned is supported by the current 32-bit SPARC NCG, but not signed. Similarly for PPC.

SPARC is easy to implement:

mov %x, %lo     ! Copy low 32 bits into output register pair
sra %x, 31, %hi ! Perform a right arithmetic shift on the input by 31 bits
                ! to get 32 copies of the sign bit and store in the high half
                ! of the output register pair

PPC is similar:

mr lo, x
srawi hi, x, 31
trommler added a comment.EditedFeb 1 2018, 12:11 PM

Currently MO_SS_Conv W32 W64 is not supported on 32 bit PPC. In fact, we would get a compiler panic if I understand the code in nativeGen/PPC/Codegen.hs right.

I don't have access to a PPC32 bit machine. Perhaps @erikd, who helped out with tests on 32 bit Linux in the past, or @hvr, who developed on AIX where we support 32 bit only yet, could help out.

Currently MO_SS_Conv W32 W64 is not supported on 32 bit PPC.

I created D4468 for this.