[commit: packages/primitive] ghc-head: Add C block fill operations for various types (e1ca53e)

git at git.haskell.org git at git.haskell.org
Thu Sep 26 11:44:07 CEST 2013


Repository : ssh://git@git.haskell.org/primitive

On branch  : ghc-head
Link       : http://git.haskell.org/packages/primitive.git/commitdiff/e1ca53eabd71210ac025a83eb40970412daf3428

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

commit e1ca53eabd71210ac025a83eb40970412daf3428
Author: Roman Leshchinskiy <rl at cse.unsw.edu.au>
Date:   Thu Jan 26 15:34:56 2012 -0700

    Add C block fill operations for various types


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

e1ca53eabd71210ac025a83eb40970412daf3428
 cbits/primitive-memops.c |   40 ++++++++++++++++++++++++++++++++++++++++
 cbits/primitive-memops.h |   11 +++++++++++
 2 files changed, 51 insertions(+)

diff --git a/cbits/primitive-memops.c b/cbits/primitive-memops.c
index e4f6d9f..a6d1959 100644
--- a/cbits/primitive-memops.c
+++ b/cbits/primitive-memops.c
@@ -1,4 +1,5 @@
 #include <string.h>
+#include "primitive-memops.h"
 
 void memcpy_off( void *dst, int doff, void *src, int soff, size_t len )
 {
@@ -15,3 +16,42 @@ void memset_off( void *dst, int doff, int c, size_t len )
   memset( (char *)dst + doff, c, len );
 }
 
+#define MEMSET(TYPE, ATYPE)                                                  \
+void hsprimitive_memset_ ## TYPE (Hs ## TYPE *p, int off, int n, ATYPE x)    \
+{                                                                            \
+  p += off;                                                                  \
+  if (x == 0)                                                                \
+    memset(p, 0, n * sizeof(Hs ## TYPE));                                    \
+  else if (sizeof(Hs ## TYPE) == sizeof(int)*2) {                            \
+    int *q = (int *)p;                                                       \
+    const int *r = (const int *)&x;                                          \
+    while (n>0) {                                                            \
+      q[0] = r[0];                                                           \
+      q[1] = r[1];                                                           \
+      q += 2;                                                                \
+      --n;                                                                   \
+    }                                                                        \
+  }                                                                          \
+  else {                                                                     \
+    while (n>0) {                                                            \
+      *p++ = x;                                                              \
+      --n;                                                                   \
+    }                                                                        \
+  }                                                                          \
+}
+
+void hsprimitive_memset_Word8 (HsWord8 *p, int off, int n, HsWord x)
+{
+  memset( (char *)(p+off), x, n );
+}
+
+/* MEMSET(HsWord8, HsWord) */
+MEMSET(Word16, HsWord)
+MEMSET(Word32, HsWord)
+MEMSET(Word64, HsWord64)
+MEMSET(Word, HsWord)
+MEMSET(Ptr, HsPtr)
+MEMSET(Float, HsFloat)
+MEMSET(Double, HsDouble)
+MEMSET(Char, HsChar)
+
diff --git a/cbits/primitive-memops.h b/cbits/primitive-memops.h
index 92dab27..2aad75a 100644
--- a/cbits/primitive-memops.h
+++ b/cbits/primitive-memops.h
@@ -2,10 +2,21 @@
 #define haskell_primitive_memops_h
 
 #include <stdlib.h>
+#include <HsFFI.h>
 
 void memcpy_off( void *dst, int doff, void *src, int soff, size_t len );
 void memmove_off( void *dst, int doff, void *src, int soff, size_t len );
 void memset_off( void *dst, int doff, int c, size_t len );
 
+void hsprimitive_memset_Word8 (HsWord8 *, int, int, HsWord);
+void hsprimitive_memset_Word16 (HsWord16 *, int, int, HsWord);
+void hsprimitive_memset_Word32 (HsWord32 *, int, int, HsWord);
+void hsprimitive_memset_Word64 (HsWord64 *, int, int, HsWord64);
+void hsprimitive_memset_Word (HsWord *, int, int, HsWord);
+void hsprimitive_memset_Ptr (HsPtr *, int, int, HsPtr);
+void hsprimitive_memset_Float (HsFloat *, int, int, HsFloat);
+void hsprimitive_memset_Double (HsDouble *, int, int, HsDouble);
+void hsprimitive_memset_Char (HsChar *, int, int, HsChar);
+
 #endif
 




More information about the ghc-commits mailing list