source: git/misc/auxiliary.h.in @ a59c630

spielwiese
Last change on this file since a59c630 was a59c630, checked in by Hans Schoenemann <hannes@…>, 14 years ago
HAVE_RINGS
  • Property mode set to 100644
File size: 9.9 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR   
3\*****************************************************************************/
4/** @file auxiliary.h
5 *
6 * All the auxiliary stuff.
7 *
8 * ABSTRACT: we shall put here everything that does not have its own place.
9 *
10 * @author Oleksandr Motsak
11 *
12 * @internal @version \$Id$
13 *
14 **/
15/*****************************************************************************/
16
17#ifndef MISC_AUXILIARY_H
18#define MISC_AUXILIARY_H
19     
20// ----------------- which parts/extensions of Singular to build
21#define HAVE_RINGS
22// ----------------  end of parts/extensions
23// -----------------  configure stuff
24
25/* CPU type: i[3456]86: */
26#undef SI_CPU_I386
27/* CPU type: sparc: */
28#undef SI_CPU_SPARC
29/* CPU type: ppc: */
30#undef SI_CPU_PPC
31/* CPU type: IA64: */
32#undef SI_CPU_IA64
33/* CPU type: x86_64: */
34#undef SI_CPU_X86_64
35
36/* Define sizeof(long) */
37#define SIZEOF_LONG 4
38
39// ----------------- end of configure stuff
40
41// ---------------- Singular standard types etc.
42// BOOLEAN
43
44#if (SIZEOF_LONG == 8)
45typedef int BOOLEAN;
46/* testet on x86_64, gcc 3.4.6: 2 % */
47/* testet on IA64, gcc 3.4.6: 1 % */
48#else
49/* testet on athlon, gcc 2.95.4: 1 % */
50typedef short BOOLEAN;
51#endif
52
53#ifndef FALSE
54#define FALSE       0
55#endif
56
57#ifndef TRUE
58#define TRUE        1
59#endif
60
61#ifndef NULL
62#define NULL        (0)
63#endif
64
65// #ifdef _TRY
66#ifndef ABS
67#define ABS(x) ((x)<0?(-(x)):(x))
68#endif
69// #endif
70
71static const int MAX_INT_LEN= 11;
72typedef void* ADDRESS;
73
74#define loop for(;;)
75
76static inline int si_max(const int a, const int b)  { return (a>b) ? a : b; }
77
78// ---------------- end of Singular standard types etc.
79// ---------------- defines which depend on the settings above
80
81#if defined(SI_CPU_I386) || defined(SI_CPU_X86_64)
82  // the following settings seems to be better on i386 and x86_64 processors
83  // define if a*b is with mod instead of tables
84#define HAVE_MULT_MOD
85  // #define HAVE_GENERIC_ADD
86  // #ifdef HAVE_MULT_MOD
87  // #define HAVE_DIV_MOD
88  // #endif
89#elif defined(SI_CPU_IA64)
90  // the following settings seems to be better on itanium processors
91  // #define HAVE_MULT_MOD
92#define HAVE_GENERIC_ADD
93  // #ifdef HAVE_MULT_MOD
94  // #define HAVE_DIV_MOD
95  // #endif
96#elif defined(SI_CPU_SPARC)
97  // #define HAVE_GENERIC_ADD
98#define HAVE_MULT_MOD
99#ifdef HAVE_MULT_MOD
100#define HAVE_DIV_MOD
101#endif
102#elif defined(SI_CPU_PPC)
103  // the following settings seems to be better on ppc processors
104  // testet on: ppc_Linux, 740/750 PowerMac G3, 512k L2 cache
105#define HAVE_MULT_MOD
106  // #ifdef HAVE_MULT_MOD
107  // #define HAVE_DIV_MOD
108  // #endif
109#endif
110
111
112/*******************************************************************
113 * DEBUG OPTIONS
114 * -- only significant for for compiling without -DNDEBUG
115 * -- you better know what your are doing, if you touch this
116 ******************************************************************/
117#ifndef NDEBUG
118
119/* undefine to enable inline */
120#define NO_INLINE
121
122/* undefine to disable assume -- should normally be defined for NDEBUG */
123#define HAVE_ASSUME
124
125/* undef PDEBUG to disable checks of polys
126
127 define PDEBUG to
128  0 for enabling pTest
129  1 plus tests in Level 1 poly routines (operations on monomials)
130  2 plus tests in Level 2 poly routines (operations on single exponents)
131 -- see also polys.h for more info
132
133 NOTE: you can set the value of PDEBUG on a per-file basis, before
134       including mod2.h, provided ! PDEBUG is defined in mod2.h E.g.:
135
136       #define PDEBUG 2
137       #include "auxiliary.h"
138       ...
139
140       makes sure that all poly operations in your file are done with
141       PDEBUG == 2
142 To break after an error occured, set a debugger breakpoint on
143 dErrorBreak.
144*/
145#ifndef PDEBUG
146#define PDEBUG 0
147#endif
148
149/* define MDEBUG to enable memory checks */
150#define MDEBUG 0
151
152#ifdef MDEBUG
153/* If ! defined(OM_NDEBUG) and (defined(OM_TRACK) or defined(OM_CHECK)
154   then omDebug routines are used for memory allocation/free:
155
156   The omDebug routines are controlled by the values of OM_TRACK, OM_CHECK
157   and OM_KEEP.  There meaning is roughly as follows:
158   OM_TRACK: strored with address                              : extra space
159     0     : no additional info is stored                      : 0
160     1     : file:line of location where address was allocated : 1 word
161     2     : plus backtrace of stack where adress was allocated: 6 words
162     3     : plus size/bin info and front-, and back padding   : 9 words
163     4     : plus file:line of location where adress was freed : 10 words
164     5     : plus backtrace of stack where adress was allocated: 15 words
165   OM_CHECK: checks done
166     0     : no checks
167     1     : constant-time checks: i.e. addr checks only
168     2     : plus linear-time checks and constant related bin check
169     3     : plus quadratic-time checks and linear-time related bin checks and
170             constant time all memory checks
171     4     : and so on
172     ==> for OM_CHECK >= 3 it gets rather slow
173   OM_KEEP:  determines whether addresses are really freed  (
174     0     : addresses are really freed
175     1     : addresses are only marked as free and not really freed.
176
177   OM_CHECK, OM_TRACK, and OM_KEEP can be set on a per-file basis
178   (as can OM_NDEBUG),  e.g.:
179     #define OM_CHECK 3
180     #define OM_TRACK 5
181     #define OM_KEEP  1
182     #include "mod2.h"
183     #include "omalloc.h"
184   ensures that all memory allocs/free in this file are done with
185   OM_CHECK==3 and OM_TRACK==5, and that all addresses allocated/freed
186   in this file are only marked as free and never really freed.
187 
188   To set OM_CHECK, OM_TRACK and OM_KEEP under dynamic scope, set
189   om_Opts.MinCheck, om_Opts.MinTrack to the respectiv values and
190   om_Opts.Keep to the number of addresses which are kept before they are
191   actually freed. E.g.:
192     int check=om_Opts.MinCheck, track=om_Opts.MinTrack, keep= m_OPts.Keep;
193     om_Opts.MinCheck = 3; om_Opts.MinTrack = 5; omOpts.Keep = LONG_MAX;
194     ExternalRoutine();
195     om_Opts.MinCheck = check; omOpts.MinTrack = track; omOpts.Keep = keep;
196   ensures that all calls omDebug routines  occuring during the computation of
197   ExternalRoutine() are done with OM_CHECK==3 and OM_TRACK==5, and
198   calls to omFree only mark addresses as free and not really free them.
199
200   Furthermore, the value of OM_SING_KEEP (resp. om_Opts.Keep) specifies
201   how many addresses are kept before they are actually freed, independently
202   of the value of OM_KEEP.
203
204   Some tips on possible values of OM_TRACK, OM_CHECK, OM_KEEP:
205   + To find out about an address that has been freed twice, first locate the
206     file(s) where the error occured, and then at the beginning of these files:
207       #define OM_CHECK 3
208       #define OM_TRACK 5
209       #define OM_KEEP  1
210       #include "mod2.h"
211       #include "omalloc.h"
212     Under dynamic scope, do (e.g., from within the debugger):
213       om_Opts.MinCheck = 3; om_Opts.MinTrack = 5; omOpts.Keep = LONG_MAX;
214   + to find out where "memory corruption" occured, increase value of
215     OM_CHECK - the higher this value is, the more consistency checks are
216     done (However a value > 3 checks the entire memory each time an omalloc
217     routine is used!)
218   
219   Some more tips on the usage of omalloc:
220   + omAlloc*, omRealloc*, omFree*, omCheck* omDebug* omTest* rotuines
221     assume that sizes are > 0 and pointers are != NULL
222   + omalloc*, omrealloc*, omfree* omcheck*, omdebug* omtest* routines allow
223     NULL pointers and sizes == 0
224   + You can safely use any free/realloc routine in combination with any alloc
225     routine (including the debug versions): E.g., an address allocated with
226     omAllocBin can be freed with omfree, or an adress allocated with
227     om(Debug)Alloc can be freed with omfree, or omFree, or omFreeSize, etc.
228     However, keep in mind that the efficiency decreases from
229     Bin over Size to General routines (i.e., omFreeBin is more efficient than
230     omFreeSize which is more efficient than omFree, likewise with the alloc
231     routines).
232   + if OM_CHECK is undefined or 0, then all omCheck routines do nothing
233   + if OM_CHECK and OM_TRACK are both undefined (or 0), or if OM_NDEBUG is
234     defined, then the "real" alloc/realloc/free macros are used, and all
235     omTest, omDebug and omCheck routines are undefined
236   + to break after an omError occured within a debugger,
237     set a breakpoint on dErrorBreak
238   + to do checks from within the debugger, or to do checks with explicit
239     check level, use omTest routines.
240*/
241
242/* by default, store alloc info and file/line where addr was freed */
243#ifndef OM_TRACK
244#define OM_TRACK 4
245#endif
246/* only do constant-time memory checks */
247#ifndef OM_CHECK
248#define OM_CHECK 1
249#endif
250/* Do actually free memory:
251   (be careful: if this is set, memory is never really freed,
252    but only marked as free) */
253#ifndef OM_KEEP
254#define OM_KEEP 0
255#endif
256/* but only after you have freed 1000 more addresses
257   (this is actually independent of the value of OM_KEEP and used
258   to initialize om_Opts.Keep) */
259#ifndef OM_SING_KEEP
260#define OM_SING_KEEP 1000
261#endif
262
263#endif /* MDEBUG */
264
265
266/* undef KDEBUG for check of data during std computations
267 *
268 * define KDEBUG to
269 * 0 for basic tests
270 * 1 for tests in kSpoly
271 * NOTE: You can locally enable tests in kspoly by setting the
272 *       define at the beginning of kspoly.cc
273 */
274#define KDEBUG 0
275
276/* define LDEBUG checking numbers, undefine otherwise */
277#define LDEBUG
278/* define RDEBUG checking rings (together with TRACE=9) */
279#define RDEBUG
280/* define TEST for non time critical tests, undefine otherwise */
281#define TEST
282
283/* define YYDEBUG 1 for debugging bison texts, 0 otherwise */
284#define YYDEBUG 1
285
286#endif
287/* end of debugging option (ifndef NDEBUG) */
288
289
290
291#ifdef _DEBUG
292#      define FORCEINLINE inline
293#else
294#ifdef NDEBUG
295#if   defined(_MSC_VER)
296#      define FORCEINLINE __forceinline
297#elif defined(__GNUC__) && __GNUC__ > 3
298#      define FORCEINLINE inline __attribute__ ((always_inline))
299#else
300#      define FORCEINLINE inline
301#endif
302#else
303#      define FORCEINLINE inline
304#endif
305/* NDEBUG */
306#endif
307/* _DEBUG */
308
309
310
311#endif
312/* MISC_AUXILIARY_H */
313
Note: See TracBrowser for help on using the repository browser.