source: git/polys/polys-impl.h @ 3fe3da0

spielwiese
Last change on this file since 3fe3da0 was 3fe3da0, checked in by Hans Schoenemann <hannes@…>, 14 years ago
fixed coeff macros
  • Property mode set to 100644
File size: 8.5 KB
Line 
1#ifndef POLYS_IMPL_H
2#define POLYS_IMPL_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7
8/***************************************************************
9 *
10 * File:       polys-impl.h
11 * Purpose:    low-level and macro definition of polys
12 *
13 * If you touch anything here, you better know what you are doing.
14 * What is here should not be used directly from other routines -- the
15 * encapsulations in polys.h should be used, instead.
16 *
17 ***************************************************************/
18#include <omalloc.h>
19
20/***************************************************************
21 *
22 * definition of the poly structure and its fields
23 *
24 ***************************************************************/
25
26struct  spolyrec
27{
28  poly      next;           // next needs to be the first field
29  number    coef;           // and coef the second --- do not change this !!!
30  unsigned long exp[1];     // make sure that exp is aligned
31};
32#define POLYSIZE (sizeof(poly) + sizeof(number))
33#define POLYSIZEW (POLYSIZE / sizeof(long))
34#if SIZEOF_LONG == 8
35#define POLY_NEGWEIGHT_OFFSET (((long)0x80000000) << 32)
36#else
37#define POLY_NEGWEIGHT_OFFSET ((long)0x80000000)
38#endif
39
40
41/***************************************************************
42 *
43 * What should be inlined and debugged?
44 *
45 ***************************************************************/
46#ifdef NO_PDEBUG
47#undef PDEBUG
48#endif
49
50// determines inlining of poly procs which iter through polys
51#if defined(DO_PINLINE0) && !defined(PDEBUG)
52#define PINLINE0 static inline
53#else
54#define PINLINE0
55#endif
56
57// determines inlining of poly procs which iter over ExpVector
58#undef NO_PINLINE1
59#if PDEBUG <= 0 && !defined(NO_INLINE1)
60#define PINLINE1 static inline
61#else
62#define PINLINE1
63#define NO_PINLINE1 1
64#endif
65
66// determines inlining of constant time poly procs
67#undef NO_PINLINE2
68#if PDEBUG <= 1 && !defined(NO_INLINE2)
69#define PINLINE2 static inline
70#else
71#define PINLINE2
72#define NO_PINLINE2 1
73#endif
74
75// determines inlining of stuff from polys-impl.h
76#undef NO_PINLINE3
77#if PDEBUG <= 2 && !defined(NO_INLINE3)
78#define PINLINE3 static inline
79#else
80#define PINLINE3
81#define NO_PINLINE3 1
82#endif
83
84/***************************************************************
85 *
86 * prepare debugging
87 *
88 ***************************************************************/
89
90#if defined(PDEBUG)
91
92extern BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...);
93
94// macros for checking of polys
95#define pAssumeReturn(cond)                                  \
96do                                                          \
97{                                                           \
98  if (! (cond))                                             \
99  {                                                         \
100    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
101                 #cond);                                    \
102    return FALSE;                                           \
103  }                                                         \
104}                                                           \
105while (0)
106
107#define pAssume(cond)                                        \
108do                                                          \
109{                                                           \
110  if (! (cond))                                             \
111  {                                                         \
112    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
113                 #cond);                                    \
114  }                                                         \
115}                                                           \
116while (0)
117
118#define pPolyAssumeReturn(cond, p, r)                       \
119do                                                          \
120{                                                           \
121  if (! (cond))                                             \
122  {                                                         \
123    dPolyReportError(p, r, "pPolyAssume violation of: %s",   \
124                 #cond);                                    \
125    return FALSE;                                           \
126  }                                                         \
127}                                                           \
128while (0)
129
130#define pPolyAssume(cond,p,r)                                   \
131do                                                              \
132{                                                               \
133  if (! (cond))                                                 \
134  {                                                             \
135    dPolyReportError(p, r, "pPolyAssume violation of: %s",    \
136                 #cond);                                        \
137  }                                                             \
138}                                                               \
139while (0)
140
141#define pPolyAssumeReturnMsg(cond, msg, p, r)   \
142do                                              \
143{                                               \
144  if (! (cond))                                 \
145  {                                             \
146    dPolyReportError(p, r, "%s ",  msg);        \
147    return FALSE;                               \
148  }                                             \
149}                                               \
150while (0)
151
152#define pFalseReturn(cond)  do {if (! (cond)) return FALSE;} while (0)
153#if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
154#define p_SetRingOfLm(p, r) omSetCustomOfAddr(p, r)
155void p_SetRingOfLeftv(leftv l, ring r);
156#else
157#define p_SetRingOfLm(p, r) ((void)0)
158#define p_SetRingOfLeftv(l, r) ((void)0)
159#endif
160
161#else // ! defined(PDEBUG)
162#define pFalseReturn(cond)           ((void)0)
163#define pAssume(cond)                ((void)0)
164#define pPolyAssume(cond, p,r)      ((void)0)
165#define pPolyAssumeReturn(cond,p,r) ((void)0)
166#define p_SetRingOfLm(p, r)          ((void)0)
167#define p_SetRingOfLeftv(l, r)       ((void)0)
168#endif // defined(PDEBUG)
169
170#if PDEBUG >= 1
171#define pAssume1             pAssume
172#define pPolyAssume1         pPolyAssume
173#define pAssumeReturn1       pAssumeReturn
174#define pPolyAssumeReturn1   pPolyAssumeReturn
175#define _pPolyAssumeReturn1  _pPolyAssumeReturn
176#define p_LmCheckPolyRing1    p_LmCheckPolyRing
177#define p_CheckRing1        p_CheckRing
178#define pIfThen1          pIfThen
179#else
180#define pAssume1(cond)               ((void)0)
181#define pPolyAssume1(cond)           ((void)0)
182#define pAssumeReturn1(cond)         ((void)0)
183#define pPolyAssumeReturn1(cond)     ((void)0)
184#define p_LmCheckPolyRing1(p,r)       ((void)0)
185#define p_CheckRing1(r)             ((void)0)
186#define pIfThen1(cond, check)     ((void)0)
187#endif // PDEBUG >= 1
188
189#if PDEBUG >= 2
190#define pAssume2             pAssume
191#define pPolyAssume2         pPolyAssume
192#define pAssumeReturn2       pAssumeReturn
193#define pPolyAssumeReturn2   pPolyAssumeReturn
194#define p_LmCheckPolyRing2    p_LmCheckPolyRing
195#define p_CheckRing2        p_CheckRing
196#define pIfThen2          pIfThen
197#else
198#define pAssume2(cond)                   ((void)0)
199#define pPolyAssume2(cond,p,r)           ((void)0)
200#define pAssumeReturn2(cond,p,r)         ((void)0)
201#define pPolyAssumeReturn2(cond,p,r)     ((void)0)
202#define p_LmCheckPolyRing2(p,r)          ((void)0)
203#define p_CheckRing2(r)                  ((void)0)
204#define pIfThen2(cond, check)            ((void)0)
205#endif // PDEBUG >= 2
206
207/***************************************************************
208 *
209 * Macros for access/iteration
210 *
211 ***************************************************************/
212
213#define __p_GetComp(p, r)   (p)->exp[r->pCompIndex]
214#define _p_GetComp(p, r)    ((long) (r->pCompIndex >= 0 ? __p_GetComp(p, r) : 0))
215
216/***************************************************************
217 *
218 * Macros for low-level allocation
219 *
220 ***************************************************************/
221#ifdef PDEBUG
222#define p_AllocBin(p, bin, r)                   \
223do                                              \
224{                                               \
225  omTypeAllocBin(poly, p, bin);                 \
226  p_SetRingOfLm(p, r);                        \
227}                                               \
228while (0)
229#define p_FreeBinAddr(p, r) p_LmFree(p, r)
230#else
231#define p_AllocBin(p, bin, r)   omTypeAllocBin(poly, p, bin)
232#define p_FreeBinAddr(p, r)     omFreeBinAddr(p)
233#endif
234
235/***************************************************************
236 *
237 * Misc macros
238 *
239 ***************************************************************/
240#define rRing_has_Comp(r)   (r->pCompIndex >= 0)
241
242// number of Variables
243extern int pVariables;
244
245#endif // POLYS_IMPL_H
Note: See TracBrowser for help on using the repository browser.