M4RI  1.0.1
mmc.h
Go to the documentation of this file.
00001 
00009 #ifndef M4RI_MMC_H
00010 #define M4RI_MMC_H
00011 
00012 /*******************************************************************
00013 *
00014 *                 M4RI: Linear Algebra over GF(2)
00015 *
00016 *    Copyright (C) 2007, 2008 Gregory Bard <bard@fordham.edu>
00017 *    Copyright (C) 2008 Martin Albrecht <M.R.Albrecht@rhul.ac.uk>
00018 *
00019 *  Distributed under the terms of the GNU General Public License (GPL)
00020 *  version 2 or higher.
00021 *
00022 *    This code is distributed in the hope that it will be useful,
00023 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025 *    General Public License for more details.
00026 *
00027 *  The full text of the GPL is available at:
00028 *
00029 *                  http://www.gnu.org/licenses/
00030 *
00031 ********************************************************************/
00032 
00033 #include "misc.h"
00034 
00035 void *m4ri_mmc_malloc(size_t size);
00036 void m4ri_mmc_free(void *condemned, size_t size);
00037 void m4ri_mmc_cleanup(void);
00038 
00042 #define __M4RI_ENABLE_MMC
00043 
00047 #define __M4RI_MMC_NBLOCKS 16
00048 
00052 #define __M4RI_MMC_THRESHOLD __M4RI_CPU_L2_CACHE
00053 
00057 typedef struct _mm_block {
00061   size_t size;
00062 
00066   void *data;
00067 
00068 } mmb_t;
00069 
00078 static inline void *m4ri_mmc_calloc(size_t count, size_t size) {
00079 #ifdef __M4RI_ENABLE_MMC
00080   size_t total_size = count * size;
00081   if (total_size <= __M4RI_MMC_THRESHOLD)
00082   {
00083     void *ret = m4ri_mmc_malloc(total_size);
00084     memset((char*)ret, 0, total_size);
00085     return ret;
00086   }
00087 #endif
00088   return m4ri_mm_calloc(count, size);
00089 }
00090 
00091 #endif // M4RI_MMC_H