[Cbe-oss-dev] [PATCH] libspe: add posix_memalign_ea

Dirk Herrendoerfer d.herrendoerfer at de.ibm.com
Fri Apr 18 00:02:53 EST 2008


Add support for posix_memalign_ea.

This is on the SPU, since we often want 8 byte alignments, but malloc_ea
gives 4 byte alignment.

Signed-off-by: Dirk Herrendoerfer < d.herrendoerfer at de.ibm.com >

Index: quilt-libspe2/spebase/default_libea_handler.c
===================================================================
--- quilt-libspe2.orig/spebase/default_libea_handler.c
+++ quilt-libspe2/spebase/default_libea_handler.c
@@ -167,12 +167,49 @@ static int default_libea_handler_realloc

 }

+/**
+ * default_libea_handler_posix_memalign
+ * @ls: base pointer to local store area.
+ * @opdata: LIBEA call opcode & data.
+ *
+ * LIBEA library operation, implement:
+ *
+ *          int posix_memalign(void **memptr, size_t alignment, size_t
size);
+ *
+ * memptr is an LS pointer that points to an EA pointer, so *memptr is 32
+ * or 64 bits long.
+ */
+static int default_libea_handler_posix_memalign(char *ls, unsigned long
opdata)
+{
+  DECL_3_ARGS();
+  DECL_RET();
+  size_t size, alignment;
+  void **memptr;
+  int rc;
+
+  memptr = GET_LS_PTR(arg0->slot[0]);
+  alignment = arg64_to_size_t(arg1);
+  size = arg64_to_size_t(arg2);
+
+  if(arg2->slot[0] == 0 || sizeof(size) == 8)
+    rc = posix_memalign(memptr, alignment, size);
+  else
+    /*
+     * Yes, rc and not errno since posix_memalign never sets errno.
+     */
+    rc = ENOMEM;
+
+  PUT_LS_RC(rc, 0, 0, 0);
+  return 0;
+}
+
 static int (*default_libea_funcs[SPE_LIBEA_NR_OPCODES]) (char *, unsigned
long) = {
             [SPE_LIBEA_UNUSED]                        = NULL,
             [SPE_LIBEA_CALLOC]                        =
default_libea_handler_calloc,
             [SPE_LIBEA_FREE]                    =
default_libea_handler_free,
             [SPE_LIBEA_MALLOC]                        =
default_libea_handler_malloc,
             [SPE_LIBEA_REALLOC]                       =
default_libea_handler_realloc,
+            [SPE_LIBEA_POSIX_MEMALIGN]          =
default_libea_handler_posix_memalign,
 };

 /**
Index: quilt-libspe2/spebase/default_libea_handler.h
===================================================================
--- quilt-libspe2.orig/spebase/default_libea_handler.h
+++ quilt-libspe2/spebase/default_libea_handler.h
@@ -6,7 +6,8 @@
 #define SPE_LIBEA_FREE         0x02
 #define SPE_LIBEA_MALLOC       0x03
 #define SPE_LIBEA_REALLOC      0x04
-#define SPE_LIBEA_NR_OPCODES   0x05
+#define SPE_LIBEA_POSIX_MEMALIGN   0x05
+#define SPE_LIBEA_NR_OPCODES   0x06

 extern int _base_spe_default_libea_handler(char *ls, unsigned long args);





More information about the cbe-oss-dev mailing list