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