source: git/libpolys/misc/auxiliary.h.in @ 41dde6

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