source: git/libpolys/polys/templates/p_Procs_Generate.cc @ a3f0fea

spielwiese
Last change on this file since a3f0fea was a3f0fea, checked in by Reimer Behrends <behrends@…>, 5 years ago
Modify variable declarions for pSingular.
  • Property mode set to 100644
File size: 9.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    p_ProcsGenerate.cc
6 *  Purpose: generate p_Procs*.inc at compile
7 *  Note:    this file is included by p_Procs.cc
8 *  Author:  obachman (Olaf Bachmann)
9 *  Created: 8/00
10 *******************************************************************/
11
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
17
18#include "misc/auxiliary.h"
19
20#include "reporter/reporter.h"
21
22
23#ifdef p_Procs_Static
24#include "polys/templates/p_Procs_Static.h"
25#else
26#include "polys/templates/p_Procs_Dynamic.h"
27#endif
28
29#include "polys/templates/p_Procs_Impl.h"
30
31#ifndef p_Procs_Static
32VAR int FieldGeneralProcs = 0,
33  FieldIndepProcs = 0,
34  FieldZpProcs = 0,
35  FieldQProcs = 0,
36  RingGeneralProcs = 0,
37  KernelProcs = 0,
38  UnknownProcs = 0;
39
40// returns 1, if proc should go into kernel, 0 otherwise
41int IsKernelProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)
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}
61
62#endif
63
64#define DoSetProc(what, field, length, ord) \
65      GenerateProc(#what, what##_Proc, field, length, ord)
66
67VAR char*** generated_p_procs;
68
69inline int AlreadyHaveProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)
70{
71  return (generated_p_procs[proc])[index(proc, field, length, ord)] != 0;
72}
73
74const char* macros_field[] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", "n_InpMult", "n_InpAdd", NULL};
75
76const char* macros_length[] =
77{"p_MemCopy", "p_MemAdd", "p_MemSum", "p_MemDiff", NULL};
78
79const char* macros_length_ord[] = {"p_MemCmp", NULL};
80VAR int DummyProcs = 0;
81
82VAR int NumberOfHaveProcs = 0;
83
84void AddProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)
85{
86  NumberOfHaveProcs++;
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)
108      FieldGeneralProcs++;
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)
118      RingGeneralProcs++;
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");
170    if (proc != pp_Mult_Coeff_mm_DivSelectMult_Proc)
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
183  if (proc == pp_Mult_Coeff_mm_DivSelectMult_Proc)
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}
220
221void GenerateProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)
222{
223  if (! AlreadyHaveProc(proc, field, length, ord))
224    AddProc(s_what, proc, field, length, ord);
225}
226
227int main()
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  {
254    generated_p_procs[i] =
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}
340
341
Note: See TracBrowser for help on using the repository browser.