Ticket #5413: 0001-Add-fallbacks-for-processor-specific-instructions-e..patch

File 0001-Add-fallbacks-for-processor-specific-instructions-e..patch, 3.5 KB (added by tibbe, 23 months ago)
  • (a) /dev/null vs. (b) b/cbits/popcnt.c

    From 4d2e6e4819939ea994775836e2801b5faa5533e3 Mon Sep 17 00:00:00 2001
    From: Johan Tibell <johan.tibell@gmail.com>
    Date: Wed, 20 Jul 2011 23:05:21 +0200
    Subject: [PATCH 1/1] 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(-)
     create mode 100644 cbits/popcnt.c
    
    diff --git a/cbits/popcnt.c b/cbits/popcnt.c
    new file mode 100644
    index 0000000..10d6fa4
    a b  
     1#include "Rts.h" 
     2 
     3static const unsigned char popcount_tab[] = 
     4{ 
     5    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, 
     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, 
     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, 
     8    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, 
     9    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, 
     10    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, 
     11    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, 
     12    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, 
     13}; 
     14 
     15extern StgWord8 hs_popcnt8(StgWord8 x); 
     16StgWord8 
     17hs_popcnt8(StgWord8 x) 
     18{ 
     19  return popcount_tab[(unsigned char)x]; 
     20} 
     21 
     22extern StgWord16 hs_popcnt16(StgWord16 x); 
     23StgWord16 
     24hs_popcnt16(StgWord16 x) 
     25{ 
     26  return popcount_tab[(unsigned char)x] + 
     27      popcount_tab[(unsigned char)(x >> 8)]; 
     28} 
     29 
     30extern StgWord32 hs_popcnt32(StgWord32 x); 
     31StgWord32 
     32hs_popcnt32(StgWord32 x) 
     33{ 
     34  return popcount_tab[(unsigned char)x] + 
     35      popcount_tab[(unsigned char)(x >> 8)] + 
     36      popcount_tab[(unsigned char)(x >> 16)] + 
     37      popcount_tab[(unsigned char)(x >> 24)]; 
     38} 
     39 
     40extern StgWord64 hs_popcnt64(StgWord64 x); 
     41StgWord64 
     42hs_popcnt64(StgWord64 x) 
     43{ 
     44  return popcount_tab[(unsigned char)x] + 
     45      popcount_tab[(unsigned char)(x >> 8)] + 
     46      popcount_tab[(unsigned char)(x >> 16)] + 
     47      popcount_tab[(unsigned char)(x >> 24)] + 
     48      popcount_tab[(unsigned char)(x >> 32)] + 
     49      popcount_tab[(unsigned char)(x >> 40)] + 
     50      popcount_tab[(unsigned char)(x >> 48)] + 
     51      popcount_tab[(unsigned char)(x >> 56)]; 
     52} 
     53 
     54#ifdef i386_HOST_ARCH 
     55 
     56extern StgWord32 hs_popcnt(StgWord32 x); 
     57StgWord32 
     58hs_popcnt(StgWord32 x) 
     59{ 
     60  return popcount_tab[(unsigned char)x] + 
     61      popcount_tab[(unsigned char)(x >> 8)] + 
     62      popcount_tab[(unsigned char)(x >> 16)] + 
     63      popcount_tab[(unsigned char)(x >> 24)]; 
     64} 
     65 
     66#else 
     67 
     68extern StgWord64 hs_popcnt(StgWord64 x); 
     69StgWord64 
     70hs_popcnt(StgWord64 x) 
     71{ 
     72  return popcount_tab[(unsigned char)x] + 
     73      popcount_tab[(unsigned char)(x >> 8)] + 
     74      popcount_tab[(unsigned char)(x >> 16)] + 
     75      popcount_tab[(unsigned char)(x >> 24)] + 
     76      popcount_tab[(unsigned char)(x >> 32)] + 
     77      popcount_tab[(unsigned char)(x >> 40)] + 
     78      popcount_tab[(unsigned char)(x >> 48)] + 
     79      popcount_tab[(unsigned char)(x >> 56)]; 
     80} 
     81 
     82#endif 
  • ghc-prim.cabal

    diff --git a/ghc-prim.cabal b/ghc-prim.cabal
    index 38330fb..d06d3ed 100644
    a b  
    4242    c-sources: 
    4343        cbits/debug.c 
    4444        cbits/longlong.c 
     45        cbits/popcnt.c 
    4546    extensions: CPP, MagicHash, ForeignFunctionInterface, UnliftedFFITypes, 
    4647                UnboxedTuples, EmptyDataDecls, NoImplicitPrelude 
    4748    -- We need to set the package name to ghc-prim (without a version number)