Changes between Version 33 and Version 34 of ReplacingGMPNotes


Ignore:
Timestamp:
Nov 8, 2006 12:21:42 AM (7 years ago)
Author:
p_tanski
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ReplacingGMPNotes

    v33 v34  
    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 [http://darcs.haskell.org/ghc/compiler/cmm/ compiler/cmm] of the HEAD branch); and, 
     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, 
    1414        * makefiles and configuration scripts. 
     15 
     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 Integer is in [http://darcs.haskell.org/packages/base/GHC/Num.lhs /packages/base/GHC/Num.lhs]. 
    1517 
    1618Other basic recommended reading is: 
     
    40423. Other Improvements to Integer 
    4143 
    42         Most of the suggestions in this section come from discussions in the glasgow-haskell-users list thread [http://www.haskell.org/pipermail/glasgow-haskell-users/2006-July/010654.html returning to Cost of Integer].  In particular, [http://www.haskell.org/pipermail/glasgow-haskell-users/2006-July/010660.html John Meacham's suggestion] to use a !ForeignPtr to data held by the normal GMP system library and store the value in an unboxed Int if the number of significant digits in Integer could fit into the size of an Int.  For those who are curious, 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] for a description of primops.txt.pp; and a highly recommended introduction directly related to GMP is [wiki:AddingNewPrimitiveOperations].) In primops.txt.pp, you might want to search for the text "section "The word size story."", and especially the text "section "Integer#"".   The Haskell definition of Integer is in [http://darcs.haskell.org/packages/base/GHC/Num.lhs /packages/base/GHC/Num.lhs]. 
     44        Most of the suggestions in this section come from discussions in the glasgow-haskell-users list thread [http://www.haskell.org/pipermail/glasgow-haskell-users/2006-July/010654.html returning to Cost of Integer].  In particular, [http://www.haskell.org/pipermail/glasgow-haskell-users/2006-July/010660.html John Meacham's suggestion] to use a !ForeignPtr to data held by the normal GMP system library and store the value in an unboxed Int if the number of significant digits in Integer could fit into the size of an Int. 
    4345 
    4446        The current GMP implementation of Integer is: 
     
    9496 
    9597#ifndef THREADED_RTS 
    96 section "bss" {                           /* "bss" = UninitialisedData, see CmmParse.y:427 */ 
     98section "bss" {                   /* "bss" = UninitialisedData, see CmmParse.y:427 */ 
    9799  mp_tmp1: 
    98     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 */ 
    99101} 
    100102 
     
    151153  MP_INT__mp_d(mp_tmp2)     = BYTE_ARR_CTS(d2);                         \ 
    152154                                                                        \ 
    153   foreign "C" __gmpz_init(mp_result1 "ptr") [];   \ /* This actually initialises GMP as well as mp_result1 */ 
    154                                                   \ /* mp_result1 must subsequently grow to size */ 
     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 */ 
    155157  /* Perform the operation */                                           \ 
    156158  foreign "C" mp_fun(mp_result1 "ptr",mp_tmp1  "ptr",mp_tmp2  "ptr") []; \