Changes between Version 2 and Version 3 of MemcpyOptimizations


Ignore:
Timestamp:
Jun 14, 2011 9:52:28 PM (3 years ago)
Author:
dterei
Comment:

Linkify and expand a little

Legend:

Unmodified
Added
Removed
Modified
  • MemcpyOptimizations

    v2 v3  
    11= memcpy/memmove/memset optimizations = 
    22 
    3 Starting with version 7.2 GHC has three new primitives for copying/setting blocks of memory, corresponding to the C functions `memcpy`, `memmove`, and `memset`. GHC optimizes occurrences of these primitives into efficient unrolled loops whenever possible (and calls the corresponding C functions otherwise.) 
     3Starting with version 7.2, GHC has three new primitives for copying/setting blocks of memory, corresponding to the C functions `memcpy`, `memmove`, and `memset`. GHC optimizes occurrences of these primitives into efficient unrolled loops when possible and calls the corresponding C functions otherwise. 
    44 
    55== Implementation == 
    66 
    7 The primitives are implemented as three `CallishMachOp`s, defined in `compiler/cmm/CmmMachOp`. The code generator generates calls to these `CallishMachOp`s using three utility functions: `emitMemcpyCall`, `emitMemmoveCall`, and `emitMemsetCall`, defined in `compiler/codeGen/CgPrimOp.hs` (old code generator) and `compiler/codeGen/StgCmmPrim.hs` (new code generator). The helper functions take an extra parameter that indicates the alignment of the arguments, which is used as a hint by the backends. 
     7The primitives are implemented as three [wiki:Commentary/Compiler/CmmType Cmm language] [wiki:Commentary/Compiler/CmmType#OperatorsandPrimitiveOperations CallishMachOp`s], defined in [[GhcFile(compiler/cmm/CmmMachOp.hs)]]. The code generator generates calls to these `CallishMachOp`s using three utility functions: `emitMemcpyCall`, `emitMemmoveCall`, and `emitMemsetCall`, defined in [[GhcFile(compiler/codeGen/CgPrimOp.hs)]] (old code generator) and [[GhcFile(compiler/codeGen/StgCmmPrim.hs)]] (new code generator). The helper functions take an extra parameter that indicates the alignment of the arguments, which is used as a optimisation hint by the backends. 
    88 
    9 The reason the primitives are unrolled in the backends, instead of in the code generator, is to allow us to make use of LLVM's `memcpy`/`memmove`/`memset` intrinsics, which LLVM  optimizes well. In the x86/x86-64 backend we unroll the primitives ourselves. 
     9The reason the primitives are unrolled in the backends, instead of in the code generator, is to allow us to make use of LLVM's `memcpy`/`memmove`/`memset` intrinsics, which LLVM  optimizes well. In the x86/x86-64 backend we unroll the primitives ourselves. The different native code generator backends can also generate more efficient code then a generic case higher up. Currently only the X86 backend unrolls these primitives though, SPARC and !PowerPC both just call the corresponding C functions. 
    1010 
    1111== Unrolling heuristics == 
     
    2020== User API == 
    2121 
    22 These primitives are exposed to the user as a set of primitive operations on boxed arrays: 
     22These primitives aren't directly exposed to the user at this time. Instead the primitives are exposed to the user through a set of primitive operations on boxed arrays: 
    2323 
    2424 * `copyArray#` 
     
    2929 * `thawArray#` 
    3030 
    31 The latter four allow the user to efficiently clone an array without first setting all elements to some dummy element, which would be required to e.g. implement `cloneArray#` in terms of `newArray#` and `copyArray#`. The implementation of these primitive operations are in `compiler/cmm/CgPrimOps.hs` (old code generator) and `compiler/codeGen/StgCmmPrim.hs` (new code generator) 
     31The latter four allow the user to efficiently clone an array without first setting all elements to some dummy element, which would be required to e.g. implement `cloneArray#` in terms of `newArray#` and `copyArray#`. The implementation of these primitive operations are in [[GhcFile(compiler/cmm/CgPrimOps.hs)]] (old code generator) and [[GhcFile(compiler/codeGen/StgCmmPrim.hs)]] (new code generator). 
     32 
     33== Test API == 
     34 
     35The main test for this feature of GHC is `cgrun069`, located at `testsuite/tests/ghc-regress/codeGen/should_run/`.