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