source: git/libpolys/misc/auxiliary.h @ 68e548

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