1 | #ifndef POLYS_IMPL_H |
---|
2 | #define POLYS_IMPL_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: polys-impl.h,v 1.3 2006-01-05 13:42:57 Singular Exp $ */ |
---|
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 "structs.h" |
---|
19 | #include "omalloc.h" |
---|
20 | |
---|
21 | /*************************************************************** |
---|
22 | * |
---|
23 | * definition of the poly structure and its fields |
---|
24 | * |
---|
25 | ***************************************************************/ |
---|
26 | |
---|
27 | #ifndef NDEBUG |
---|
28 | #define VARS (10) /*max. number of variables as constant*/ |
---|
29 | #else |
---|
30 | #ifdef __GNUC__ |
---|
31 | #define VARS (0) |
---|
32 | #else |
---|
33 | #define VARS (1) |
---|
34 | #endif |
---|
35 | #endif |
---|
36 | |
---|
37 | typedef Exponent_t* Exponent_pt; |
---|
38 | struct spolyrec |
---|
39 | { |
---|
40 | poly next; // next needs to be the first field |
---|
41 | number coef; // and coef the second --- do not change this !!! |
---|
42 | unsigned long exp[VARS]; // make sure that exp is aligned |
---|
43 | }; |
---|
44 | #define POLYSIZE (sizeof(poly) + sizeof(number)) |
---|
45 | #define POLYSIZEW (POLYSIZE / sizeof(long)) |
---|
46 | #if SIZEOF_LONG == 8 |
---|
47 | #define POLY_NEGWEIGHT_OFFSET (((long)0x80000000) << 32) |
---|
48 | #else |
---|
49 | #define POLY_NEGWEIGHT_OFFSET ((long)0x80000000) |
---|
50 | #endif |
---|
51 | |
---|
52 | |
---|
53 | /*************************************************************** |
---|
54 | * |
---|
55 | * What should be inlined and debugged? |
---|
56 | * |
---|
57 | ***************************************************************/ |
---|
58 | #ifdef NO_PDEBUG |
---|
59 | #undef PDEBUG |
---|
60 | #endif |
---|
61 | |
---|
62 | // determines inlining of poly procs which iter through polys |
---|
63 | #if defined(DO_PINLINE0) && !defined(PDEBUG) |
---|
64 | #define PINLINE0 static inline |
---|
65 | #else |
---|
66 | #define PINLINE0 |
---|
67 | #endif |
---|
68 | |
---|
69 | // determines inlining of poly procs which iter over ExpVector |
---|
70 | #undef NO_PINLINE1 |
---|
71 | #if PDEBUG <= 0 && !defined(NO_INLINE1) |
---|
72 | #define PINLINE1 static inline |
---|
73 | #else |
---|
74 | #define PINLINE1 |
---|
75 | #define NO_PINLINE1 1 |
---|
76 | #endif |
---|
77 | |
---|
78 | // determines inlining of constant time poly procs |
---|
79 | #undef NO_PINLINE2 |
---|
80 | #if PDEBUG <= 1 && !defined(NO_INLINE2) |
---|
81 | #define PINLINE2 static inline |
---|
82 | #else |
---|
83 | #define PINLINE2 |
---|
84 | #define NO_PINLINE2 1 |
---|
85 | #endif |
---|
86 | |
---|
87 | // determines inlining of stuff from polys-impl.h |
---|
88 | #undef NO_PINLINE3 |
---|
89 | #if PDEBUG <= 2 && !defined(NO_INLINE3) |
---|
90 | #define PINLINE3 static inline |
---|
91 | #else |
---|
92 | #define PINLINE3 |
---|
93 | #define NO_PINLINE3 1 |
---|
94 | #endif |
---|
95 | |
---|
96 | /*************************************************************** |
---|
97 | * |
---|
98 | * prepare debugging |
---|
99 | * |
---|
100 | ***************************************************************/ |
---|
101 | |
---|
102 | #if defined(PDEBUG) |
---|
103 | |
---|
104 | extern BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...); |
---|
105 | |
---|
106 | // macros for checking of polys |
---|
107 | #define pAssumeReturn(cond) \ |
---|
108 | do \ |
---|
109 | { \ |
---|
110 | if (! (cond)) \ |
---|
111 | { \ |
---|
112 | dPolyReportError(NULL, NULL, "pAssume violation of: %s", \ |
---|
113 | #cond); \ |
---|
114 | return FALSE; \ |
---|
115 | } \ |
---|
116 | } \ |
---|
117 | while (0) |
---|
118 | |
---|
119 | #define pAssume(cond) \ |
---|
120 | do \ |
---|
121 | { \ |
---|
122 | if (! (cond)) \ |
---|
123 | { \ |
---|
124 | dPolyReportError(NULL, NULL, "pAssume violation of: %s", \ |
---|
125 | #cond); \ |
---|
126 | } \ |
---|
127 | } \ |
---|
128 | while (0) |
---|
129 | |
---|
130 | #define _pPolyAssumeReturn(cond, p, r) \ |
---|
131 | do \ |
---|
132 | { \ |
---|
133 | if (! (cond)) \ |
---|
134 | { \ |
---|
135 | dPolyReportError(p, r, "pPolyAssume violation of: %s", \ |
---|
136 | #cond); \ |
---|
137 | return FALSE; \ |
---|
138 | } \ |
---|
139 | } \ |
---|
140 | while (0) |
---|
141 | |
---|
142 | #define _pPolyAssume(cond,p,r) \ |
---|
143 | do \ |
---|
144 | { \ |
---|
145 | if (! (cond)) \ |
---|
146 | { \ |
---|
147 | dPolyReportError(p, r, "pPolyAssume violation of: %s", \ |
---|
148 | #cond); \ |
---|
149 | } \ |
---|
150 | } \ |
---|
151 | while (0) |
---|
152 | |
---|
153 | #define _pPolyAssumeReturnMsg(cond, msg, p, r) \ |
---|
154 | do \ |
---|
155 | { \ |
---|
156 | if (! (cond)) \ |
---|
157 | { \ |
---|
158 | dPolyReportError(p, r, "%s ", msg); \ |
---|
159 | return FALSE; \ |
---|
160 | } \ |
---|
161 | } \ |
---|
162 | while (0) |
---|
163 | |
---|
164 | #define pPolyAssume(cond) _pPolyAssume(cond, p, r) |
---|
165 | #define pPolyAssumeReturn(cond) _pPolyAssumeReturn(cond, p, r) |
---|
166 | #define pPolyAssumeReturnMsg(cond, msg) _pPolyAssumeReturnMsg(cond, msg, p, r) |
---|
167 | |
---|
168 | #define pFalseReturn(cond) do {if (! (cond)) return FALSE;} while (0) |
---|
169 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
170 | #define p_SetRingOfLm(p, r) omSetCustomOfAddr(p, r) |
---|
171 | void p_SetRingOfLeftv(leftv l, ring r); |
---|
172 | #else |
---|
173 | #define p_SetRingOfLm(p, r) ((void)0) |
---|
174 | #define p_SetRingOfLeftv(l, r) ((void)0) |
---|
175 | #endif |
---|
176 | |
---|
177 | #else // ! defined(PDEBUG) |
---|
178 | #define pFalseReturn(cond) ((void)0) |
---|
179 | #define pAssume(cond) ((void)0) |
---|
180 | #define pPolyAssume(cond) ((void)0) |
---|
181 | #define _pPolyAssume(cond, p,r) ((void)0) |
---|
182 | #define pAssumeReturn(cond) ((void)0) |
---|
183 | #define pPolyAssumeReturn(cond) ((void)0) |
---|
184 | #define _pPolyAssumeReturn(cond,p,r) ((void)0) |
---|
185 | #define p_SetRingOfLm(p, r) ((void)0) |
---|
186 | #define p_SetRingOfLeftv(l, r) ((void)0) |
---|
187 | #endif // defined(PDEBUG) |
---|
188 | |
---|
189 | #if PDEBUG >= 1 |
---|
190 | #define pAssume1 pAssume |
---|
191 | #define pPolyAssume1 pPolyAssume |
---|
192 | #define _pPolyAssume1 _pPolyAssume |
---|
193 | #define pAssumeReturn1 pAssumeReturn |
---|
194 | #define pPolyAssumeReturn1 pPolyAssumeReturn |
---|
195 | #define _pPolyAssumeReturn1 _pPolyAssumeReturn |
---|
196 | #define p_LmCheckPolyRing1 p_LmCheckPolyRing |
---|
197 | #define p_CheckRing1 p_CheckRing |
---|
198 | #define pIfThen1 pIfThen |
---|
199 | #else |
---|
200 | #define pAssume1(cond) ((void)0) |
---|
201 | #define pPolyAssume1(cond) ((void)0) |
---|
202 | #define _pPolyAssume1(cond,p,r) ((void)0) |
---|
203 | #define pAssumeReturn1(cond) ((void)0) |
---|
204 | #define pPolyAssumeReturn1(cond) ((void)0) |
---|
205 | #define _pPolyAssumeReturn1(cond,p,r)((void)0) |
---|
206 | #define p_LmCheckPolyRing1(p,r) ((void)0) |
---|
207 | #define p_CheckRing1(r) ((void)0) |
---|
208 | #define pIfThen1(cond, check) ((void)0) |
---|
209 | #endif // PDEBUG >= 1 |
---|
210 | |
---|
211 | #if PDEBUG >= 2 |
---|
212 | #define pAssume2 pAssume |
---|
213 | #define pPolyAssume2 pPolyAssume |
---|
214 | #define _pPolyAssume2 _pPolyAssume |
---|
215 | #define pAssumeReturn2 pAssumeReturn |
---|
216 | #define pPolyAssumeReturn2 pPolyAssumeReturn |
---|
217 | #define _pPolyAssumeReturn2 _pPolyAssumeReturn |
---|
218 | #define p_LmCheckPolyRing2 p_LmCheckPolyRing |
---|
219 | #define p_CheckRing2 p_CheckRing |
---|
220 | #define pIfThen2 pIfThen |
---|
221 | #else |
---|
222 | #define pAssume2(cond) ((void)0) |
---|
223 | #define pPolyAssume2(cond) ((void)0) |
---|
224 | #define _pPolyAssume2(cond,p,r) ((void)0) |
---|
225 | #define pAssumeReturn2(cond) ((void)0) |
---|
226 | #define pPolyAssumeReturn2(cond) ((void)0) |
---|
227 | #define _pPolyAssumeReturn2(cond,p,r)((void)0) |
---|
228 | #define p_LmCheckPolyRing2(p,r) ((void)0) |
---|
229 | #define p_CheckRing2(r) ((void)0) |
---|
230 | #define pIfThen2(cond, check) ((void)0) |
---|
231 | #endif // PDEBUG >= 2 |
---|
232 | |
---|
233 | /*************************************************************** |
---|
234 | * |
---|
235 | * Macros for access/iteration |
---|
236 | * |
---|
237 | ***************************************************************/ |
---|
238 | #define _pNext(p) ((p)->next) |
---|
239 | #define _pIter(p) ((p) = (p)->next) |
---|
240 | |
---|
241 | // coeff |
---|
242 | #define _pGetCoeff(p) ((p)->coef) |
---|
243 | #define _pSetCoeff0(p,n) (p)->coef=n |
---|
244 | #define __p_GetComp(p, r) (p)->exp[r->pCompIndex] |
---|
245 | #define _p_GetComp(p, r) ((long) (r->pCompIndex >= 0 ? __p_GetComp(p, r) : 0)) |
---|
246 | |
---|
247 | /*************************************************************** |
---|
248 | * |
---|
249 | * Macros for low-level allocation |
---|
250 | * |
---|
251 | ***************************************************************/ |
---|
252 | #ifdef PDEBUG |
---|
253 | #define p_AllocBin(p, bin, r) \ |
---|
254 | do \ |
---|
255 | { \ |
---|
256 | omTypeAllocBin(poly, p, bin); \ |
---|
257 | p_SetRingOfLm(p, r); \ |
---|
258 | } \ |
---|
259 | while (0) |
---|
260 | #define p_FreeBinAddr(p, r) p_LmFree(p, r) |
---|
261 | #else |
---|
262 | #define p_AllocBin(p, bin, r) omTypeAllocBin(poly, p, bin) |
---|
263 | #define p_FreeBinAddr(p, r) omFreeBinAddr(p) |
---|
264 | #endif |
---|
265 | |
---|
266 | /*************************************************************** |
---|
267 | * |
---|
268 | * Misc macros |
---|
269 | * |
---|
270 | ***************************************************************/ |
---|
271 | #define rRing_has_Comp(r) (r->pCompIndex >= 0) |
---|
272 | |
---|
273 | // number of Variables |
---|
274 | extern int pVariables; |
---|
275 | |
---|
276 | #endif // POLYS_IMPL_H |
---|