source: git/Singular/mmemory.h @ 416465

spielwiese
Last change on this file since 416465 was 416465, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* bug-fixes from work with Thomas git-svn-id: file:///usr/local/Singular/svn/trunk@3826 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 25.0 KB
Line 
1#ifndef MMEMORY_H
2#define MMEMORY_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: mmemory.h,v 1.31 1999-11-15 17:20:24 obachman Exp $ */
7/*
8* ABSTRACT
9*/
10#include <stdlib.h>
11#include <stdio.h>
12
13#ifdef __cplusplus
14extern "C" {
15#else
16#define inline static
17#endif
18
19#include "mod2.h"
20#include "structs.h"
21
22/**********************************************************************
23 *
24 * Memory allocation
25 *
26 **********************************************************************/
27#ifndef MDEBUG
28void * mmAllocBlock( size_t );
29void * mmAllocBlock0( size_t );
30void   mmFreeBlock( void*, size_t );
31void * mmReallocBlock( void*, size_t, size_t );
32void * mmReallocBlock0( void*, size_t, size_t );
33void * mmAlloc( size_t );
34void * mmRealloc( void*, size_t );
35void   mmFree( void* );
36char * mmStrdup( const char* );
37#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
38void * mmAllocAlignedBlock( size_t );
39void * mmAllocAlignedBlock0( size_t );
40void   mmFreeAlignedBlock( void*, size_t );
41#endif
42#define AllocHeap(h)            _AllocHeap(h)           
43#define Alloc0Heap(h)           _Alloc0Heap(h)
44#define AllocHeapType(h, t)     (t) AllocHeap(h)
45#define Alloc0HeapType(h, t)    (t) Alloc0Heap(h)
46#define FreeHeap                mmFreeHeap
47#define Alloc                   mmAllocBlock
48#define Alloc0                  mmAllocBlock0
49#define Free                    mmFreeBlock
50#define ReAlloc                 mmReallocBlock
51#define ReAlloc0                mmReallocBlock0
52#define FreeL                   mmFree
53#define AllocL                  mmAlloc
54#define mstrdup                 mmStrdup
55#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
56#define AllocAligned0           mmAllocAlignedBlock0
57#define AllocAligned            mmAllocAlignedBlock
58#define FreeAligned             mmFreeAlignedBlock
59#elif SIZEOF_DOUBLE == SIZEOF_VOIDP
60#define AllocAligned0           mmAllocBlock0
61#define AllocAligned            mmAllocBlock
62#define FreeAligned             mmFreeBlock
63#endif
64
65#else /* MDEBUG */
66
67void * mmDBAllocHeap(memHeap heap, char*, int );
68void * mmDBAlloc0Heap(memHeap heap, char*, int );
69void   mmDBFreeHeap(void* addr, memHeap heap, char*, int );
70void * mmDBAllocBlock( size_t, char*, int );
71void * mmDBAllocBlock0( size_t,  char*, int);
72void   mmDBFreeBlock( void*, size_t, char*, int);
73void * mmDBReallocBlock( void*, size_t, size_t, char*, int );
74void * mmDBReallocBlock0( void*, size_t, size_t, char*, int );
75void * mmDBAlloc( size_t, char*, int );
76void * mmDBRealloc( void*, size_t, char*, int );
77void   mmDBFree( void*, char*, int );
78char * mmDBStrdup( const char * s, char *fname, int lineno);
79#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
80void * mmDBAllocAlignedBlock( size_t, char*, int );
81void * mmDBAllocAlignedBlock0( size_t,  char*, int);
82void   mmDBFreeAlignedBlock( void*, size_t, char*, int );
83#endif
84
85#define AllocHeap(heap)         mmDBAllocHeap(heap, __FILE__, __LINE__)
86#define Alloc0Heap(heap)        mmDBAlloc0Heap(heap, __FILE__, __LINE__)
87#define AllocHeapType(heap,t)   (t) mmDBAllocHeap(heap, __FILE__, __LINE__)
88#define Alloc0HeapType(heap,t)  (t) mmDBAlloc0Heap(heap, __FILE__, __LINE__)
89#define FreeHeap(addr, heap)    mmDBFreeHeap(addr, heap,  __FILE__, __LINE__)
90#define Alloc(s)                mmDBAllocBlock(s, __FILE__, __LINE__)
91#define Alloc0(s)               mmDBAllocBlock0(s, __FILE__, __LINE__)
92#define Free(a,s)               mmDBFreeBlock(a, s, __FILE__, __LINE__)
93#define ReAlloc(a,o,n)          mmDBReallocBlock(a, o, n, __FILE__, __LINE__)
94#define ReAlloc0(a,o,n)         mmDBReallocBlock0(a, o, n, __FILE__, __LINE__)
95#define AllocL(s)               mmDBAlloc(s, __FILE__, __LINE__)
96#define FreeL(a)                mmDBFree(a,__FILE__,__LINE__)
97#define mstrdup(s)              mmDBStrdup(s, __FILE__, __LINE__)
98#if SIZEOF_DOUBLE == SIZEOF_VOIDP + SIZEOF_VOIDP
99#define AllocAligned(s)         mmDBAllocAlignedBlock(s, __FILE__, __LINE__)
100#define AllocAligned0(s)        mmDBAllocAlignedBlock0(s, __FILE__, __LINE__)
101#define FreeAligned(a,s)        mmDBFreeAlignedBlock(a, s, __FILE__, __LINE__)
102#elif SIZEOF_DOUBLE == SIZEOF_VOIDP
103#define AllocAligned(s)         mmDBAllocBlock(s, __FILE__, __LINE__)
104#define AllocAligned0(s)        mmDBAllocBlock0(s, __FILE__, __LINE__)
105#define FreeAligned(a,s)        mmDBFreeBlock(a, s, __FILE__, __LINE__)
106#endif
107
108#endif /* MDEBUG */
109
110/**********************************************************************
111 *
112 * ASO stuff -- enable/disable in mod2.h
113 *
114 **********************************************************************/
115#if defined(HAVE_ASO) && HAVE_ASO == 1
116
117/* definitions of ALLOC_SIZE_OF_## are given in *.aso */
118
119#define AllocSizeOf(x)  ALLOC_SIZE_OF_##x
120#define Alloc0SizeOf(x) ALLOC0_SIZE_OF_##x
121#define FreeSizeOf(x,y) FREE_SIZE_OF_##y(x)
122
123#if defined(ASO_DEBUG) || defined(MDEBUG)
124void* mmDBAllocHeapSizeOf(memHeap heap, size_t size, char* file, int line);
125void* mmDBAlloc0HeapSizeOf(memHeap heap, size_t size, char* file, int line);
126void  mmDBFreeHeapSizeOf(void* addr, memHeap heap, size_t size, 
127                         char* file, int line);
128#define AllocHeapSizeOf(h, s, t) (t) mmDBAllocHeapSizeOf(h, s, __FILE__, __LINE__)
129#define Alloc0HeapSizeOf(h, s, t) (t) mmDBAlloc0HeapSizeOf(h, s, __FILE__, __LINE__)
130#define FreeHeapSizeOf(x, h, s) mmDBFreeHeapSizeOf(x, h, s, __FILE__, __LINE__)
131#else /* ! (ASO_DEBUG || MDEBUG) */
132#define AllocHeapSizeOf(h, s, t)   AllocHeapType(h, t)
133#define Alloc0HeapSizeOf(h, s, t)  Alloc0HeapType(h, t)
134#define FreeHeapSizeOf(x, h, s) FreeHeap(x, h)
135#endif /* ASO_DEBUG || MDEBUG */
136
137#else
138/* defaults for AllocSizeOf stuff -- should be redefined by *.aso files */
139#define AllocSizeOf(x)    Alloc(sizeof(x))
140#define Alloc0SizeOf(x)   Alloc0(sizeof(x))
141#define FreeSizeOf(x, y)  Free(x, sizeof(y))
142#endif /* HAVE_ASO */
143
144
145/**********************************************************************
146 *
147 * Tests of memory (for MDEBUG, only)
148 *
149 **********************************************************************/
150
151#ifdef MDEBUG
152
153/* use this variables to control level of MDEBUG at run-time
154   (see mod2.h for details) */
155extern int mm_MDEBUG;
156
157BOOLEAN mmDBTestHeapBlock(const void* adr, const memHeap heap,
158                          const char * fname, const int lineno );
159BOOLEAN mmDBTestBlock(const void* adr, const size_t size,
160                      const char * fname, const int lineno );
161BOOLEAN mmDBTest(const void* adr, const char * fname, const int lineno);
162
163#if MDEBUG >= 0
164#define mmTestHeap(a, h)\
165  mmDBTestHeapBlock(a, h, __FILE__, __LINE__)
166#define mmTest(A,B)     mmDBTestBlock(A,B,__FILE__,__LINE__)
167#define mmTestL(A)      mmDBTest(A,__FILE__,__LINE__)
168#define mmTestP(A,B)    mmDBTestBlock(A,B,__FILE__,__LINE__)
169#define mmTestLP(A)     mmDBTest(A,__FILE__,__LINE__)
170#else /* MDEBUG < 0 */
171#define mmTestHeap(addr, heap) mmCheckHeapAddr(addr, heap)
172#define mmTest(A,B) TRUE
173#define mmTestL(A)  TRUE
174#define mmTestP(A,B) TRUE
175#define mmTestLP(A)  TRUE
176#endif /* MDEBUG >= 0 */
177
178int mmTestMemory();
179
180void mmPrintUsedList();
181void mmMarkInitDBMCB();
182void mmMarkCurrentUsageState();
183void mmMarkCurrentUsageStart();
184void mmMarkCurrentUsageStop();
185void mmPrintUnMarkedBlocks();
186void mmStartReferenceWatch();
187void mmStopReferenceWatch();
188void mmTestList(FILE *fd, int all);
189
190#else
191
192
193#define mmTestHeap(addr, heap) mmCheckHeapAddr(addr, heap)
194#define mmTest(A,B) TRUE
195#define mmTestL(A)  TRUE
196#define mmTestP(A,B) TRUE
197#define mmTestLP(A)  TRUE
198#define mmTestMemory() TRUE
199#define mmMarkInitDBMCB()
200#define mmTestList(a)
201
202#endif /* MDEBUG */
203
204/**********************************************************************
205 *
206 * Public Heap Routines
207 *
208 **********************************************************************/
209
210/**********************************
211 *
212 * Creation/Destruction/Garbage Collection
213 *
214 **********************************/
215/* creates and initializes a temporary heap */
216extern memHeap mmGetTempHeap(size_t size);
217#ifndef HEAP_DEBUG
218/* UNCONDITIONALLY clears and destroys temporary heap */
219extern void mmUnGetTempHeap(memHeap *heap_p);
220#else
221#define mmUnGetTempHeap(h) mmDebugDestroyTempHeap(h)
222extern void mmUnGetTempHeap(memHeap *heap);
223#endif /* HEAP_DEBUG */
224
225// #define HAVE_AUTOMATIC_GC
226#ifndef HAVE_AUTOMATIC_GC
227/* removes chunks in freelist which fill one page */
228/* if strict & 1, does it even if free ptr  has not changed w.r.t. last gc */
229/* if strict & 2, also releases free pages */
230/* if strict & 4, gc also of temp heaps */
231extern void mmGarbageCollectHeaps(int strict);
232extern void mmGarbageCollectHeap(memHeap heap, int strict);
233#else
234#define  mmGarbageCollectHeaps(s)
235#define  mmGarbageCollectHeap(h, s)
236#endif /* HAVE_AUTOMATIC_GC */
237
238/* Returns a heap of the given size */
239extern memHeap mmGetSpecHeap( size_t );
240/* use this to "unget" (free) a heap once allocated with mmGetSpecHeap */
241extern void mmUnGetSpecHeap(memHeap *heap);
242 
243/* Merges what is free in Heap "what" into free list of heap "into" */
244extern void mmMergeHeap(memHeap into, memHeap what);
245
246/**********************************
247 *
248 * Allocate, Free from Heaps
249 *
250 **********************************/
251#ifndef HEAP_DEBUG
252#define mmAllocHeap(res, heap)  _mmAllocHeap(res, heap, void*)
253#define mmFreeHeap(addr, heap)  _mmFreeHeap(addr, heap)
254#define mmAllocHeapType(res, heap, type)  _mmAllocHeap(res, heap, type)
255#define mmCheckHeap(heap)           1
256#define mmCheckHeapAddr(addr, heap) 1
257#define mmTestHeaps()               1
258#else
259/*
260 * define HEAP_DEBUG  and/or set mm_HEAP_DEBUG to
261 * 0 to enable basic heap addr checks (at least on each alloc/free)
262 * 1 for addtl. containment checks in free/alloc list of heap
263 * 2 for addtl. check of entire  heap at each heap addr check
264 * NOTE: For HEAP_DEBUG > 1 on, it gets very slow
265 */
266extern int mm_HEAP_DEBUG;
267
268#define mmAllocHeapType(res, heap, type) \
269  (res) = (type)  mmDebugAllocHeap(heap, __FILE__, __LINE__)
270#define mmAllocHeap(res, heap) \
271  (res) = mmDebugAllocHeap(heap, __FILE__, __LINE__)
272void * mmDebugAllocHeap(memHeap heap, const char*, int );
273
274#define mmFreeHeap(addr, heap)\
275  mmDebugFreeHeap(addr, heap, __FILE__, __LINE__)
276void   mmDebugFreeHeap(void* addr, memHeap heap, const char*, int );
277
278#define mmCheckHeap(heap)\
279  mmDebugCheckHeap(heap, __FILE__, __LINE__)
280int mmDebugCheckHeap(memHeap heap, const char* fn, int line);
281
282#define mmCheckHeapAddr(addr, heap) \
283  mmDebugCheckHeapAdr(addr, heap, MM_HEAP_ADDR_USED_FLAG, __FILE__, __LINE__) 
284int mmDebugCheckHeapAddr(void* addr, memHeap heap, int flag,
285                         const char* fn, int l);
286int mmTestHeaps();
287#endif /* HEAP_DEBUG */
288
289/**********************************
290 *
291 * Low-level heap stuff
292 *
293 **********************************/
294/* Need to define it here, has to be known to macros */
295
296/* array of static heaps */
297extern struct sip_memHeap mm_theList[];
298extern memHeapPage mmAllocNewHeapPage(memHeap heap);
299
300#ifndef  HAVE_AUTOMATIC_GC
301struct sip_memHeapPage
302{
303  memHeapPage next;
304  long counter;
305};
306
307/* Change this appropriately, if you change sip_memHeapPage           */
308/* However, make sure that sizeof(sip_memHeapPage) is a multiple of 8 */
309#define SIZE_OF_HEAP_PAGE_HEADER (SIZEOF_VOIDP + SIZEOF_LONG)
310#define SIZE_OF_HEAP_PAGE (SIZE_OF_PAGE - SIZE_OF_HEAP_PAGE_HEADER)
311
312struct sip_memHeap
313{
314  void*         current; /* Freelist pointer */
315  memHeapPage   pages;   /* Pointer to linked list of pages */
316  void*         last_gc; /* current pointer after last gc */
317  long          size;    /* Size of heap chunks */
318};
319
320/* Allocates memory block from a heap */
321#define _mmAllocHeap(what, heap, type)                      \
322do                                                          \
323{                                                           \
324  register memHeap _heap = heap;                            \
325  if ((_heap)->current == NULL) mmAllocNewHeapPage(_heap);  \
326  what = (type)((_heap)->current);              \
327  (_heap)->current =  *((void**)(_heap)->current);          \
328}                                                           \
329while (0)
330
331/* Frees addr into heap, assumes  addr was previously allocated from heap */ 
332#define _mmFreeHeap(addr, heap)                \
333do                                              \
334{                                               \
335  register memHeap _heap = heap;                \
336  *((void**) addr) = (_heap)->current;          \
337  (_heap)->current = (void*) addr;              \
338}                                               \
339while (0)
340
341#else /* HAVE_AUTOMATIC_GC */
342
343struct sip_memHeapPage
344{
345  long          used_blocks;    /* number of used blocks of this page */
346  void*         current;        /* pointer to current freelist */
347  memHeapPage   next;           /* next/prev pointer of pages */
348  memHeapPage   prev;
349};
350
351/* Change this appropriately, if you change sip_memHeapPage           */
352/* However, make sure that sizeof(sip_memHeapPage) is a multiple of 8 */
353#define SIZE_OF_HEAP_PAGE_HEADER (3*SIZEOF_VOIDP + SIZEOF_LONG)
354#define SIZE_OF_HEAP_PAGE (SIZE_OF_PAGE - SIZE_OF_HEAP_PAGE_HEADER)
355
356struct sip_memHeap
357{
358  memHeapPage current_page;   /* page of current freelist */
359  memHeapPage last_page;      /* pointer to last page of freelist */
360  int size;                   /* size of blocks */
361  int max_blocks;             /* max(SIZE_OF_HEAP_PAGE / size, 1) */
362};
363
364extern memHeapPage  mmGetNewCurrentPage(memHeap heap);
365extern void mmRearrangeHeapPages(memHeapPage page, void* addr, memHeap heap);
366extern struct sip_memHeapPage mmZeroPage[];
367#ifndef mmGetPageOfAddr
368#define mmGetPageOfAddr(addr) \
369  ((void*) ((long) (addr) & ~(SIZE_OF_SYSTEM_PAGE -1)))
370#endif
371
372#define _mmAllocHeap(what, heap, type)                              \
373do                                                                  \
374{                                                                   \
375  register memHeapPage _page = (heap)->current_page;                \
376  if (_page->current == NULL) _page = mmGetNewCurrentPage(heap);    \
377  (_page->used_blocks)++;                                           \
378  what = (type)((_page)->current);                                  \
379  (_page)->current =  *((void**)(_page)->current);                  \
380}                                                                   \
381while (0)
382
383#define _mmFreeHeap(addr, heap)                         \
384do                                                      \
385{                                                       \
386  register memHeapPage _page = mmGetPageOfAddr(addr);   \
387  (_page->used_blocks)--;                               \
388  if (_page->used_blocks == 0)                          \
389    mmRearrangeHeapPages(_page, addr, heap);            \
390  else                                                  \
391  {                                                     \
392    *((void**) (addr)) = _page->current;                  \
393    _page->current = (addr);                              \
394  }                                                     \
395}                                                       \
396while (0)
397
398#endif /* ! HAVE_AUTOMATIC_GC */
399
400#define MM_HEAP_ADDR_UNKNOWN_FLAG 0 
401#define MM_HEAP_ADDR_USED_FLAG   1
402#define MM_HEAP_ADDR_FREE_FLAG   2
403/* use this for unknown heaps */
404#define MM_UNKNOWN_HEAP ((memHeap) 1)
405
406
407/**********************************************************************
408 *
409 * Misc stuff
410 *
411 **********************************************************************/
412/* for handling of memory statistics */
413int mmMemAlloc( void );
414int mmMemUsed( void );
415#ifdef HAVE_SBRK
416int mmMemPhysical( void );
417#endif
418void mmPrintStat();
419
420size_t mmSizeL( void* );
421
422/**********************************************************************
423 *
424 * Some operations on linked lists of memory
425 *
426 **********************************************************************/
427/* The following routines assume that Next(list) == *((void**) list) */
428/* Removes element from list, if contained in it and returns list */
429void* mmRemoveFromList(void* list, void* element);
430/* Returns the length of a memory list; assumes list has no cycles */
431int mmListLength(void* list);
432/* Returns last non-NULL element of list; assumes list has no cycles */
433void* mmListLast(void* list);
434/* returns 1, if addr is contained in memory list
435 * 0, otherwise */
436int mmIsAddrOnList(void* addr, void* list);
437/* Checks whether memory list has cycles: If yes, returns address of
438 * first element of list which is contained at least twice in memory
439 * list. If no, NULL is returned */
440void* mmListHasCycle(void* list);
441
442/* The following routines assume that Next(list) == *((void**) list + next) */
443
444/* Returns the length of a memory list; assumes list has no cycles */
445int mmGListLength(void* list, int next);
446/* Returns last non-NULL element of list; assumes list has no cycles */
447void* mmGListLast(void* list, int next);
448/* returns 1, if addr is contained in memory list
449 * 0, otherwise */
450int mmIsAddrOnGList(void* addr, void* list, int next);
451/* Checks whether memory list has cycles: If yes, returns address of
452 * first element of list which is contained at least twice in memory
453 * list. If no, NULL is returned */
454void* mmGListHasCycle(void* list, int next);
455/* Removes element from list, if contained in it and returns list */
456void* mmRemoveFromGList(void* list, int next, void* element);
457
458/* The following cast (list + int_field) to a pointer to int
459   and assume list is sorted in ascending order w.r.t. *(list + int_field)
460 */
461/* Inserts element at the right place */
462void* mmSortedInsertInGList(void* list, int next, int int_field, void* element);
463/* Finds element */
464void* mmFindInSortedGList(void* list, int next, int int_field, int what);
465 
466
467 
468/**********************************************************************
469 *
470 * some fast macros for basic memory operations
471 *
472 **********************************************************************/
473#ifdef DO_DEEP_PROFILE
474extern void _memcpyW(long* p1, long* p2, long l);
475#define memcpy_nwEVEN(p1, p2, l)    _memcpyW((long*) p1, (long*) p2, (long) l)
476#define memcpy_nwODD(p1, p2, l)     _memcpyW((long*) p1, (long*) p2, (long) l)
477#define memcpyW(p1, p2, l)          _memcpyW((long*) p1, (long*) p2, (long) l)
478
479extern void _memaddW(long* p1, long* p2, long* p3, long l);
480#define memaddW(p1, p2, p3, l)          _memaddW(p1, p2, p3, l)
481#define memadd_nwODD(p1, p2, p3, l)     _memaddW(p1, p2, p3, l)
482#define memadd_nwEVEN(p1, p2, p3, l)    _memaddW(p1, p2, p3, l)
483#define memadd_nwONE(p1, p2, p3)        _memaddW(p1, p2, p3, 1)
484#define memadd_nwTWO(p1, p2, p3)        _memaddW(p1, p2, p3, 2)
485
486extern void _memsetW(long* p1, long w, long l);
487#define memsetW(p1, w, l) _memsetW(p1, w, l)
488
489#else /* ! DO_DEEP_PROFILE */
490
491#define memcpyW(p1, p2, l)                      \
492do                                              \
493{                                               \
494  long _i = l;                                  \
495  long* _s1 = (long*) p1;                       \
496  const long* _s2 = (long*) p2;                 \
497                                                \
498  for (;;)                                      \
499  {                                             \
500    *_s1 = *_s2;                                \
501    _i--;                                       \
502    if (_i == 0) break;                         \
503    _s1++;                                      \
504    _s2++;                                      \
505  }                                             \
506}                                               \
507while(0)
508
509#define memcpy_nwODD(p1, p2, l)                 \
510do                                              \
511{                                               \
512  long _i = l - 1;                              \
513  long* _s1 = (long*) p1;                       \
514  const long* _s2 = (long*) p2;                 \
515                                                \
516  *_s1++ = *_s2++;                              \
517  for (;;)                                      \
518  {                                             \
519    *_s1++ = *_s2++;                            \
520    *_s1++ = *_s2++;                            \
521    _i -= 2;                                    \
522    if (_i == 0) break;                         \
523  }                                             \
524}                                               \
525while(0)
526
527#define memcpy_nwEVEN(p1, p2, l)                \
528do                                              \
529{                                               \
530  long _i = l;                                  \
531  long* _s1 = (long*) p1;                       \
532  const long* _s2 = (long*) p2;                 \
533                                                \
534  for (;;)                                      \
535  {                                             \
536    *_s1++ = *_s2++;                            \
537    *_s1++ = *_s2++;                            \
538    _i -= 2;                                    \
539    if (_i == 0) break;                         \
540  }                                             \
541}                                               \
542while(0)
543
544#define memaddW(P1, P2, P3, L)                  \
545do                                              \
546{                                               \
547  unsigned long* _p1 = P1;                      \
548  const unsigned long* _p2 = P2;                \
549  const unsigned long* _p3 = P3;                \
550  unsigned long l = L;                          \
551                                                \
552  do                                            \
553  {                                             \
554    *_p1++ = *_p2++ + *_p3++;                   \
555    l--;                                        \
556  }                                             \
557  while(l);                                     \
558}                                               \
559while(0)
560
561#define memadd_nwODD(P1, P2, P3, L)             \
562do                                              \
563{                                               \
564  unsigned long* _p1 = P1;                      \
565  const unsigned long* _p2 = P2;                \
566  const unsigned long* _p3 = P3;                \
567  unsigned long l = L;                          \
568                                                \
569 *_p1++ = *_p2++ + *_p3++;                      \
570  l--;                                          \
571                                                \
572  do                                            \
573  {                                             \
574     *_p1++ = *_p2++ + *_p3++;                  \
575     *_p1++ = *_p2++ + *_p3++;                  \
576     l -=2;                                     \
577  }                                             \
578  while(l);                                     \
579}                                               \
580while(0)
581
582#define memadd_nwEVEN(P1, P2, P3, L)            \
583do                                              \
584{                                               \
585  unsigned long* _p1 = P1;                      \
586  const unsigned long* _p2 = P2;                \
587  const unsigned long* _p3 = P3;                \
588  unsigned long l = L;                          \
589                                                \
590  do                                            \
591  {                                             \
592     *_p1++ = *_p2++ + *_p3++;                  \
593     *_p1++ = *_p2++ + *_p3++;                  \
594     l -=2;                                     \
595  }                                             \
596  while(l);                                     \
597}                                               \
598while(0)
599
600#define memadd_nwONE(P1, P2, P3)                \
601do                                              \
602{                                               \
603  unsigned long* _p1 = P1;                      \
604  const unsigned long* _p2 = P2;                \
605  const unsigned long* _p3 = P3;                \
606                                                \
607 *_p1 = *_p2 + *_p3;                            \
608}                                               \
609while(0)
610
611#define memadd_nwTWO(P1, P2, P3)                \
612do                                              \
613{                                               \
614  unsigned long* _p1 = P1;                      \
615  const unsigned long* _p2 = P2;                \
616  const unsigned long* _p3 = P3;                \
617                                                \
618 *_p1++ = *_p2++ + *_p3++;                      \
619 *_p1 = *_p2 + *_p3;                            \
620}                                               \
621while(0)
622
623#define memsetW(P1, W, L)                       \
624do                                              \
625{                                               \
626  long* _p1 = (long*) P1;                               \
627  unsigned long _l = L;                         \
628  long _w = (long) W;                                  \
629                                                \
630  while(_l)                                     \
631  {                                             \
632    *_p1++ = W;                                 \
633    _l--;                                       \
634  }                                             \
635}                                               \
636while(0)
637
638#endif /* DO_DEEP_PROFILE */
639
640#ifdef __cplusplus
641}
642int mmInit();
643#endif
644
645#if ! defined(MDEBUG)
646inline void* _AllocHeap(memHeap heap)
647{
648  void* ptr;
649  mmAllocHeap(ptr, heap);
650  return ptr;
651}
652inline void* _Alloc0Heap(memHeap heap)
653{
654  void* ptr;
655  mmAllocHeap(ptr, heap);
656  memsetW(ptr, 0, (heap->size) >> LOG_SIZEOF_LONG);
657  return ptr;
658}
659#endif
660
661
662#endif
Note: See TracBrowser for help on using the repository browser.