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

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