source: git/libpolys/misc/auxiliary.h.in @ 8872ef

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