source: git/libpolys/misc/auxiliary.h @ 1820e7

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