Macros | Functions | Variables
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)   GenerateProc(#what, what##_Proc, 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

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

Definition at line 63 of file p_Procs_Generate.cc.

Function Documentation

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

Definition at line 83 of file p_Procs_Generate.cc.

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

Definition at line 68 of file p_Procs_Generate.cc.

69 {
70  return (generated_p_procs[proc])[index(proc, field, length, ord)] != 0;
71 }
char *** generated_p_procs
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:597
void GenerateProc ( const char *  s_what,
p_Proc  proc,
p_Field  field,
p_Length  length,
p_Ord  ord 
)

Definition at line 209 of file p_Procs_Generate.cc.

210 {
211  if (! AlreadyHaveProc(proc, field, length, ord))
212  AddProc(s_what, proc, field, length, ord);
213 }
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)
int IsKernelProc ( p_Proc  proc,
p_Field  field,
p_Length  length,
p_Ord  ord 
)

Definition at line 43 of file p_Procs_Generate.cc.

44 {
45  // general procs go into kernel
46  if (field == FieldGeneral && length == LengthGeneral && ord == OrdGeneral)
47  return 1;
48 
49  // plus procs with FieldZp
50  if ((field == FieldZp || field == FieldQ) &&
51  // which are not general in length or ord
52  !((length == LengthGeneral && p_ProcDependsOn_Length(proc)) ||
53  (ord == OrdGeneral && p_ProcDependsOn_Ord(proc))) &&
54  // and whose length is smaller than five
55  (!p_ProcDependsOn_Length(proc) || (length >= LengthFour)))
56  return 1;
57 
58  return 0;
59 }
static int p_ProcDependsOn_Ord(p_Proc proc)
Definition: p_Procs_Impl.h:306
static int p_ProcDependsOn_Length(p_Proc proc)
Definition: p_Procs_Impl.h:322
int main ( void  )

Definition at line 215 of file p_Procs_Generate.cc.

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

Variable Documentation

int DummyProcs = 0

Definition at line 79 of file p_Procs_Generate.cc.

int FieldGeneralProcs = 0

Definition at line 32 of file p_Procs_Generate.cc.

int FieldIndepProcs = 0

Definition at line 33 of file p_Procs_Generate.cc.

int FieldQProcs = 0

Definition at line 35 of file p_Procs_Generate.cc.

int FieldZpProcs = 0

Definition at line 34 of file p_Procs_Generate.cc.

char*** generated_p_procs

Definition at line 66 of file p_Procs_Generate.cc.

int KernelProcs = 0

Definition at line 39 of file p_Procs_Generate.cc.

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 73 of file p_Procs_Generate.cc.

const char* macros_length[]
Initial value:
=
{"p_MemCopy", "p_MemAdd", "p_MemSum", "p_MemDiff", NULL}
#define NULL
Definition: omList.c:10

Definition at line 75 of file p_Procs_Generate.cc.

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

Definition at line 78 of file p_Procs_Generate.cc.

int NumberOfHaveProcs = 0

Definition at line 81 of file p_Procs_Generate.cc.

int RingGeneralProcs = 0

Definition at line 37 of file p_Procs_Generate.cc.

int UnknownProcs = 0

Definition at line 40 of file p_Procs_Generate.cc.