Changes between Version 34 and Version 35 of ReplacingGMPNotes


Ignore:
Timestamp:
Nov 8, 2006 5:36:12 AM (9 years ago)
Author:
p_tanski
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ReplacingGMPNotes

    v34 v35  
    77GHC currently implements the Integer and Fractional types by using the [http://swox.com/gmp/ The GNU MP Bignum Library] (GMP) which supports arbitrary precision mathematical calculations.  GMP is fast, memory efficient, and offers many high level signed integer functions (140 of them), as well as many rational and floating point arithmetic functions.  The current GHC implementation only uses those functions necessary for the Prelude. 
    88
    9 GMP memory is integrated with the !RunTime System's (RTS's) Garbage Collector (GC).  GMP memory is allocated from the GC heap, so values produced by GMP are under the control of the RTS and its GC.  The current implementation is memory efficient wile allowing the RTS and its GC to maintain control of GMP evaluations.
     9GMP memory is integrated with the [wiki:Commentary/Rts RunTime System's] (RTS's) [wiki:Commentary/Rts/Storage Storage Manager] (SM)--the RTS's Garbage Collector (GC).  GMP memory is allocated from the GC heap, so values produced by GMP are under the control of the RTS and its GC.  The current implementation is memory efficient wile allowing the RTS and its GC to maintain control of GMP evaluations.
    1010
    1111If you want to help with replacing GMP or do it yourself, you will have to work with the GC and RTS system.  The parts you will have to modify are written in C and C--, with configuration and assembly done through the Makefiles.  You should have an understanding of:
    1212        * how the GC works and how memory from GMP is integrated with it;
    13         * some C-- (this is fairly basic if you know C well, the only real documentation on C-- itself is in the [http://cminusminus.org/extern/man2.pdf C-- manual (PDF)], from cminusminus.org; the implementation of C-- for GHC is performed by several Haskell modules in the directory [[GhcFile(compiler/cmm/)]] of the HEAD branch, see [http://darcs.haskell.org/ghc http://darcs.haskell.org/ghc]); and,
     13        * some C-- (this is fairly basic if you know C well, though the same adage for knowing C well holds for C--: if you know enough Assembler to  understand and debug C in Assembler you will be much better off), the only real documentation on C-- itself is in the [http://cminusminus.org/extern/man2.pdf C-- manual (PDF)], from cminusminus.org; the implementation of C-- for GHC is performed by several Haskell modules in the directory [[GhcFile(compiler/cmm/)]] of the HEAD branch, see [http://darcs.haskell.org/ghc http://darcs.haskell.org/ghc]); and,
    1414        * makefiles and configuration scripts.
    1515
    16 A guide to GHC primitives is available (in an unformatted version) in [[GhcFile(/compiler/prelude/primops.txt.pp)]]; there is a formatted version (from the latest build) at [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html].  (See [wiki:Commentary The (new) GHC Commentary] [wiki:Commentary/PrimOps PrimOps] page for an excellent description of how primitive operations are implemented.  A highly recommended introduction directly related to GMP is [wiki:AddingNewPrimitiveOperations].) In primops.txt.pp--better yet, [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html GHC.Prim]--you might want to search for the text {{{"section "The word size story.""}}}, and especially the text {{{"section "Integer#""}}} or just go to [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html#1 The word size story] and [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html#8 Integer].   The Haskell definition of Integer is in [http://darcs.haskell.org/packages/base/GHC/Num.lhs /packages/base/GHC/Num.lhs].
     16A guide to GHC primitives is available (in an unformatted version) in [[GhcFile(/compiler/prelude/primops.txt.pp)]]; there is a formatted version (from the latest build) at [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html].  (See [wiki:Commentary The (new) GHC Commentary] [wiki:Commentary/PrimOps PrimOps] page for an excellent description of how primitive operations are implemented.  A highly recommended introduction directly related to GMP is [wiki:AddingNewPrimitiveOperations].) In primops.txt.pp--better yet, [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html GHC.Prim]--you might want to search for the text {{{"section "The word size story.""}}}, and especially the text {{{"section "Integer#""}}} or just go to [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html#1 The word size story] and [http://www.haskell.org/ghc/dist/current/docs/libraries/base/GHC-Prim.html#8 Integer].   The Haskell definition of the Integer data type is in [http://darcs.haskell.org/packages/base/GHC/Num.lhs /packages/base/GHC/Num.lhs].
    1717
    1818Other basic recommended reading is:
    1919        * [http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/ The (old) GHC Commentary]: [http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/the-beast/ncg.html The Native Code Generator]; and,
    20         * [http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/ The (old) GHC Commentary]: [http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/rts-libs/coding-style.html Style Guidelines for RTS C code].
     20        * [http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/ The (old) GHC Commentary]: [http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/rts-libs/coding-style.html Style Guidelines for RTS C code] or [wiki:Commentary The (new) GHC Commentary]: [wiki:Commentary/Rts/Conventions Style Conventions for RTS C Code].
    2121
    2222==== ''Caveat'' ====
     
    9696
    9797#ifndef THREADED_RTS
    98 section "bss" {                   /* "bss" = UninitialisedData, see CmmParse.y:427 */
     98section "bss" {           /* "bss" = UninitialisedData, see CmmParse.y:427 */
    9999  mp_tmp1:
    100     bits8 [SIZEOF_MP_INT];        /* SIZEOF_MP_INT created by includes/mkDerivedConstants.c:43-48 */
     100    bits8 [SIZEOF_MP_INT];/* SIZEOF_MP_INT created by includes/mkDerivedConstants.c:43-48 */
    101101}
    102102
     
    153153  MP_INT__mp_d(mp_tmp2)     = BYTE_ARR_CTS(d2);                         \
    154154                                                                        \
    155   foreign "C" __gmpz_init(mp_result1 "ptr") [];\ /* This actually initialises GMP as well as mp_result1 */
    156                                                \ /* mp_result1 must subsequently grow to size */
     155  /* This actually initialises GMP as well as mp_result1 */             \
     156  /* mp_result1 must subsequently grow to size */                       \
     157  foreign "C" __gmpz_init(mp_result1 "ptr") [];                         \
     158                                                                        \
    157159  /* Perform the operation */                                           \
    158   foreign "C" mp_fun(mp_result1 "ptr",mp_tmp1  "ptr",mp_tmp2  "ptr") []; \
     160  foreign "C" mp_fun(mp_result1 "ptr",mp_tmp1  "ptr",mp_tmp2  "ptr") [];\
    159161                                                                        \
    160162  RET_NP(TO_W_(MP_INT__mp_size(mp_result1)),                            \