Repository : ssh://darcs.haskell.org//srv/darcs/packages/ghc-prim On branch : master
http://hackage.haskell.org/trac/ghc/changeset/cefc19afafe5107ff98d5205c204b190da1d497b >--------------------------------------------------------------- commit cefc19afafe5107ff98d5205c204b190da1d497b Author: Johan Tibell <[email protected]> Date: Wed Jul 20 23:05:21 2011 +0200 Add fallbacks for processor specific instructions (e.g. POPCNT). These fallbacks are referred to by code generated by GHC. >--------------------------------------------------------------- cbits/popcnt.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ghc-prim.cabal | 1 + 2 files changed, 83 insertions(+), 0 deletions(-) diff --git a/cbits/popcnt.c b/cbits/popcnt.c new file mode 100644 index 0000000..10d6fa4 --- /dev/null +++ b/cbits/popcnt.c @@ -0,0 +1,82 @@ +#include "Rts.h" + +static const unsigned char popcount_tab[] = +{ + 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, + 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, + 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, + 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, + 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, + 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, + 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, + 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8, +}; + +extern StgWord8 hs_popcnt8(StgWord8 x); +StgWord8 +hs_popcnt8(StgWord8 x) +{ + return popcount_tab[(unsigned char)x]; +} + +extern StgWord16 hs_popcnt16(StgWord16 x); +StgWord16 +hs_popcnt16(StgWord16 x) +{ + return popcount_tab[(unsigned char)x] + + popcount_tab[(unsigned char)(x >> 8)]; +} + +extern StgWord32 hs_popcnt32(StgWord32 x); +StgWord32 +hs_popcnt32(StgWord32 x) +{ + return popcount_tab[(unsigned char)x] + + popcount_tab[(unsigned char)(x >> 8)] + + popcount_tab[(unsigned char)(x >> 16)] + + popcount_tab[(unsigned char)(x >> 24)]; +} + +extern StgWord64 hs_popcnt64(StgWord64 x); +StgWord64 +hs_popcnt64(StgWord64 x) +{ + return popcount_tab[(unsigned char)x] + + popcount_tab[(unsigned char)(x >> 8)] + + popcount_tab[(unsigned char)(x >> 16)] + + popcount_tab[(unsigned char)(x >> 24)] + + popcount_tab[(unsigned char)(x >> 32)] + + popcount_tab[(unsigned char)(x >> 40)] + + popcount_tab[(unsigned char)(x >> 48)] + + popcount_tab[(unsigned char)(x >> 56)]; +} + +#ifdef i386_HOST_ARCH + +extern StgWord32 hs_popcnt(StgWord32 x); +StgWord32 +hs_popcnt(StgWord32 x) +{ + return popcount_tab[(unsigned char)x] + + popcount_tab[(unsigned char)(x >> 8)] + + popcount_tab[(unsigned char)(x >> 16)] + + popcount_tab[(unsigned char)(x >> 24)]; +} + +#else + +extern StgWord64 hs_popcnt(StgWord64 x); +StgWord64 +hs_popcnt(StgWord64 x) +{ + return popcount_tab[(unsigned char)x] + + popcount_tab[(unsigned char)(x >> 8)] + + popcount_tab[(unsigned char)(x >> 16)] + + popcount_tab[(unsigned char)(x >> 24)] + + popcount_tab[(unsigned char)(x >> 32)] + + popcount_tab[(unsigned char)(x >> 40)] + + popcount_tab[(unsigned char)(x >> 48)] + + popcount_tab[(unsigned char)(x >> 56)]; +} + +#endif diff --git a/ghc-prim.cabal b/ghc-prim.cabal index 38330fb..d06d3ed 100644 --- a/ghc-prim.cabal +++ b/ghc-prim.cabal @@ -42,6 +42,7 @@ Library { c-sources: cbits/debug.c cbits/longlong.c + cbits/popcnt.c extensions: CPP, MagicHash, ForeignFunctionInterface, UnliftedFFITypes, UnboxedTuples, EmptyDataDecls, NoImplicitPrelude -- We need to set the package name to ghc-prim (without a version number) _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
