1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: p_Procs_Impl.h |
---|
6 | * Purpose: implementation of primitive procs for polys |
---|
7 | * Author: obachman (Olaf Bachmann) |
---|
8 | * Created: 12/00 |
---|
9 | * Version: $Id: p_Procs_Impl.h,v 1.7 2002-01-30 14:33:05 Singular Exp $ |
---|
10 | *******************************************************************/ |
---|
11 | #ifndef P_PROCS_IMPL_H |
---|
12 | #define P_PROCS_IMPL_H |
---|
13 | |
---|
14 | /*************************************************************** |
---|
15 | * |
---|
16 | * Configurations |
---|
17 | * |
---|
18 | *******************************************************************/ |
---|
19 | |
---|
20 | /*************************************************************** |
---|
21 | Here is how it works: |
---|
22 | At run-time, SetProcs is used to choose the appropriate PolyProcs |
---|
23 | based on the ring properies. |
---|
24 | At generate-time, SetProcs is used to generate all |
---|
25 | possible PolyProcs. |
---|
26 | Which PolyProcs are generated/used can be controled by values of |
---|
27 | HAVE_FAST_P_PROCS, HAVE_FAST_LENGTH, HAVE_FAST_ORD, and FAST_FIELD |
---|
28 | |
---|
29 | At generate-time, the file p_Procs.inc is generated, |
---|
30 | which provides implementations of the p_Procs, based on |
---|
31 | the p_*_Templates.cc and header files which provide the respective |
---|
32 | macros. |
---|
33 | |
---|
34 | At run-time, a fast proc is set/choosen if found/generated, else |
---|
35 | a general proc is set/choosen. |
---|
36 | *******************************************************************/ |
---|
37 | |
---|
38 | // Define HAVE_FAST_P_PROCS to: |
---|
39 | // 0 -- only FieldGeneral_LengthGeneral_OrdGeneral |
---|
40 | // 1 -- plus FieldZp_Length*_OrdGeneral procs |
---|
41 | // 2 -- plus FieldZp_Length*_Ord* procs |
---|
42 | // 3 -- plus FieldQ_Length*_Ord* |
---|
43 | // 4 -- plus FieldGeneral_Length*_OrdGeneral procs |
---|
44 | // 5 -- all Field*_Length*_Ord* procs |
---|
45 | #ifndef HAVE_FAST_P_PROCS |
---|
46 | #define HAVE_FAST_P_PROCS 0 |
---|
47 | #endif |
---|
48 | |
---|
49 | // Define HAVE_FAST_FIELD to: |
---|
50 | // 0 -- only FieldGeneral |
---|
51 | // 1 -- special cases for FieldZp |
---|
52 | // 2 -- plus special cases for FieldQ |
---|
53 | // nothing else is implemented, yet |
---|
54 | #ifndef HAVE_FAST_FIELD |
---|
55 | #define HAVE_FAST_FIELD 0 |
---|
56 | #endif |
---|
57 | |
---|
58 | // Define HAVE_FAST_LENGTH to: |
---|
59 | // 0 -- only LengthGeneral |
---|
60 | // 1 -- special cases for length <= 1 |
---|
61 | // 2 -- special cases for length <= 2 |
---|
62 | // 3 -- special cases for length <= 4 |
---|
63 | // 4 -- special cases for length <= 8 |
---|
64 | #ifndef HAVE_FAST_LENGTH |
---|
65 | #define HAVE_FAST_LENGTH 0 |
---|
66 | #endif |
---|
67 | |
---|
68 | // Define HAVE_FAST_ORD to: |
---|
69 | // 0 -- only OrdGeneral |
---|
70 | // 1 -- special for ords with n_min <= 1 |
---|
71 | // 2 -- special for ords with n_min <= 2 |
---|
72 | // 3 -- special ords for with n_min <= 3 |
---|
73 | // 4 -- special for all ords |
---|
74 | #ifndef HAVE_FAST_ORD |
---|
75 | #define HAVE_FAST_ORD 0 |
---|
76 | #endif |
---|
77 | |
---|
78 | // Define HAVE_FAST_ZERO_ORD to: |
---|
79 | // 0 -- no zero ords are considered |
---|
80 | // 1 -- only ZeroOrds for OrdPosNomogPosZero, OrdNomogPosZero, OrdPomogNegZero |
---|
81 | // 2 -- ZeroOrds for all |
---|
82 | #ifndef HAVE_FAST_ZERO_ORD |
---|
83 | #define HAVE_FAST_ZERO_ORD 0 |
---|
84 | #endif |
---|
85 | |
---|
86 | // undefine this, if ExpL_Size always equals CompLSize |
---|
87 | #define HAVE_LENGTH_DIFF |
---|
88 | |
---|
89 | |
---|
90 | // Predicate which returns true if alloc/copy/free of numbers is |
---|
91 | // like that of Zp |
---|
92 | #define ZP_COPY_FIELD(field) \ |
---|
93 | (field == FieldZp || field == FieldGF || field == FieldR) |
---|
94 | |
---|
95 | /*************************************************************** |
---|
96 | * |
---|
97 | * Definitions of our fields, lengths, ords, procs we work with |
---|
98 | * |
---|
99 | *******************************************************************/ |
---|
100 | |
---|
101 | // Here are the different parameters for setting the PolyProcs: |
---|
102 | |
---|
103 | // If you add/remove things from here, also remeber to adjust the |
---|
104 | // respective *_2_String |
---|
105 | typedef enum p_Field |
---|
106 | { |
---|
107 | FieldGeneral = 0, |
---|
108 | FieldZp, |
---|
109 | FieldQ, |
---|
110 | FieldR, |
---|
111 | FieldGF, |
---|
112 | #if HAVE_MORE_FIELDS_IMPLEMENTED |
---|
113 | FieldLong_R, |
---|
114 | FieldLong_C, |
---|
115 | FieldZp_a, |
---|
116 | FieldQ_a, |
---|
117 | #endif |
---|
118 | FieldUnknown |
---|
119 | } p_Field; |
---|
120 | typedef enum p_Length // Length of exponent vector in words |
---|
121 | { |
---|
122 | LengthGeneral = 0, // n >= 1 |
---|
123 | LengthEight, // n == 8 |
---|
124 | LengthSeven, |
---|
125 | LengthSix, |
---|
126 | LengthFive, |
---|
127 | LengthFour, |
---|
128 | LengthThree, |
---|
129 | LengthTwo, |
---|
130 | LengthOne, |
---|
131 | LengthUnknown |
---|
132 | } p_Length; |
---|
133 | typedef enum p_Ord |
---|
134 | { |
---|
135 | OrdGeneral = 0, |
---|
136 | // ordsgn |
---|
137 | // 0 1 i n-1 n n_min Example |
---|
138 | OrdPomog, // + + + + + 1 (lp,C) |
---|
139 | OrdNomog, // - - - - - 1 (ls, c), (ds, c) |
---|
140 | #define ORD_MAX_N_1 OrdNomog |
---|
141 | |
---|
142 | #ifdef HAVE_LENGTH_DIFF |
---|
143 | OrdPomogZero, // + + + + 0 2 (Dp, C), Even vars |
---|
144 | OrdNomogZero, // - - - - 0 2 (ds, c), Even vars |
---|
145 | #endif |
---|
146 | |
---|
147 | OrdNegPomog, // - + + + + 2 (c, lp), (Ds, c) |
---|
148 | OrdPomogNeg, // + + + + - 2 (lp, c) |
---|
149 | #define ORD_MAX_N_2 OrdPomogNeg |
---|
150 | |
---|
151 | OrdPosNomog, // + - - - + 3 (dp, c) (for n == 2, use PomogNeg) |
---|
152 | OrdNomogPos, // - - - - + 3 (ls, C) (for n == 2, use NegPomog) |
---|
153 | |
---|
154 | #ifdef HAVE_LENGTH_DIFF |
---|
155 | OrdNegPomogZero, // - + + + 0 3 (c, lp), (Ds, c) |
---|
156 | OrdPomogNegZero, // + + + - 0 3 (lp, c) |
---|
157 | #endif |
---|
158 | |
---|
159 | OrdPosPosNomog, // + + - - - 3 (C, dp) |
---|
160 | OrdPosNomogPos, // + - - - + 3 (dp, C) |
---|
161 | OrdNegPosNomog, // - + - - - 3 (c, dp) |
---|
162 | #define ORD_MAX_N_3 OrdNegPosNomog |
---|
163 | |
---|
164 | #ifdef HAVE_LENGTH_DIFF |
---|
165 | OrdNomogPosZero, // - - - + 0 4 (ls, C) (for n == 3, use NegPomogZero) |
---|
166 | OrdPosNomogZero, // + - - - 0 4 (dp, c) (for n == 3, use PomogNegZero) |
---|
167 | |
---|
168 | OrdPosPosNomogZero,// + + - - 0 4 (C, dp) |
---|
169 | OrdPosNomogPosZero,// + - - + 0 4 (dp, C) |
---|
170 | OrdNegPosNomogZero,// - + - - 0 4 (c, dp) |
---|
171 | #endif |
---|
172 | |
---|
173 | OrdUnknown |
---|
174 | } p_Ord; |
---|
175 | |
---|
176 | typedef enum p_Proc |
---|
177 | { |
---|
178 | p_Copy_Proc = 0, |
---|
179 | p_Delete_Proc, |
---|
180 | p_ShallowCopyDelete_Proc, |
---|
181 | p_Mult_nn_Proc, |
---|
182 | pp_Mult_nn_Proc, |
---|
183 | pp_Mult_mm_Proc, |
---|
184 | pp_Mult_mm_Noether_Proc, |
---|
185 | p_Mult_mm_Proc, |
---|
186 | p_Add_q_Proc, |
---|
187 | p_Minus_mm_Mult_qq_Proc, |
---|
188 | p_Neg_Proc, |
---|
189 | pp_Mult_Coeff_mm_DivSelect_Proc, |
---|
190 | pp_Mult_Coeff_mm_DivSelectMult_Proc, |
---|
191 | p_Merge_q_Proc, |
---|
192 | p_kBucketSetLm_Proc, |
---|
193 | p_Unknown_Proc |
---|
194 | } p_Proc; |
---|
195 | |
---|
196 | static inline char* p_FieldEnum_2_String(p_Field field) |
---|
197 | { |
---|
198 | switch(field) |
---|
199 | { |
---|
200 | case FieldGeneral: return "FieldGeneral"; |
---|
201 | case FieldZp: return "FieldZp"; |
---|
202 | case FieldQ: return "FieldQ"; |
---|
203 | case FieldR: return "FieldR"; |
---|
204 | case FieldGF: return "FieldGF"; |
---|
205 | #if HAVE_MORE_FIELDS_IMPLEMENTED |
---|
206 | case FieldLong_R: return "FieldLong_R"; |
---|
207 | case FieldLong_C: return "FieldLong_C"; |
---|
208 | case FieldZp_a: return "FieldZp_a"; |
---|
209 | case FieldQ_a: return "FieldQ_a"; |
---|
210 | #endif |
---|
211 | case FieldUnknown: return "FieldUnknown"; |
---|
212 | } |
---|
213 | return "NoField_2_String"; |
---|
214 | } |
---|
215 | |
---|
216 | static inline char* p_LengthEnum_2_String(p_Length length) |
---|
217 | { |
---|
218 | switch(length) |
---|
219 | { |
---|
220 | case LengthGeneral: return "LengthGeneral"; |
---|
221 | case LengthEight: return "LengthEight"; |
---|
222 | case LengthSeven: return "LengthSeven"; |
---|
223 | case LengthSix: return "LengthSix"; |
---|
224 | case LengthFive: return "LengthFive"; |
---|
225 | case LengthFour: return "LengthFour"; |
---|
226 | case LengthThree: return "LengthThree"; |
---|
227 | case LengthTwo: return "LengthTwo"; |
---|
228 | case LengthOne: return "LengthOne"; |
---|
229 | case LengthUnknown: return "LengthUnknown"; |
---|
230 | } |
---|
231 | return "NoLength_2_String"; |
---|
232 | } |
---|
233 | |
---|
234 | static inline char* p_OrdEnum_2_String(p_Ord ord) |
---|
235 | { |
---|
236 | switch(ord) |
---|
237 | { |
---|
238 | case OrdGeneral: return "OrdGeneral"; |
---|
239 | case OrdPomog: return "OrdPomog"; |
---|
240 | case OrdNomog: return "OrdNomog"; |
---|
241 | case OrdNegPomog: return "OrdNegPomog"; |
---|
242 | case OrdPomogNeg: return "OrdPomogNeg"; |
---|
243 | case OrdPosNomog: return "OrdPosNomog"; |
---|
244 | case OrdNomogPos: return "OrdNomogPos"; |
---|
245 | case OrdPosPosNomog: return "OrdPosPosNomog"; |
---|
246 | case OrdPosNomogPos: return "OrdPosNomogPos"; |
---|
247 | case OrdNegPosNomog: return "OrdNegPosNomog"; |
---|
248 | #ifdef HAVE_LENGTH_DIFF |
---|
249 | case OrdNegPomogZero: return "OrdNegPomogZero"; |
---|
250 | case OrdPomogNegZero: return "OrdPomogNegZero"; |
---|
251 | case OrdPomogZero: return "OrdPomogZero"; |
---|
252 | case OrdNomogZero: return "OrdNomogZero"; |
---|
253 | case OrdNomogPosZero: return "OrdNomogPosZero"; |
---|
254 | case OrdPosNomogZero: return "OrdPosNomogZero"; |
---|
255 | case OrdPosPosNomogZero: return "OrdPosPosNomogZero"; |
---|
256 | case OrdPosNomogPosZero: return "OrdPosNomogPosZero"; |
---|
257 | case OrdNegPosNomogZero: return "OrdNegPosNomogZero"; |
---|
258 | #endif |
---|
259 | case OrdUnknown: return "OrdUnknown"; |
---|
260 | } |
---|
261 | return "NoOrd_2_String"; |
---|
262 | } |
---|
263 | |
---|
264 | static inline char* p_ProcEnum_2_String(p_Proc proc) |
---|
265 | { |
---|
266 | switch(proc) |
---|
267 | { |
---|
268 | case p_Copy_Proc: return "p_Copy_Proc"; |
---|
269 | case p_Delete_Proc: return "p_Delete_Proc"; |
---|
270 | case p_ShallowCopyDelete_Proc: return "p_ShallowCopyDelete_Proc"; |
---|
271 | case p_Mult_nn_Proc: return "p_Mult_nn_Proc"; |
---|
272 | case pp_Mult_nn_Proc: return "pp_Mult_nn_Proc"; |
---|
273 | case pp_Mult_mm_Proc: return "pp_Mult_mm_Proc"; |
---|
274 | case pp_Mult_mm_Noether_Proc: return "pp_Mult_mm_Noether_Proc"; |
---|
275 | case p_Mult_mm_Proc: return "p_Mult_mm_Proc"; |
---|
276 | case p_Add_q_Proc: return "p_Add_q_Proc"; |
---|
277 | case p_Minus_mm_Mult_qq_Proc: return "p_Minus_mm_Mult_qq_Proc"; |
---|
278 | case p_Neg_Proc: return "p_Neg_Proc"; |
---|
279 | case pp_Mult_Coeff_mm_DivSelect_Proc: return "pp_Mult_Coeff_mm_DivSelect_Proc"; |
---|
280 | case pp_Mult_Coeff_mm_DivSelectMult_Proc: return "pp_Mult_Coeff_mm_DivSelectMult_Proc"; |
---|
281 | case p_Merge_q_Proc: return "p_Merge_q_Proc"; |
---|
282 | case p_kBucketSetLm_Proc: return "p_kBucketSetLm_Proc"; |
---|
283 | case p_Unknown_Proc: return "p_Unknown_Proc"; |
---|
284 | } |
---|
285 | return "NoProc_2_String"; |
---|
286 | } |
---|
287 | |
---|
288 | static inline int p_ProcDependsOn_Field(p_Proc proc) |
---|
289 | { |
---|
290 | if (proc == p_ShallowCopyDelete_Proc || |
---|
291 | proc == p_Merge_q_Proc) |
---|
292 | return 0; |
---|
293 | return 1; |
---|
294 | } |
---|
295 | |
---|
296 | static inline int p_ProcDependsOn_Ord(p_Proc proc) |
---|
297 | { |
---|
298 | switch(proc) |
---|
299 | { |
---|
300 | case p_Add_q_Proc: |
---|
301 | case p_Minus_mm_Mult_qq_Proc: |
---|
302 | case pp_Mult_mm_Noether_Proc: |
---|
303 | case p_kBucketSetLm_Proc: |
---|
304 | case p_Merge_q_Proc: |
---|
305 | return 1; |
---|
306 | |
---|
307 | default: |
---|
308 | return 0; |
---|
309 | } |
---|
310 | } |
---|
311 | |
---|
312 | static inline int p_ProcDependsOn_Length(p_Proc proc) |
---|
313 | { |
---|
314 | switch(proc) |
---|
315 | { |
---|
316 | case p_Delete_Proc: |
---|
317 | case p_Mult_nn_Proc: |
---|
318 | case p_Neg_Proc: |
---|
319 | return 0; |
---|
320 | |
---|
321 | default: |
---|
322 | return 1; |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | // returns string specifying the module into which the p_Proc |
---|
327 | // should go |
---|
328 | static inline const char* p_ProcField_2_Module(p_Proc proc, p_Field field) |
---|
329 | { |
---|
330 | if (! p_ProcDependsOn_Field(proc)) |
---|
331 | return "FieldIndep"; |
---|
332 | else |
---|
333 | { |
---|
334 | if (field > FieldQ) field = FieldGeneral; |
---|
335 | return p_FieldEnum_2_String(field); |
---|
336 | } |
---|
337 | } |
---|
338 | |
---|
339 | /*************************************************************** |
---|
340 | * |
---|
341 | * |
---|
342 | * Deal with OrdZero |
---|
343 | * |
---|
344 | *******************************************************************/ |
---|
345 | #ifdef HAVE_LENGTH_DIFF |
---|
346 | static inline int IsZeroOrd(p_Ord ord) |
---|
347 | { |
---|
348 | return (ord == OrdPomogZero || ord == OrdNomogZero || |
---|
349 | ord == OrdNegPomogZero || ord == OrdPosNomogZero || |
---|
350 | ord == OrdPomogNegZero || ord == OrdNomogPosZero || |
---|
351 | ord == OrdPosNomogPosZero || ord == OrdPosPosNomogZero || |
---|
352 | ord == OrdNegPosNomogZero); |
---|
353 | } |
---|
354 | |
---|
355 | static inline p_Ord ZeroOrd_2_NonZeroOrd(p_Ord ord, int strict) |
---|
356 | { |
---|
357 | if (IsZeroOrd(ord)) |
---|
358 | { |
---|
359 | switch (ord) |
---|
360 | { |
---|
361 | case OrdPomogZero: return OrdPomog; |
---|
362 | case OrdNomogZero: return OrdNomog; |
---|
363 | case OrdNegPomogZero: return OrdNegPomog; |
---|
364 | case OrdPosNomogZero: return OrdPosNomog; |
---|
365 | case OrdPosPosNomogZero: return OrdPosPosNomog; |
---|
366 | case OrdNegPosNomogZero: return OrdNegPosNomog; |
---|
367 | default: |
---|
368 | if (strict) return OrdGeneral; |
---|
369 | else if (ord == OrdPomogNegZero) return OrdPomogNeg; |
---|
370 | else if (ord == OrdNomogPosZero) return OrdNomogPos; |
---|
371 | else if (ord == OrdPosNomogPosZero) return OrdPosNomogPos; |
---|
372 | else return OrdGeneral; |
---|
373 | } |
---|
374 | } |
---|
375 | else |
---|
376 | { |
---|
377 | return ord; |
---|
378 | } |
---|
379 | } |
---|
380 | #else |
---|
381 | #define IsZeroOrd(ord) 0 |
---|
382 | #define ZeroOrd_2_NonZeroOrd(ord) (ord) |
---|
383 | #endif |
---|
384 | |
---|
385 | /*************************************************************** |
---|
386 | * |
---|
387 | * Filters which are applied to field/length/ord, before a proc is |
---|
388 | * choosen |
---|
389 | * |
---|
390 | *******************************************************************/ |
---|
391 | #ifdef p_Procs_Static |
---|
392 | static inline void StaticKernelFilter(p_Field &field, p_Length &length, |
---|
393 | p_Ord &ord, const p_Proc proc) |
---|
394 | { |
---|
395 | // simply exclude some things |
---|
396 | if ((proc == pp_Mult_mm_Noether_Proc || proc == p_kBucketSetLm_Proc) && |
---|
397 | (field != FieldZp)) |
---|
398 | { |
---|
399 | field = FieldGeneral; |
---|
400 | length = LengthGeneral; |
---|
401 | ord = OrdGeneral; |
---|
402 | } |
---|
403 | } |
---|
404 | #endif |
---|
405 | |
---|
406 | static inline void FastP_ProcsFilter(p_Field &field, p_Length &length, p_Ord &ord, const p_Proc proc) |
---|
407 | { |
---|
408 | if (HAVE_FAST_P_PROCS >= 5) return; |
---|
409 | |
---|
410 | if (HAVE_FAST_P_PROCS < 3 && field == FieldQ) |
---|
411 | field = FieldGeneral; |
---|
412 | |
---|
413 | if ((HAVE_FAST_P_PROCS == 0) || |
---|
414 | (HAVE_FAST_P_PROCS <= 4 && field != FieldZp && field != FieldQ && |
---|
415 | proc != p_Merge_q_Proc)) |
---|
416 | { |
---|
417 | field = FieldGeneral; |
---|
418 | length = LengthGeneral; |
---|
419 | ord = OrdGeneral; |
---|
420 | return; |
---|
421 | } |
---|
422 | if (HAVE_FAST_P_PROCS == 1 || |
---|
423 | (HAVE_FAST_P_PROCS == 4 && field != FieldZp && proc != p_Merge_q_Proc)) |
---|
424 | ord = OrdGeneral; |
---|
425 | } |
---|
426 | |
---|
427 | static inline void FastFieldFilter(p_Field &field) |
---|
428 | { |
---|
429 | if (HAVE_FAST_FIELD <= 0 || |
---|
430 | (HAVE_FAST_FIELD == 1 && field != FieldZp) || |
---|
431 | (field != FieldZp && field != FieldQ)) |
---|
432 | field = FieldGeneral; |
---|
433 | } |
---|
434 | |
---|
435 | static inline void FastLengthFilter(p_Length &length) |
---|
436 | { |
---|
437 | if ((HAVE_FAST_LENGTH == 3 && length <= LengthFive) || |
---|
438 | (HAVE_FAST_LENGTH == 2 && length <= LengthFour) || |
---|
439 | (HAVE_FAST_LENGTH == 1 && length <= LengthTwo) || |
---|
440 | (HAVE_FAST_LENGTH <= 0)) |
---|
441 | { |
---|
442 | length = LengthGeneral; |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | static inline void FastOrdFilter(p_Ord &ord) |
---|
447 | { |
---|
448 | if ((HAVE_FAST_ORD == 3 && ord >= OrdNomogPosZero) || |
---|
449 | (HAVE_FAST_ORD == 2 && ord >= OrdPosNomog) || |
---|
450 | (HAVE_FAST_ORD == 1 && ord >= OrdPomogZero) || |
---|
451 | (HAVE_FAST_ORD <= 0)) |
---|
452 | ord = OrdGeneral; |
---|
453 | } |
---|
454 | |
---|
455 | static inline void FastOrdZeroFilter(p_Ord &ord) |
---|
456 | { |
---|
457 | if (IsZeroOrd(ord)) |
---|
458 | { |
---|
459 | if ((HAVE_FAST_ZERO_ORD == 1 && (ord != OrdPosNomogPosZero && |
---|
460 | ord != OrdNomogPosZero && |
---|
461 | ord != OrdPomogNegZero)) || |
---|
462 | (HAVE_FAST_ZERO_ORD <= 0)) |
---|
463 | ord = ZeroOrd_2_NonZeroOrd(ord, 1); |
---|
464 | } |
---|
465 | } |
---|
466 | |
---|
467 | static inline void NCopy__Filter(p_Field &field) |
---|
468 | { |
---|
469 | if (ZP_COPY_FIELD(field)) field = FieldZp; |
---|
470 | } |
---|
471 | |
---|
472 | // in p_Add_q, p_MemCmp works with CompLSize, |
---|
473 | // hence, we do not need to consider ZeroOrds |
---|
474 | static inline void p_Add_q__Filter(p_Length &length, p_Ord &ord) |
---|
475 | { |
---|
476 | if (IsZeroOrd(ord)) |
---|
477 | { |
---|
478 | ord = ZeroOrd_2_NonZeroOrd(ord, 0); |
---|
479 | if (length > LengthGeneral) |
---|
480 | { |
---|
481 | length = (p_Length) ((int)length + 1); |
---|
482 | } |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | static inline void pp_Mult_mm_Noether_Filter(p_Field &field, |
---|
487 | p_Length &length, p_Ord &ord) |
---|
488 | { |
---|
489 | if (ord == OrdPomog |
---|
490 | || ord == OrdPomogZero |
---|
491 | || (ord == OrdPomogNeg && length > LengthTwo) |
---|
492 | #ifdef HAVE_LENGTH_DIFF |
---|
493 | || (ord == OrdPomogZero) |
---|
494 | || (ord == OrdPomogNegZero && length > LengthThree) |
---|
495 | #endif |
---|
496 | ) |
---|
497 | { |
---|
498 | // all the other orderings might occur (remeber Mixed Orderings!) |
---|
499 | field = FieldGeneral; |
---|
500 | ord = OrdGeneral; |
---|
501 | length = LengthGeneral; |
---|
502 | } |
---|
503 | } |
---|
504 | |
---|
505 | static inline void FastProcFilter(p_Proc proc, p_Field &field, |
---|
506 | p_Length &length, p_Ord &ord) |
---|
507 | { |
---|
508 | switch(proc) |
---|
509 | { |
---|
510 | case p_Add_q_Proc: |
---|
511 | case p_Merge_q_Proc: |
---|
512 | p_Add_q__Filter(length, ord); |
---|
513 | break; |
---|
514 | |
---|
515 | case p_Copy_Proc: |
---|
516 | case p_Delete_Proc: |
---|
517 | NCopy__Filter(field); |
---|
518 | break; |
---|
519 | |
---|
520 | case pp_Mult_mm_Noether_Proc: |
---|
521 | pp_Mult_mm_Noether_Filter(field, length, ord); |
---|
522 | break; |
---|
523 | |
---|
524 | case pp_Mult_Coeff_mm_DivSelectMult_Proc: |
---|
525 | if (length == LengthOne || length == LengthTwo) |
---|
526 | { |
---|
527 | field = FieldGeneral; |
---|
528 | length = LengthGeneral; |
---|
529 | ord = OrdGeneral; |
---|
530 | return; |
---|
531 | } |
---|
532 | break; |
---|
533 | |
---|
534 | default: break; |
---|
535 | } |
---|
536 | |
---|
537 | FastOrdFilter(ord); |
---|
538 | FastOrdZeroFilter(ord); |
---|
539 | FastLengthFilter(length); |
---|
540 | FastFieldFilter(field); |
---|
541 | FastP_ProcsFilter(field, length, ord, proc); |
---|
542 | #ifdef p_Procs_Static |
---|
543 | StaticKernelFilter(field, length, ord, proc); |
---|
544 | #endif |
---|
545 | } |
---|
546 | |
---|
547 | // returns 1 if combination of field/length/ord is invalid |
---|
548 | static inline int IsValidSpec(p_Field field, p_Length length, p_Ord ord) |
---|
549 | { |
---|
550 | if (field == FieldUnknown || length == LengthUnknown || ord == OrdUnknown) |
---|
551 | return 0; |
---|
552 | |
---|
553 | if (length >= LengthThree && // i.e. 1, 2, or 3 |
---|
554 | ord > ORD_MAX_N_3) // i.e. OrdNomogPosZero and below |
---|
555 | return 0; |
---|
556 | |
---|
557 | if (length >= LengthTwo && // i.e. 1 or 2 |
---|
558 | ord > ORD_MAX_N_2) // i.e. PosNomog and below |
---|
559 | return 0; |
---|
560 | |
---|
561 | if (length == LengthOne && |
---|
562 | ord > ORD_MAX_N_1) // i.e. PosPomogZero and below |
---|
563 | return 0; |
---|
564 | |
---|
565 | // we cover everything for length <= two |
---|
566 | if (ord == OrdGeneral && length >= LengthTwo) |
---|
567 | return 0; |
---|
568 | return 1; |
---|
569 | } |
---|
570 | |
---|
571 | |
---|
572 | static inline int index(p_Length length, p_Ord ord) |
---|
573 | { |
---|
574 | return length*OrdUnknown + ord; |
---|
575 | } |
---|
576 | |
---|
577 | static inline int index(p_Field field, p_Length length) |
---|
578 | { |
---|
579 | return field*LengthUnknown + length; |
---|
580 | } |
---|
581 | |
---|
582 | static inline int index(p_Field field, p_Length length, p_Ord ord) |
---|
583 | { |
---|
584 | return field*LengthUnknown*OrdUnknown + length*OrdUnknown + ord; |
---|
585 | } |
---|
586 | |
---|
587 | static inline int index(p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
588 | { |
---|
589 | switch(proc) |
---|
590 | { |
---|
591 | case p_Delete_Proc: |
---|
592 | case p_Mult_nn_Proc: |
---|
593 | case p_Neg_Proc: |
---|
594 | return field; |
---|
595 | |
---|
596 | case p_ShallowCopyDelete_Proc: |
---|
597 | return length; |
---|
598 | |
---|
599 | case p_Copy_Proc: |
---|
600 | case pp_Mult_mm_Proc: |
---|
601 | case p_Mult_mm_Proc: |
---|
602 | case pp_Mult_nn_Proc: |
---|
603 | case pp_Mult_Coeff_mm_DivSelect_Proc: |
---|
604 | case pp_Mult_Coeff_mm_DivSelectMult_Proc: |
---|
605 | return index(field, length); |
---|
606 | |
---|
607 | case p_Add_q_Proc: |
---|
608 | case p_Minus_mm_Mult_qq_Proc: |
---|
609 | case pp_Mult_mm_Noether_Proc: |
---|
610 | case p_kBucketSetLm_Proc: |
---|
611 | return index(field, length, ord); |
---|
612 | |
---|
613 | case p_Merge_q_Proc: |
---|
614 | return index(length, ord); |
---|
615 | |
---|
616 | default: |
---|
617 | assume(0); |
---|
618 | return -1; |
---|
619 | } |
---|
620 | } |
---|
621 | |
---|
622 | |
---|
623 | |
---|
624 | /*************************************************************** |
---|
625 | * |
---|
626 | * Macros for setting procs -- these are used for |
---|
627 | * generation and setting |
---|
628 | * |
---|
629 | ***************************************************************/ |
---|
630 | |
---|
631 | #define SetProc(what, field, length, ord) \ |
---|
632 | do \ |
---|
633 | { \ |
---|
634 | p_Field t_field = field; \ |
---|
635 | p_Ord t_ord = ord; \ |
---|
636 | p_Length t_length = length; \ |
---|
637 | FastProcFilter(what##_Proc, t_field, t_length, t_ord); \ |
---|
638 | DoSetProc(what, t_field, t_length, t_ord); \ |
---|
639 | } \ |
---|
640 | while (0) \ |
---|
641 | |
---|
642 | #define SetProcs(field, length, ord) \ |
---|
643 | do \ |
---|
644 | { \ |
---|
645 | SetProc(p_Delete, field, LengthGeneral, OrdGeneral); \ |
---|
646 | SetProc(p_Mult_nn, field, LengthGeneral, OrdGeneral); \ |
---|
647 | SetProc(pp_Mult_nn, field, length, OrdGeneral); \ |
---|
648 | SetProc(p_ShallowCopyDelete, FieldGeneral, length, OrdGeneral); \ |
---|
649 | SetProc(p_Copy, field, length, OrdGeneral); \ |
---|
650 | SetProc(pp_Mult_mm, field, length, OrdGeneral); \ |
---|
651 | SetProc(pp_Mult_mm_Noether, field, length, ord); \ |
---|
652 | SetProc(p_Mult_mm, field, length, OrdGeneral); \ |
---|
653 | SetProc(p_Add_q, field, length, ord); \ |
---|
654 | SetProc(p_Minus_mm_Mult_qq, field, length, ord); \ |
---|
655 | SetProc(p_kBucketSetLm, field, length, ord); \ |
---|
656 | SetProc(p_Neg, field, LengthGeneral, OrdGeneral); \ |
---|
657 | SetProc(pp_Mult_Coeff_mm_DivSelect, field, length, OrdGeneral); \ |
---|
658 | SetProc(pp_Mult_Coeff_mm_DivSelectMult, field, length, OrdGeneral); \ |
---|
659 | SetProc(p_Merge_q, FieldGeneral, length, ord); \ |
---|
660 | } \ |
---|
661 | while (0) |
---|
662 | |
---|
663 | #endif // P_PROCS_IMPL_H |
---|
664 | |
---|