source: git/Singular/mmemory.h @ 421acf

spielwiese
Last change on this file since 421acf was 421acf, checked in by Hans Schönemann <hannes@…>, 25 years ago
*hannes: added Aligned for SIZEOF_DOUBLE=SIZEOF_PTR git-svn-id: file:///usr/local/Singular/svn/trunk@3191 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 14.7 KB
Line 
1#ifndef MMEMORY_H
2#define MMEMORY_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: mmemory.h,v 1.19 1999-06-30 11:53:59 Singular Exp $ */
7/*
8* ABSTRACT
9*/
10#include <stdlib.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include "structs.h"
17#include "mmheap.h"
18
19/**********************************************************************
20 *
21 * Memory allocation
22 *
23 **********************************************************************/
24
25#ifndef MDEBUG
26
27void * mmAllocBlock( size_t );
28void * mmAllocBlock0( size_t );
29void   mmFreeBlock( void*, size_t );
30void * mmReallocBlock( void*, size_t, size_t );
31void * mmReallocBlock0( void*, size_t, size_t );
32void * mmAlloc( size_t );
33void * mmRealloc( void*, size_t );
34void   mmFree( void* );
35char * mmStrdup( const char* );
36#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
37void * mmAllocAlignedBlock( size_t );
38void * mmAllocAlignedBlock0( size_t );
39void   mmFreeAlignedBlock( void*, size_t );
40#endif
41
42#define AllocHeap               mmAllocHeap
43#define FreeHeap                mmFreeHeap
44#define Alloc                   mmAllocBlock
45#define Alloc0                  mmAllocBlock0
46#define Free                    mmFreeBlock
47#define ReAlloc                 mmReallocBlock
48#define ReAlloc0                mmReallocBlock0
49#define FreeL                   mmFree
50#define AllocL                  mmAlloc
51#define mstrdup                 mmStrdup
52#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
53#define AllocAligned0           mmAllocAlignedBlock0
54#define AllocAligned            mmAllocAlignedBlock
55#define FreeAligned             mmFreeAlignedBlock
56#elif SIZEOF_DOUBLE == SIZEOF_VOIDP
57#define AllocAligned0           mmAllocBlock0
58#define AllocAligned            mmAllocBlock
59#define FreeAligned             mmFreeBlock
60#endif
61
62#else /* MDEBUG */
63
64void * mmDBAllocHeap(memHeap heap, char*, int );
65void   mmDBFreeHeap(void* addr, memHeap heap, char*, int );
66void * mmDBAllocBlock( size_t, char*, int );
67void * mmDBAllocBlock0( size_t,  char*, int);
68void   mmDBFreeBlock( void*, size_t, char*, int);
69void * mmDBReallocBlock( void*, size_t, size_t, char*, int );
70void * mmDBReallocBlock0( void*, size_t, size_t, char*, int );
71void * mmDBAlloc( size_t, char*, int );
72void * mmDBRealloc( void*, size_t, char*, int );
73void   mmDBFree( void*, char*, int );
74char * mmDBStrdup( const char * s, char *fname, int lineno);
75#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
76void * mmDBAllocAlignedBlock( size_t, char*, int );
77void * mmDBAllocAlignedBlock0( size_t,  char*, int);
78void   mmDBFreeAlignedBlock( void*, size_t, char*, int );
79#endif
80
81#define AllocHeap(res, heap)\
82  (res) = mmDBAllocHeap(heap, __FILE__, __LINE__)
83#define FreeHeap(addr, heap)\
84  mmDBFreeHeap(addr, heap,  __FILE__, __LINE__)
85#define Alloc(s)                mmDBAllocBlock(s, __FILE__, __LINE__)
86#define Alloc0(s)               mmDBAllocBlock0(s, __FILE__, __LINE__)
87#define Free(a,s)               mmDBFreeBlock(a, s, __FILE__, __LINE__)
88#define ReAlloc(a,o,n)          mmDBReallocBlock(a, o, n, __FILE__, __LINE__)
89#define ReAlloc0(a,o,n)         mmDBReallocBlock0(a, o, n, __FILE__, __LINE__)
90#define AllocL(s)               mmDBAlloc(s, __FILE__, __LINE__)
91#define FreeL(a)                mmDBFree(a,__FILE__,__LINE__)
92#define mstrdup(s)              mmDBStrdup(s, __FILE__, __LINE__)
93#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
94#define AllocAligned(s)         mmDBAllocAlignedBlock(s, __FILE__, __LINE__)
95#define AllocAligned0(s)        mmDBAllocAlignedBlock0(s, __FILE__, __LINE__)
96#define FreeAligned(a,s)        mmDBFreeAlignedBlock(a, s, __FILE__, __LINE__)
97#elif SIZEOF_DOUBLE == SIZEOF_VOIDP
98#define AllocAligned(s)         mmDBAllocBlock(s, __FILE__, __LINE__)
99#define AllocAligned0(s)        mmDBAllocBlock0(s, __FILE__, __LINE__)
100#define FreeAligned(a,s)        mmDBFreeBlock(a, s, __FILE__, __LINE__)
101#endif
102
103#endif /* MDEBUG */
104
105
106/**********************************************************************
107 *
108 * Tests of memory (for MDEBUG, only)
109 *
110 **********************************************************************/
111
112#ifdef MDEBUG
113
114/* use this variables to control level of MDEBUG at run-time
115   (see mod2.h for details) */
116extern int mm_MDEBUG;
117
118BOOLEAN mmDBTestHeapBlock(const void* adr, const memHeap heap,
119                          const char * fname, const int lineno );
120BOOLEAN mmDBTestBlock(const void* adr, const size_t size,
121                      const char * fname, const int lineno );
122BOOLEAN mmDBTest(const void* adr, const char * fname, const int lineno);
123
124#define mmTestHeap(a, h)\
125  mmDBTestHeapBlock(a, h, __FILE__, __LINE__)
126#define mmTest(A,B)     mmDBTestBlock(A,B,__FILE__,__LINE__)
127#define mmTestL(A)      mmDBTest(A,__FILE__,__LINE__)
128#define mmTestP(A,B)    mmDBTestBlock(A,B,__FILE__,__LINE__)
129#define mmTestLP(A)     mmDBTest(A,__FILE__,__LINE__)
130
131int mmTestMemory();
132int mmTestHeaps();
133
134void mmPrintUsedList();
135void mmMarkInitDBMCB();
136void mmTestList (int all);
137
138#else
139
140
141#define mmTestHeap(addr, heap) mmCheckHeapAddr(addr, heap)
142#define mmTest(A,B) TRUE
143#define mmTestL(A)  TRUE
144#define mmTestP(A,B)
145#define mmTestLP(A)
146#define mmTestMemory 1
147#define mmTestHeaps 1
148#define mmMarkInitDBMCB()
149#define mmTestList(a)
150
151#endif /* MDEBUG */
152
153
154/**********************************************************************
155 *
156 * Misc stuff
157 *
158 **********************************************************************/
159
160/* For handling of monomials */
161size_t mmSpecializeBlock( size_t );
162size_t mmGetSpecSize();
163extern memHeap mm_specHeap;
164
165/* for handling of memory statistics */
166int mmMemAlloc( void );
167int mmMemUsed( void );
168#ifdef HAVE_SBRK
169int mmMemPhysical( void );
170#endif
171void mmPrintStat();
172
173size_t mmSizeL( void* );
174
175/* max size of blocks which our memory managment handles */
176#define MAX_BLOCK_SIZE  (((SIZE_OF_HEAP_PAGE) / 16)*4)
177
178/**********************************************************************
179 *
180 * Some operations on linked lists of memory
181 *
182 **********************************************************************/
183/* The following routines assume that Next(list) == *((void**) list) */
184/* Removes element from list, if contained in it and returns list */
185void* mmRemoveFromList(void* list, void* element);
186/* Returns the length of a memory list; assumes list has no cycles */
187int mmListLength(void* list);
188/* Returns last non-NULL element of list; assumes list has no cycles */
189void* mmListLast(void* list);
190/* returns 1, if addr is contained in memory list
191 * 0, otherwise */
192int mmIsAddrOnList(void* addr, void* list);
193/* Checks whether memory list has cycles: If yes, returns address of
194 * first element of list which is contained at least twice in memory
195 * list. If no, NULL is returned */
196void* mmListHasCycle(void* list);
197
198/* The following routines assume that Next(list) == *((void**) list + next) */
199
200/* Returns the length of a memory list; assumes list has no cycles */
201int mmGListLength(void* list, int next);
202/* Returns last non-NULL element of list; assumes list has no cycles */
203void* mmGListLast(void* list, int next);
204/* returns 1, if addr is contained in memory list
205 * 0, otherwise */
206int mmIsAddrOnGList(void* addr, void* list, int next);
207/* Checks whether memory list has cycles: If yes, returns address of
208 * first element of list which is contained at least twice in memory
209 * list. If no, NULL is returned */
210void* mmGListHasCycle(void* list, int next);
211
212/**********************************************************************
213 *
214 * some fast macros for basic memory operations
215 *
216 **********************************************************************/
217#ifdef DO_DEEP_PROFILE
218extern void _memcpyW(void* p1, void* p2, long l);
219#define memcpy_nwEVEN(p1, p2, l)    _memcpyW((void*) p1, (void*) p2, (long) l)
220#define memcpy_nwODD(p1, p2, l)     _memcpyW((void*) p1, (void*) p2, (long) l)
221#define memcpyW(p1, p2, l)          _memcpyW((void*) p1, (void*) p2, (long) l)
222
223extern void _memaddW(void* p1, void* p2, void* p3, long l);
224#define memaddW(p1, p2, p3, l)          _memaddW(p1, p2, p3, l)
225#define memadd_nwODD(p1, p2, p3, l)     _memaddW(p1, p2, p3, l)
226#define memadd_nwEVEN(p1, p2, p3, l)    _memaddW(p1, p2, p3, l)
227#define memadd_nwONE(p1, p2, p3)        _memaddW(p1, p2, p3, 1)
228#define memadd_nwTWO(p1, p2, p3)        _memaddW(p1, p2, p3, 2)
229
230extern void _memsetW(void* p1, long w, long l);
231#define memsetW(p1, w, l) _memsetW(p1, w, l)
232
233#else /* ! DO_DEEP_PROFILE */
234
235#define memcpyW(p1, p2, l)                      \
236do                                              \
237{                                               \
238  long _i = l;                                  \
239  long* _s1 = (long*) p1;                       \
240  const long* _s2 = (long*) p2;                 \
241                                                \
242  for (;;)                                      \
243  {                                             \
244    *_s1 = *_s2;                                \
245    _i--;                                       \
246    if (_i == 0) break;                         \
247    _s1++;                                      \
248    _s2++;                                      \
249  }                                             \
250}                                               \
251while(0)
252
253#define memcpy_nwODD(p1, p2, l)                 \
254do                                              \
255{                                               \
256  long _i = l - 1;                              \
257  long* _s1 = (long*) p1;                       \
258  const long* _s2 = (long*) p2;                 \
259                                                \
260  *_s1++ = *_s2++;                              \
261  for (;;)                                      \
262  {                                             \
263    *_s1++ = *_s2++;                            \
264    *_s1++ = *_s2++;                            \
265    _i -= 2;                                    \
266    if (_i == 0) break;                         \
267  }                                             \
268}                                               \
269while(0)
270
271#define memcpy_nwEVEN(p1, p2, l)                \
272do                                              \
273{                                               \
274  long _i = l;                                  \
275  long* _s1 = (long*) p1;                       \
276  const long* _s2 = (long*) p2;                 \
277                                                \
278  for (;;)                                      \
279  {                                             \
280    *_s1++ = *_s2++;                            \
281    *_s1++ = *_s2++;                            \
282    _i -= 2;                                    \
283    if (_i == 0) break;                         \
284  }                                             \
285}                                               \
286while(0)
287
288#define memaddW(P1, P2, P3, L)                  \
289do                                              \
290{                                               \
291  unsigned long* _p1 = P1;                      \
292  const unsigned long* _p2 = P2;                \
293  const unsigned long* _p3 = P3;                \
294  unsigned long l = L;                          \
295                                                \
296  do                                            \
297  {                                             \
298    *_p1++ = *_p2++ + *_p3++;                   \
299    l--;                                        \
300  }                                             \
301  while(l);                                     \
302}                                               \
303while(0)
304
305#define memadd_nwODD(P1, P2, P3, L)             \
306do                                              \
307{                                               \
308  unsigned long* _p1 = P1;                      \
309  const unsigned long* _p2 = P2;                \
310  const unsigned long* _p3 = P3;                \
311  unsigned long l = L;                          \
312                                                \
313 *_p1++ = *_p2++ + *_p3++;                      \
314  l--;                                          \
315                                                \
316  do                                            \
317  {                                             \
318     *_p1++ = *_p2++ + *_p3++;                  \
319     *_p1++ = *_p2++ + *_p3++;                  \
320     l -=2;                                     \
321  }                                             \
322  while(l);                                     \
323}                                               \
324while(0)
325
326#define memadd_nwEVEN(P1, P2, P3, L)            \
327do                                              \
328{                                               \
329  unsigned long* _p1 = P1;                      \
330  const unsigned long* _p2 = P2;                \
331  const unsigned long* _p3 = P3;                \
332  unsigned long l = L;                          \
333                                                \
334  do                                            \
335  {                                             \
336     *_p1++ = *_p2++ + *_p3++;                  \
337     *_p1++ = *_p2++ + *_p3++;                  \
338     l -=2;                                     \
339  }                                             \
340  while(l);                                     \
341}                                               \
342while(0)
343
344#define memadd_nwONE(P1, P2, P3)                \
345do                                              \
346{                                               \
347  unsigned long* _p1 = P1;                      \
348  const unsigned long* _p2 = P2;                \
349  const unsigned long* _p3 = P3;                \
350                                                \
351 *_p1 = *_p2 + *_p3;                            \
352}                                               \
353while(0)
354
355#define memadd_nwTWO(P1, P2, P3)                \
356do                                              \
357{                                               \
358  unsigned long* _p1 = P1;                      \
359  const unsigned long* _p2 = P2;                \
360  const unsigned long* _p3 = P3;                \
361                                                \
362 *_p1++ = *_p2++ + *_p3++;                      \
363 *_p1 = *_p2 + *_p3;                            \
364}                                               \
365while(0)
366
367#define memsetW(P1, W, L)                       \
368do                                              \
369{                                               \
370  long* _p1 = P1;                               \
371  unsigned long _l = L;                         \
372  long _w = W;                                  \
373                                                \
374  while(_l)                                     \
375  {                                             \
376    *_p1++ = W;                                 \
377    _l--;                                       \
378  }                                             \
379}                                               \
380while(0)
381
382#endif /* DO_DEEP_PROFILE */
383
384#ifdef __cplusplus
385}
386#endif
387
388
389#endif
Note: See TracBrowser for help on using the repository browser.