Changes between Version 30 and Version 31 of ReplacingGMPNotes


Ignore:
Timestamp:
Sep 20, 2006 11:52:21 PM (9 years ago)
Author:
guest
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ReplacingGMPNotes

    v30 v31  
    8484 * [http://darcs.haskell.org/ghc/rts/PrimOps.cmm rts/PrimOps.cmm] (''Modify'': remove GMP references; NOTE: optimisation of {{{/* ToDo: this is shockingly inefficient */}}}, see discussion below)
    8585 * [http://darcs.haskell.org/ghc/rts/StgPrimFloat.c rts/StgPrimFloat.c] (''Modify'': {{{__encodeDouble}}}, {{{__encodeFloat}}} and {{{decode}}} versions defined here refer to GMP; might optimise with bitwise conversion instead of union; conversion depends on whether replacement MP library uses floating point, etc.)
    86  * [http://darcs.haskell.org/ghc/rts/Storage.c rts/Storage.c] (''Modify'': {{{stgAllocForGMP}}}, {{{stgReallocForGMP}}} and {{{stgDeallocForGMP}}}; may use as reference for implementation if replacement MP library uses GHC-garbage collected memory)
     86 * [http://darcs.haskell.org/ghc/rts/Storage.c rts/Storage.c] (''Modify'': {{{stgAllocForGMP}}}, {{{stgReallocForGMP}}} and {{{stgDeallocForGMP}}}; {{{mp_set_memory_functions(...)}}}; functions on lines 811, 833, 835, 848; may use as reference for implementation if replacement MP library uses GHC-garbage collected memory)
    8787 * [http://darcs.haskell.org/ghc/rts/gmp/ rts/gmp (directory)] (''Modify'': recommended to remove entirely, i.e., do not add conditional compilation for users who want to keep on using GMP)
    8888
     
    9494
    9595#ifndef THREADED_RTS
    96 section "bss" {
     96section "bss" {                              /* "bss" = UninitialisedData, see CmmParse.y:427 */
    9797  mp_tmp1:
    98     bits8 [SIZEOF_MP_INT];
     98    bits8 [SIZEOF_MP_INT];                   /* SIZEOF_MP_INT created by includes/mkDerivedConstants.c:43-48 */
    9999}
    100100
     
    151151  MP_INT__mp_d(mp_tmp2)     = BYTE_ARR_CTS(d2);                         \
    152152                                                                        \
    153   foreign "C" __gmpz_init(mp_result1 "ptr") [];                            \
    154                                                                         \
     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 */
    155155  /* Perform the operation */                                           \
    156156  foreign "C" mp_fun(mp_result1 "ptr",mp_tmp1  "ptr",mp_tmp2  "ptr") []; \
     
    164164
    165165   (b) use !ForeignPtr (in Cmm, Weak Pointers--difficult to implement) to foreign threads holding the the struct/array
     166
     167(2) Primitive Operations in [http://darcs.haskell.org/ghc/compiler/codeGen/CgPrimOp.hs compiler/codeGen/CgPrimOp.hs]
     168
     169Related to replacing GMP, some operations in CgPrimOP.hs such as IntAddCOp may benefit from operations defined in a replacement MP library (or, more generally, simple optimisation).  For example:
     170{{{
     171
     172emitPrimOp [res_r,res_c] IntAddCOp [aa,bb] live
     173{-
     174   With some bit-twiddling, we can define int{Add,Sub}Czh portably in
     175   C, and without needing any comparisons.  This may not be the
     176   fastest way to do it - if you have better code, please send it! --SDM
     177 
     178   Return : r = a + b,  c = 0 if no overflow, 1 on overflow.
     179 
     180   We currently don't make use of the r value if c is != 0 (i.e.
     181   overflow), we just convert to big integers and try again.  This
     182   could be improved by making r and c the correct values for
     183   plugging into a new J#. 
     184   
     185   { r = ((I_)(a)) + ((I_)(b));                                 \
     186     c = ((StgWord)(~(((I_)(a))^((I_)(b))) & (((I_)(a))^r)))    \
     187         >> (BITS_IN (I_) - 1);                                 \
     188   }
     189   Wading through the mass of bracketry, it seems to reduce to:
     190   c = ( (~(a^b)) & (a^r) ) >>unsigned (BITS_IN(I_)-1)
     191
     192-}
     193   = stmtsC [
     194        CmmAssign res_r (CmmMachOp mo_wordAdd [aa,bb]),
     195        CmmAssign res_c $
     196          CmmMachOp mo_wordUShr [
     197                CmmMachOp mo_wordAnd [
     198                    CmmMachOp mo_wordNot [CmmMachOp mo_wordXor [aa,bb]],
     199                    CmmMachOp mo_wordXor [aa, CmmReg res_r]
     200                ],
     201                CmmLit (mkIntCLit (wORD_SIZE_IN_BITS - 1))
     202          ]
     203     ]
     204}}}
     205If an integer add were to overflow here, the addition operation would be performed ''twice''; even if the integer add did not overflow one extra operation is performed.  Is this an acceptable price for no comparisons?
    166206
    167207=== Benchmarks for Multi-Precision Libraries ===