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 64 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 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)
110  FieldIndepProcs++;
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 #ifdef HAVE_RINGS
126  printf("#define HAVE_RINGS\n");
127  printf("#define HAVE_ZERODIVISORS\n");
128 #else
129  printf("#if 0\n");
130 #endif
131  }
132  else
133  {
134  printf("#undef HAVE_RINGS\n");
135  printf("#undef HAVE_ZERODIVISORS\n");
136  }
137  i = 0;
138  while (macros_field[i] != NULL)
139  {
140  printf("#undef %s__T\n#define %s__T\t%s_%s\n",
141  macros_field[i], macros_field[i], macros_field[i], s_field);
142  i++;
143  }
144  i = 0;
145  while (macros_length[i] != NULL)
146  {
147  printf("#undef %s__T\n#define %s__T\t%s_%s\n",
148  macros_length[i], macros_length[i], macros_length[i], s_length);
149  i++;
150  }
151  i = 0;
152  while (macros_length_ord[i] != NULL)
153  {
154  printf("#undef %s__T\n#define %s__T\t%s_%s_%s\n",
155  macros_length_ord[i], macros_length_ord[i], macros_length_ord[i], s_length, s_ord);
156  i++;
157  }
158 
159  // define DECLARE_LENGTH
160  printf("#undef DECLARE_LENGTH\n");
161  printf("#undef p_MemAddAdjust__T\n");
162  if (length != LengthGeneral)
163  {
164  printf("#define DECLARE_LENGTH(what) do {} while (0)\n");
165  printf("#define p_MemAddAdjust__T(p, r) do {} while (0)\n");
166  }
167  else
168  {
169  printf("#define DECLARE_LENGTH(what) what\n");
171  printf("#define p_MemAddAdjust__T(p, r) p_MemAdd_NegWeightAdjust(p, r)\n");
172  else
173  printf("#define p_MemAddAdjust__T(p, r) do {} while (0)\n");
174  }
175 
176  // define DECLARE_ORDSGN
177  printf("#undef DECLARE_ORDSGN\n");
178  if (ord != OrdGeneral)
179  printf("#define DECLARE_ORDSGN(what) do {} while (0)\n");
180  else
181  printf("#define DECLARE_ORDSGN(what) what\n");
182 
184  {
185  printf("#undef DECLARE_LENGTH_2\n");
186  printf("#undef p_MemCmp_Bitmask_2\n");
187  if (length != LengthGeneral)
188  {
189  printf("#define DECLARE_LENGTH_2(what) do {} while (0)\n");
190  if (length < LengthTwo)
191  printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_%s\n", p_LengthEnum_2_String((p_Length) ((int) length + 2)));
192  else
193  printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthZero\n");
194  }
195  else
196  {
197  printf("#define DECLARE_LENGTH_2(what) what \n");
198  printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthGeneral\n");
199  }
200  printf("#undef p_MemAddAdjust__T\n");
201  printf("#define p_MemAddAdjust__T(p, r) do {} while (0)\n");
202  }
203 
204  printf("#undef %s__T\n#define %s__T %s\n", s_what, s_what, s_full_proc_name);
205  printf("#include \"polys/templates/%s__T.cc\"\n", s_what);
206  printf("#undef %s\n", s_what);
207  if (strcmp(s_field, "RingGeneral") == 0)
208  {
209 #ifdef HAVE_RINGS
210  printf("#undef HAVE_RINGS\n");
211  printf("#undef HAVE_ZERODIVISORS\n");
212 #else
213  printf("#endif\n");
214 #endif
215  }
216 #ifndef p_Procs_Static
217  printf("#endif // p_Procs_[Kernel|Field*]\n");
218 #endif
219 }
int IsKernelProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:14
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:237
p_Length
Definition: p_Procs_Impl.h:122
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:592
static const char * p_LengthEnum_2_String(p_Length length)
Definition: p_Procs_Impl.h:219
#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:331
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:198
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 }
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:14
char *** generated_p_procs
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
void GenerateProc ( const char *  s_what,
p_Proc  proc,
p_Field  field,
p_Length  length,
p_Ord  ord 
)

Definition at line 221 of file p_Procs_Generate.cc.

222 {
223  if (! AlreadyHaveProc(proc, field, length, ord))
224  AddProc(s_what, proc, field, length, ord);
225 }
int AlreadyHaveProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:14
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 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
53  !((length == LengthGeneral && p_ProcDependsOn_Length(proc)) ||
54  (ord == OrdGeneral && p_ProcDependsOn_Ord(proc))) &&
55  // and whose length is smaller than five
56  (!p_ProcDependsOn_Length(proc) || (length >= LengthFour)))
57  return 1;
58 
59  return 0;
60 }
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:14
static int p_ProcDependsOn_Ord(p_Proc proc)
Definition: p_Procs_Impl.h:299
static int p_ProcDependsOn_Length(p_Proc proc)
Definition: p_Procs_Impl.h:315
int main ( void  )

Definition at line 227 of file p_Procs_Generate.cc.

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

Variable Documentation

int DummyProcs = 0

Definition at line 80 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 67 of file p_Procs_Generate.cc.

int KernelProcs = 0

Definition at line 37 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 74 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 76 of file p_Procs_Generate.cc.

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

Definition at line 79 of file p_Procs_Generate.cc.

int NumberOfHaveProcs = 0

Definition at line 82 of file p_Procs_Generate.cc.

int RingGeneralProcs = 0

Definition at line 36 of file p_Procs_Generate.cc.

int UnknownProcs = 0

Definition at line 38 of file p_Procs_Generate.cc.