Changes between Version 10 and Version 11 of Commentary/PrimOps


Ignore:
Timestamp:
Jul 4, 2009 9:36:13 PM (5 years ago)
Author:
duncan
Comment:

notes on adding new foreign out-of-line primops

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/PrimOps

    v10 v11  
    7171}}} 
    7272 
    73 Using this syntax requires the extensions `ForeignFunctionInterface`, `GHCForeignImportPrim`, `MagicHash`, `UnboxedTuples` and `UnliftedFFITypes`. The current type restriction is that all arguments and results must be unlifted types. Additionally the result type is allowed to be an unboxed tuple. The calling convention is exactly the same as for ordinary out-of-line primops. Currently it is not possible to specify any of the !PrimOp attributes. 
     73The string (e.g. "int2Integerzh") is the linker name of the Cmm function. Using this syntax requires the extensions `ForeignFunctionInterface`, `GHCForeignImportPrim`, `MagicHash`, `UnboxedTuples` and `UnliftedFFITypes`. The current type restriction is that all arguments and results must be unlifted types. Additionally the result type is allowed to be an unboxed tuple. The calling convention is exactly the same as for ordinary out-of-line primops. Currently it is not possible to specify any of the !PrimOp attributes. 
    7474 
    7575The `integer-gmp` package now uses this method for all the primops that deal with GMP big integer values. The advantage of using this technique is that it is a bit more modular. The RTS does not need to include all the primops. For example in the integer case the RTS no longer needs to link against the GMP C library. 
     
    9595   * [[GhcFile(rts/PrimOps.cmm)]] (implement it here) 
    9696   * [[GhcFile(rts/Linker.c)]] (declare the symbol for GHCi) 
     97 
     98 * for a foreign out-of-line primop You do not need to modify the rts or compiler at all. 
     99   * `yourpackage/cbits/primops.cmm`: implement your primops here. You have to arrange for the .cmm file to be compiled and linked into the package. The GHC build system has support for this. Cabal does not yet. 
     100   * `yourpackage/TheCode.hs`: use `foreign import prim` to import the primops. 
    97101 
    98102See also AddingNewPrimitiveOperations, a blow-by-blow description of the process for adding a new out-of-line primop from someone who went through the process.