source: git/libpolys/misc/auxiliary.h.in @ 80d772

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