[GHC] #8287: exploring calling convention changes and related engineering for 7.10

#8287: exploring calling convention changes and related engineering for 7.10 ------------------------------------+------------------------------------- Reporter: carter | Owner: Type: task | Status: new Priority: high | Milestone: 7.10.1 Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Rocket Science | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- I'm creating this as a master ticket for systematically exploring and benchmarking (possibly breaking) changes to the GHC calling convention. This work will initially focus on x86/x86_64, but may have larger scope. Goals: 1. if possible, improve performance systematically for code run on recent CPU micro architecture generations (eg sandybridge, haswell, and future extensions like Knights Landing and Skylake), ideally without pessimizing code on other or older x86_64 micro-architectures 2. Try to bring native and llvm codegens closer to feature parity (or at the very least, do not widen their capability gap) 3. a few other pieces too, will amend this ticket as ideas / plans clarify -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: task | Status: new Priority: high | Milestone: 7.10.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Rocket Science Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by carter): (hrm, i can't seem to edit the ticket) 4. explore adding support for an x32 style ABI. Ie all the x86_64 features, but 32bit pointers. most of the motivation people have for using 32bit ghc currently is the decreased memory pressure / locality element. excerpting the ghc irc thread on this {{{ [12:49:13] <thoughtpolice> copumpkin: i've thought about it, X32 is quite interesting [12:49:16] <luite> copumpkin: 3 tag bits could still work if you have 64 bit alignment of all closures [12:49:25] <luite> otherwise 2 [12:50:19] <copumpkin> yeah, that's what I was thinking [12:50:29] <copumpkin> I'm just thinking of how much downside there is to using a 64-bit ghc [12:50:30] <thoughtpolice> and haven't looked at it again this week [12:50:40] <copumpkin> due to all the pointerness, if you don't have loads more RAM, you won't actually gain that much space [12:50:45] <luite> thoughtpolice: thnx, i have worked around it here [12:50:59] <copumpkin> something resembling x32 could be a happier medium [12:51:14] <thoughtpolice> copumpkin: the more pressing thing is those doubly-sized pointers also waste extra cache space [12:51:18] <rwbarton> copumpkin: I would <3 that so much [12:51:27] <copumpkin> sure, that too [12:51:33] <copumpkin> but I'm an Agda nerd and Agda loves RAM [12:51:37] <luite> with x32 you could also have 32 bit ints and still have int64 fast [12:51:37] <copumpkin> :P [12:51:54] <luite> (would require a bit of rewiring though) }}} is is probably one of the easier experiments to do -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: task | Status: new Priority: high | Milestone: 7.10.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Rocket Science Test Case: | Blocked By: 8299 Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by rwbarton): I did a port of ghc to "real x32" with the following characteristics: * produces x32 executables (these are 32-bit ELF files containing x86-64 object code and relocations, that use the x32 versions of system calls) * in particular, the entire address space of the process lives below 4GB * executables (and object files loaded by ghci) must be mapped below 2GB to avoid over/underflow in x86-64 rip-relative addressing, but the heap can use the full remaining space below 4GB (untested) * dynamic Haskell libraries are not yet implemented * Int is 32 bits, as is Addr# * heap layout is just like on i386: everything on the heap is 4-byte aligned and pointer tagging uses two bits * now with integer-gmp, using 64-bit limbs! * features a fairly small number of bizarre testsuite segfaults and other errors Effectively, it is like i386, but faster (**much** faster when doing large Integer computations due to being able to do 64-bit arithmetic, but still often faster when not), and with more crashes (but those could presumably be sorted out) and a more awkward system library situation (there is no libx32gmp10 package yet on Ubuntu, so I have to set LD_LIBRARY_PATH when running ghc's x32 executables). I attached nofib results comparing amd64 vs. x32 and i686 vs. x32; x32 is about 15% faster on average than either. I call this "real x32" because the compiler produces actual x32 executables. One could imagine a rather different set of design choices: * produces x86-64 executables * no address space limitations * Int is 64 bits, as is Addr# * heap layout is just like on x86-64 (in particular, closures are 8-byte aligned) **except**: all pointers to other closures are stored as 4 bytes rather than 8 (possibly using "compressed references", e.g., address an 8 GB heap by storing a pointer to a closure at address `p` as `p >> 1`, with the two lowest bits used for pointer tagging) This would be less time-efficient than "real x32", but still give much of the space savings, while allowing a larger heap. Good for computations that need between 1 and 2 billion pointers' worth of storage, like compiling modestly complex Agda programs. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: task | Status: new Priority: high | Milestone: 7.10.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Rocket Science Test Case: | Blocked By: 8299 Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by duncan):
I attached nofib results comparing amd64 vs. x32 and i686 vs. x32; x32 is about 15% faster on average than either.
Impressive. So that's our memory/cache penalty for having all our data structures 2x the size on x86-64 ABI. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: task | Status: new Priority: high | Milestone: 7.10.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Rocket Science Test Case: | Blocked By: 8299 Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by carter): related to the x32 matter, theres apparently some leg work by Intel to add / improve x32 support in LLVM and GCC and related bits http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074451.html https://sites.google.com/site/x32abi/ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: task | Status: new Priority: high | Milestone: 7.10.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Rocket Science Test Case: | Blocked By: 8299 Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by gidyn): * cc: gideon@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: task | Status: new Priority: high | Milestone: 7.12.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Rocket Science Type of failure: | Blocked By: 8299 None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by carter): * milestone: 7.10.1 => 7.12.1 Comment: lowering priority and moving to 7.12 mileston -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Rocket Science Type of failure: | Blocked By: 8299 None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by carter): * priority: high => normal -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: 8299 | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by gidyn): * cc: gideon@… (removed) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: 8299 | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by gidyn): * cc: gidyn (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 8299 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * milestone: => ⊥ Comment: My very old patches are also here: https://github.com/rwbarton/ghc/tree/rwbarton-x32 I'm putting this on hold indefinitely though because recent Debian kernels no longer support x32 out of the box (you need a kernel command-line parameter to enable x32 support). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8287: exploring calling convention changes and related engineering for 7.10 -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 8299 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * milestone: ⊥ => Comment: Er, this ticket wasn't specifically about x32 I guess. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8287#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC