source: git/libpolys/misc/auxiliary.h.in @ b4c4621

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