My Project
Loading...
Searching...
No Matches
p_Procs_Generate.cc File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc/auxiliary.h"
#include "reporter/reporter.h"
#include "polys/templates/p_Procs_Dynamic.h"
#include "polys/templates/p_Procs_Impl.h"

Go to the source code of this file.

Macros

#define DoSetProc(what, field, length, ord)
 

Functions

int IsKernelProc (p_Proc proc, p_Field field, p_Length length, p_Ord ord)
 
int AlreadyHaveProc (p_Proc proc, p_Field field, p_Length length, p_Ord ord)
 
void AddProc (const char *s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)
 
void GenerateProc (const char *s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)
 
int main ()
 

Variables

int FieldGeneralProcs = 0
 
int FieldIndepProcs = 0
 
int FieldZpProcs = 0
 
int FieldQProcs = 0
 
int RingGeneralProcs = 0
 
int KernelProcs = 0
 
int UnknownProcs = 0
 
char *** generated_p_procs
 
const char * macros_field [] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", "n_InpMult", "n_InpAdd", NULL}
 
const char * macros_length []
 
const char * macros_length_ord [] = {"p_MemCmp", NULL}
 
int DummyProcs = 0
 
int NumberOfHaveProcs = 0
 

Macro Definition Documentation

◆ DoSetProc

#define DoSetProc ( what,
field,
length,
ord )
Value:
GenerateProc(#what, what##_Proc, field, length, ord)
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
void GenerateProc(const char *s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)

Definition at line 64 of file p_Procs_Generate.cc.

64#define DoSetProc(what, field, length, ord) \
65 GenerateProc(#what, what##_Proc, field, length, ord)

Function Documentation

◆ AddProc()

void AddProc ( const char * s_what,
p_Proc proc,
p_Field field,
p_Length length,
p_Ord ord )

Definition at line 84 of file p_Procs_Generate.cc.

85{
87 int i;
88 const char* s_length = p_LengthEnum_2_String(length);
89 const char* s_ord = p_OrdEnum_2_String(ord);
90 const char* s_field = p_FieldEnum_2_String(field);
91 char* s_full_proc_name = (char*) malloc(200);
92
93 sprintf(s_full_proc_name, "%s__%s_%s_%s", s_what, s_field, s_length, s_ord);
94
95 (generated_p_procs[proc])[index(proc, field, length, ord)] = s_full_proc_name;
96 // define all macros
97 printf("\n// definition of %s\n", s_full_proc_name);
98#ifndef p_Procs_Static
99 if (IsKernelProc(proc, field, length, ord))
100 {
101 KernelProcs++;
102 printf("#ifdef p_Procs_Kernel\n");
103 }
104 else
105 {
106 const char* module = p_ProcField_2_Module(proc, field);
107 if (strcmp(module, "FieldGeneral") == 0)
109 else if (strcmp(module, "FieldIndep") == 0)
111 else if (strcmp(module, "FieldZp") == 0)
112 FieldZpProcs++;
113 else if (strcmp(module, "FieldQ") == 0)
114 FieldQProcs++;
115 else
116 UnknownProcs++;
117 if (field==RingGeneral)
119
120 printf("#ifdef p_Procs_%s\n", module);
121 }
122#endif
123 if (strcmp(s_field, "RingGeneral") == 0)
124 {
125 printf("#define HAVE_RINGS\n");
126 printf("#define HAVE_ZERODIVISORS\n");
127 }
128 else
129 {
130 printf("#undef HAVE_RINGS\n");
131 printf("#undef HAVE_ZERODIVISORS\n");
132 }
133 i = 0;
134 while (macros_field[i] != NULL)
135 {
136 printf("#undef %s__T\n#define %s__T\t%s_%s\n",
137 macros_field[i], macros_field[i], macros_field[i], s_field);
138 i++;
139 }
140 i = 0;
141 while (macros_length[i] != NULL)
142 {
143 printf("#undef %s__T\n#define %s__T\t%s_%s\n",
145 i++;
146 }
147 i = 0;
148 while (macros_length_ord[i] != NULL)
149 {
150 printf("#undef %s__T\n#define %s__T\t%s_%s_%s\n",
152 i++;
153 }
154
155 // define DECLARE_LENGTH
156 printf("#undef DECLARE_LENGTH\n");
157 printf("#undef p_MemAddAdjust__T\n");
158 if (length != LengthGeneral)
159 {
160 printf("#define DECLARE_LENGTH(what) do {} while (0)\n");
161 printf("#define p_MemAddAdjust__T(p, r) do {} while (0)\n");
162 }
163 else
164 {
165 printf("#define DECLARE_LENGTH(what) what\n");
167 printf("#define p_MemAddAdjust__T(p, r) p_MemAdd_NegWeightAdjust(p, r)\n");
168 else
169 printf("#define p_MemAddAdjust__T(p, r) do {} while (0)\n");
170 }
171
172 // define DECLARE_ORDSGN
173 printf("#undef DECLARE_ORDSGN\n");
174 if (ord != OrdGeneral)
175 printf("#define DECLARE_ORDSGN(what) do {} while (0)\n");
176 else
177 printf("#define DECLARE_ORDSGN(what) what\n");
178
180 {
181 printf("#undef DECLARE_LENGTH_2\n");
182 printf("#undef p_MemCmp_Bitmask_2\n");
183 if (length != LengthGeneral)
184 {
185 printf("#define DECLARE_LENGTH_2(what) do {} while (0)\n");
186 if (length < LengthTwo)
187 printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_%s\n", p_LengthEnum_2_String((p_Length) ((int) length + 2)));
188 else
189 printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthZero\n");
190 }
191 else
192 {
193 printf("#define DECLARE_LENGTH_2(what) what \n");
194 printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthGeneral\n");
195 }
196 printf("#undef p_MemAddAdjust__T\n");
197 printf("#define p_MemAddAdjust__T(p, r) do {} while (0)\n");
198 }
199
200 printf("#undef %s__T\n#define %s__T %s\n", s_what, s_what, s_full_proc_name);
201 printf("#include \"polys/templates/%s__T.cc\"\n", s_what);
202 printf("#undef %s\n", s_what);
203 if (strcmp(s_field, "RingGeneral") == 0)
204 {
205 printf("#undef HAVE_RINGS\n");
206 printf("#undef HAVE_ZERODIVISORS\n");
207 }
208#ifndef p_Procs_Static
209 printf("#endif // p_Procs_[Kernel|Field*]\n");
210#endif
211}
int i
Definition cfEzgcd.cc:132
unsigned char * proc[NUM_PROC]
Definition checklibs.c:16
#define malloc
Definition omAllocFunc.c:12
#define NULL
Definition omList.c:12
int FieldQProcs
int FieldIndepProcs
int FieldGeneralProcs
int UnknownProcs
int KernelProcs
int NumberOfHaveProcs
int RingGeneralProcs
const char * macros_length_ord[]
int IsKernelProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)
const char * macros_length[]
const char * macros_field[]
char *** generated_p_procs
int FieldZpProcs
p_Length
@ LengthGeneral
@ LengthTwo
static int index(p_Length length, p_Ord ord)
static const char * p_ProcField_2_Module(p_Proc proc, p_Field field)
@ RingGeneral
@ pp_Mult_Coeff_mm_DivSelectMult_Proc
static const char * p_FieldEnum_2_String(p_Field field)
@ OrdGeneral
static const char * p_OrdEnum_2_String(p_Ord ord)
static const char * p_LengthEnum_2_String(p_Length length)

◆ AlreadyHaveProc()

int AlreadyHaveProc ( p_Proc proc,
p_Field field,
p_Length length,
p_Ord ord )
inline

Definition at line 69 of file p_Procs_Generate.cc.

70{
71 return (generated_p_procs[proc])[index(proc, field, length, ord)] != 0;
72}

◆ GenerateProc()

void GenerateProc ( const char * s_what,
p_Proc proc,
p_Field field,
p_Length length,
p_Ord ord )

Definition at line 213 of file p_Procs_Generate.cc.

214{
215 if (! AlreadyHaveProc(proc, field, length, ord))
216 AddProc(s_what, proc, field, length, ord);
217}
void AddProc(const char *s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)
int AlreadyHaveProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)

◆ IsKernelProc()

int IsKernelProc ( p_Proc proc,
p_Field field,
p_Length length,
p_Ord ord )

Definition at line 41 of file p_Procs_Generate.cc.

42{
43 // general procs go into kernel
44 if (field == FieldGeneral && length == LengthGeneral && ord == OrdGeneral)
45 return 1;
46
47 if (field == RingGeneral && length == LengthGeneral && ord == OrdGeneral)
48 return 1;
49
50 // plus procs with FieldZp
51 if ((field == FieldZp || field == FieldQ) &&
52 // which are not general in length or ord
54 (ord == OrdGeneral && p_ProcDependsOn_Ord(proc))) &&
55 // and whose length is smaller than five
57 return 1;
58
59 return 0;
60}
static int p_ProcDependsOn_Ord(p_Proc proc)
@ LengthFour
@ FieldQ
@ FieldZp
@ FieldGeneral
static int p_ProcDependsOn_Length(p_Proc proc)

◆ main()

int main ( )

Definition at line 219 of file p_Procs_Generate.cc.

220{
221 int field = FieldGeneral;
222 int length = LengthGeneral;
223 int ord = OrdGeneral;
224 int i;
225
226
227 printf("/* -*-c++-*- */\n");
228 printf("/***************************************************************\n");
229 printf(" * This file was generated automatically by p_ProcsGenerate.cc: DO NOT EDIT\n");
230 printf(" *\n");
231 printf(" * This file provides the needed implementation of p_Procs for\n");
232 printf(" * %s\n",
233#if defined(p_Procs_Static)
234 "p_Procs_Static"
235#else
236 "p_Procs_Dynamic"
237#endif
238 );
239 printf(" * See the end for a summary.\n");
240 printf(" *******************************************************************/\n");
241
242
243 generated_p_procs = (char***) malloc(p_Unknown_Proc*sizeof(char**));
244 for (i=0; i<p_Unknown_Proc; i++)
245 {
247 (char**) calloc(index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown), sizeof(char*));
248 }
249
250 // set default procs
251 for (field = 0; field < (int) FieldUnknown; field++)
252 {
253 for (length=0; length < (int) LengthUnknown; length++)
254 {
255 for (ord=0; ord < (int)OrdUnknown; ord++)
256 {
257 if (IsValidSpec((p_Field) field, (p_Length) length, (p_Ord) ord))
258 SetProcs((p_Field) field, (p_Length) length, (p_Ord) ord);
259 }
260 }
261 }
262
263// we only need lookup tables for p_Procs_Static
264#ifdef p_Procs_Static
265 int j;
266 printf("\n"
267 "/***************************************************************\n"
268 "Names of procs for RDEBUG */\n"
269 "#ifdef RDEBUG\n");
270
271 for (i=0; i<p_Unknown_Proc; i++)
272 {
273 printf("static const char* %s_names[] = {", p_ProcEnum_2_String((p_Proc)i));
275 {
276 char* s = (generated_p_procs[i])[j];
277 if (s != 0)
278 {
279 printf("\n\"%s\",", s);
280 }
281 else
282 printf("0,");
283
284 }
285 printf("\n};\n");
286 }
287 printf("\n #endif // RDEBUG\n\n"
288 "/***************************************************************/\n"
289 "/* Tables for lookup of procedures: */\n");
290
291 for (i=0; i<p_Unknown_Proc; i++)
292 {
293 printf("static const %s_Ptr %s_funcs[] = {", p_ProcEnum_2_String((p_Proc)i), p_ProcEnum_2_String((p_Proc)i));
295 {
296 char* s = (generated_p_procs[i])[j];
297 if (s != 0)
298 {
299 printf("\n%s,", s);
300 }
301 else
302 printf("0,");
303 }
304 printf("\n};\n");
305 }
306#endif
307
308 printf("\n/***************************************************************");
309 printf("* Summary:\n");
310 printf("* HAVE_FAST_P_PROCS = %d,\n",HAVE_FAST_P_PROCS);
311 printf("* HAVE_FAST_FIELD = %d,\n",HAVE_FAST_FIELD);
312 printf("* HAVE_FAST_LENGTH = %d,\n",HAVE_FAST_LENGTH);
313 printf("* HAVE_FAST_ORD = %d,\n",HAVE_FAST_ORD);
314 printf("* HAVE_FAST_ZERO_ORD = %d\n",HAVE_FAST_ZERO_ORD);
315 printf("*\n");
316 printf("* Generated PolyProcs= %d\n",NumberOfHaveProcs);
317
318#ifndef p_Procs_Static
319 printf("*\n");
320 printf("* KernelProcs = %d\n",KernelProcs);
321 printf("* FieldIndepProcs = %d\n",FieldIndepProcs);
322 printf("* FieldZpProcs = %d\n",FieldZpProcs);
323 printf("* FieldQProcs = %d\n",FieldQProcs);
324 printf("* FieldGeneralProcs = %d\n",FieldGeneralProcs-RingGeneralProcs);
325 printf("* RingGeneralProcs = %d (in FieldGeneral module)\n",RingGeneralProcs);
326 printf("* FieldUnknownProcs = %d\n",UnknownProcs);
327#endif
328
329 printf("*\n");
330 printf("*******************************************************************/\n");
331}
const CanonicalForm int s
Definition facAbsFact.cc:51
int j
Definition facHensel.cc:110
#define calloc
Definition omAllocFunc.c:13
#define HAVE_FAST_LENGTH
#define HAVE_FAST_P_PROCS
#define HAVE_FAST_ZERO_ORD
#define HAVE_FAST_FIELD
#define HAVE_FAST_ORD
@ LengthUnknown
p_Field
@ FieldUnknown
p_Proc
@ p_Unknown_Proc
p_Ord
@ OrdUnknown
#define SetProcs(field, length, ord)
static const char * p_ProcEnum_2_String(p_Proc proc)
static int IsValidSpec(p_Field field, p_Length length, p_Ord ord)
#define p_Procs_Static

Variable Documentation

◆ DummyProcs

int DummyProcs = 0

Definition at line 80 of file p_Procs_Generate.cc.

◆ FieldGeneralProcs

int FieldGeneralProcs = 0

Definition at line 32 of file p_Procs_Generate.cc.

◆ FieldIndepProcs

int FieldIndepProcs = 0

Definition at line 33 of file p_Procs_Generate.cc.

◆ FieldQProcs

int FieldQProcs = 0

Definition at line 35 of file p_Procs_Generate.cc.

◆ FieldZpProcs

int FieldZpProcs = 0

Definition at line 34 of file p_Procs_Generate.cc.

◆ generated_p_procs

char*** generated_p_procs

Definition at line 67 of file p_Procs_Generate.cc.

◆ KernelProcs

int KernelProcs = 0

Definition at line 37 of file p_Procs_Generate.cc.

◆ macros_field

const char* macros_field[] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", "n_InpMult", "n_InpAdd", NULL}

Definition at line 74 of file p_Procs_Generate.cc.

74{"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", "n_InpMult", "n_InpAdd", NULL};

◆ macros_length

const char* macros_length[]
Initial value:
=
{"p_MemCopy", "p_MemAdd", "p_MemSum", "p_MemDiff", NULL}

Definition at line 76 of file p_Procs_Generate.cc.

77{"p_MemCopy", "p_MemAdd", "p_MemSum", "p_MemDiff", NULL};

◆ macros_length_ord

const char* macros_length_ord[] = {"p_MemCmp", NULL}

Definition at line 79 of file p_Procs_Generate.cc.

79{"p_MemCmp", NULL};

◆ NumberOfHaveProcs

int NumberOfHaveProcs = 0

Definition at line 82 of file p_Procs_Generate.cc.

◆ RingGeneralProcs

int RingGeneralProcs = 0

Definition at line 36 of file p_Procs_Generate.cc.

◆ UnknownProcs

int UnknownProcs = 0

Definition at line 38 of file p_Procs_Generate.cc.