From 5d69a524f81f234b3fbc41d49ba18d6f6886baba Mon Sep 17 00:00:00 2001
From: jcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Date: Thu, 3 Aug 2006 04:51:51 +0000
Subject: Houston, we have a trunk.

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3122 221aa14e-8319-0410-a670-987f0aec2ac5
---
 gnuradio-core/src/lib/general/malloc16.c | 46 ++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 gnuradio-core/src/lib/general/malloc16.c

(limited to 'gnuradio-core/src/lib/general/malloc16.c')

diff --git a/gnuradio-core/src/lib/general/malloc16.c b/gnuradio-core/src/lib/general/malloc16.c
new file mode 100644
index 0000000000..2cc6135e77
--- /dev/null
+++ b/gnuradio-core/src/lib/general/malloc16.c
@@ -0,0 +1,46 @@
+/* Wrapper functions for malloc/free that force 16-byte alignment
+ * See http://perso.club-internet.fr/matmac/sourcesc.htm
+
+ * Copyright 2001 Phil Karn, KA9Q
+ * May be used under the terms of the GNU Public License (GPL)
+ */
+
+#include "malloc16.h"
+#include <string.h>
+
+void *malloc16Align(int size){
+  void *p;
+  void **p1;
+
+  if((p = malloc(size+31)) == NULL)
+    return NULL;
+
+  /* Round up to next 16-byte boundary */
+  p1 = (void **)(((long)p + 31) & (~15));
+
+  /* Stash actual start of block just before ptr we return */
+  p1[-1] = p;
+
+  /* Return 16-byte aligned address */
+  return (void *)p1;
+}
+
+void *calloc16Align(size_t nmemb,size_t size){
+  int nbytes;
+  void *p;
+
+  nbytes = nmemb*size;
+  if((p = malloc16Align(nbytes)) == NULL)
+    return NULL;
+
+  memset(p,0,nbytes);
+  return p;
+}
+
+void free16Align(void *p){
+
+  if(p != NULL){
+    /* Retrieve pointer to actual start of block and free it */
+    free(((void **)p)[-1]);
+  }
+}
-- 
cgit v1.2.3