[commit: ghc-prim] master: add other architecture for bswap in a form of Stg functions. (585bdc6)

Ian Lynagh igloo at earth.li
Sun Jun 9 14:16:08 CEST 2013


Repository : ssh://darcs.haskell.org//srv/darcs/packages/ghc-prim

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/585bdc6acbf49493e0274bf3162a8525c7972e34

>---------------------------------------------------------------

commit 585bdc6acbf49493e0274bf3162a8525c7972e34
Author: Ian Lynagh <ian at well-typed.com>
Date:   Sun Jun 9 12:06:07 2013 +0100

    add other architecture for bswap in a form of Stg functions.
    
    Patch from Vincent Hanquez

>---------------------------------------------------------------

 cbits/bswap.c  |   27 +++++++++++++++++++++++++++
 ghc-prim.cabal |    1 +
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/cbits/bswap.c b/cbits/bswap.c
new file mode 100644
index 0000000..9f920b3
--- /dev/null
+++ b/cbits/bswap.c
@@ -0,0 +1,27 @@
+#include "Rts.h"
+
+extern StgWord16 hs_bswap16(StgWord16 x);
+StgWord16
+hs_bswap16(StgWord16 x)
+{
+  return ((x >> 8) | (x << 8));
+}
+
+extern StgWord32 hs_bswap32(StgWord32 x);
+StgWord32
+hs_bswap32(StgWord32 x)
+{
+  return ((x >> 24) | ((x >> 8) & 0xff00) |
+          (x << 24) | ((x & 0xff00) << 8));
+}
+
+extern StgWord64 hs_bswap64(StgWord64 x);
+StgWord64
+hs_bswap64(StgWord64 x)
+{
+  return ( (x >> 56)                | (x << 56)
+         | ((x >> 40) & 0xff00)     | ((x & 0xff00) << 40)
+         | ((x >> 24) & 0xff0000)   | ((x & 0xff0000) << 24)
+         | ((x >> 8)  & 0xff000000) | ((x & 0xff000000) << 8)
+         );
+}
diff --git a/ghc-prim.cabal b/ghc-prim.cabal
index 24eacd6..7381a8e 100644
--- a/ghc-prim.cabal
+++ b/ghc-prim.cabal
@@ -40,6 +40,7 @@ Library {
         cbits/debug.c
         cbits/longlong.c
         cbits/popcnt.c
+        cbits/bswap.c
         cbits/word2float.c
     extensions: CPP, MagicHash, ForeignFunctionInterface, UnliftedFFITypes,
                 UnboxedTuples, EmptyDataDecls, NoImplicitPrelude





More information about the ghc-commits mailing list