source: git/misc/auxiliary.h.in @ 8a455c

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