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