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