source: git/misc/auxiliary.h.in @ 0a59ea

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