source: git/libpolys/misc/auxiliary.h @ ea11dc

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