My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
libpolys
polys
p_Procs_Generate.cc
Go to the documentation of this file.
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
32
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
41
int
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
67
char
***
generated_p_procs
;
68
69
inline
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
74
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
};
75
76
const
char
*
macros_length
[] =
77
{
"p_MemCopy"
,
"p_MemAdd"
,
"p_MemSum"
,
"p_MemDiff"
,
NULL
};
78
79
const
char
*
macros_length_ord
[] = {
"p_MemCmp"
,
NULL
};
80
int
DummyProcs
= 0;
81
82
int
NumberOfHaveProcs
= 0;
83
84
void
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
snprintf(s_full_proc_name,200,
"%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
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"
,
144
macros_length
[
i
],
macros_length
[
i
],
macros_length
[
i
], s_length);
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"
,
151
macros_length_ord
[
i
],
macros_length_ord
[
i
],
macros_length_ord
[
i
], s_length, s_ord);
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"
);
166
if
(
proc
!=
pp_Mult_Coeff_mm_DivSelectMult_Proc
)
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
179
if
(
proc
==
pp_Mult_Coeff_mm_DivSelectMult_Proc
)
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
}
212
213
void
GenerateProc
(
const
char
* s_what,
p_Proc
proc
,
p_Field
field,
p_Length
length
,
p_Ord
ord)
214
{
215
if
(!
AlreadyHaveProc
(
proc
, field,
length
, ord))
216
AddProc
(s_what,
proc
, field,
length
, ord);
217
}
218
219
int
main
()
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
{
246
generated_p_procs
[
i
] =
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
));
274
for
(
j
=0;
j
<
index
((
p_Proc
)
i
,
FieldUnknown
,
LengthUnknown
,
OrdUnknown
);
j
++)
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
));
294
for
(
j
=0;
j
<
index
((
p_Proc
)
i
,
FieldUnknown
,
LengthUnknown
,
OrdUnknown
);
j
++)
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
}
332
333
auxiliary.h
All the auxiliary stuff.
i
int i
Definition
cfEzgcd.cc:132
proc
unsigned char * proc[NUM_PROC]
Definition
checklibs.c:16
s
const CanonicalForm int s
Definition
facAbsFact.cc:51
j
int j
Definition
facHensel.cc:110
length
static BOOLEAN length(leftv result, leftv arg)
Definition
interval.cc:257
calloc
#define calloc
Definition
omAllocFunc.c:13
malloc
#define malloc
Definition
omAllocFunc.c:12
NULL
#define NULL
Definition
omList.c:12
p_Procs_Dynamic.h
HAVE_FAST_LENGTH
#define HAVE_FAST_LENGTH
Definition
p_Procs_Dynamic.h:25
HAVE_FAST_P_PROCS
#define HAVE_FAST_P_PROCS
Definition
p_Procs_Dynamic.h:16
HAVE_FAST_ZERO_ORD
#define HAVE_FAST_ZERO_ORD
Definition
p_Procs_Dynamic.h:19
HAVE_FAST_FIELD
#define HAVE_FAST_FIELD
Definition
p_Procs_Dynamic.h:17
HAVE_FAST_ORD
#define HAVE_FAST_ORD
Definition
p_Procs_Dynamic.h:18
FieldQProcs
int FieldQProcs
Definition
p_Procs_Generate.cc:35
FieldIndepProcs
int FieldIndepProcs
Definition
p_Procs_Generate.cc:33
FieldGeneralProcs
int FieldGeneralProcs
Definition
p_Procs_Generate.cc:32
GenerateProc
void GenerateProc(const char *s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)
Definition
p_Procs_Generate.cc:213
UnknownProcs
int UnknownProcs
Definition
p_Procs_Generate.cc:38
KernelProcs
int KernelProcs
Definition
p_Procs_Generate.cc:37
NumberOfHaveProcs
int NumberOfHaveProcs
Definition
p_Procs_Generate.cc:82
RingGeneralProcs
int RingGeneralProcs
Definition
p_Procs_Generate.cc:36
macros_length_ord
const char * macros_length_ord[]
Definition
p_Procs_Generate.cc:79
AddProc
void AddProc(const char *s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord)
Definition
p_Procs_Generate.cc:84
IsKernelProc
int IsKernelProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)
Definition
p_Procs_Generate.cc:41
macros_length
const char * macros_length[]
Definition
p_Procs_Generate.cc:76
macros_field
const char * macros_field[]
Definition
p_Procs_Generate.cc:74
DummyProcs
int DummyProcs
Definition
p_Procs_Generate.cc:80
generated_p_procs
char *** generated_p_procs
Definition
p_Procs_Generate.cc:67
FieldZpProcs
int FieldZpProcs
Definition
p_Procs_Generate.cc:34
main
int main()
Definition
p_Procs_Generate.cc:219
AlreadyHaveProc
int AlreadyHaveProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord)
Definition
p_Procs_Generate.cc:69
p_Procs_Impl.h
p_ProcDependsOn_Ord
static int p_ProcDependsOn_Ord(p_Proc proc)
Definition
p_Procs_Impl.h:299
p_Length
p_Length
Definition
p_Procs_Impl.h:123
LengthUnknown
@ LengthUnknown
Definition
p_Procs_Impl.h:133
LengthFour
@ LengthFour
Definition
p_Procs_Impl.h:129
LengthGeneral
@ LengthGeneral
Definition
p_Procs_Impl.h:124
LengthTwo
@ LengthTwo
Definition
p_Procs_Impl.h:131
index
static int index(p_Length length, p_Ord ord)
Definition
p_Procs_Impl.h:592
p_ProcField_2_Module
static const char * p_ProcField_2_Module(p_Proc proc, p_Field field)
Definition
p_Procs_Impl.h:331
p_Field
p_Field
Definition
p_Procs_Impl.h:107
FieldUnknown
@ FieldUnknown
Definition
p_Procs_Impl.h:120
FieldQ
@ FieldQ
Definition
p_Procs_Impl.h:110
FieldZp
@ FieldZp
Definition
p_Procs_Impl.h:109
RingGeneral
@ RingGeneral
Definition
p_Procs_Impl.h:119
FieldGeneral
@ FieldGeneral
Definition
p_Procs_Impl.h:108
p_ProcDependsOn_Length
static int p_ProcDependsOn_Length(p_Proc proc)
Definition
p_Procs_Impl.h:315
p_Proc
p_Proc
Definition
p_Procs_Impl.h:179
pp_Mult_Coeff_mm_DivSelectMult_Proc
@ pp_Mult_Coeff_mm_DivSelectMult_Proc
Definition
p_Procs_Impl.h:192
p_Unknown_Proc
@ p_Unknown_Proc
Definition
p_Procs_Impl.h:195
p_FieldEnum_2_String
static const char * p_FieldEnum_2_String(p_Field field)
Definition
p_Procs_Impl.h:198
p_Ord
p_Ord
Definition
p_Procs_Impl.h:136
OrdUnknown
@ OrdUnknown
Definition
p_Procs_Impl.h:175
OrdGeneral
@ OrdGeneral
Definition
p_Procs_Impl.h:137
SetProcs
#define SetProcs(field, length, ord)
Definition
p_Procs_Impl.h:662
p_OrdEnum_2_String
static const char * p_OrdEnum_2_String(p_Ord ord)
Definition
p_Procs_Impl.h:237
p_LengthEnum_2_String
static const char * p_LengthEnum_2_String(p_Length length)
Definition
p_Procs_Impl.h:219
p_ProcEnum_2_String
static const char * p_ProcEnum_2_String(p_Proc proc)
Definition
p_Procs_Impl.h:267
IsValidSpec
static int IsValidSpec(p_Field field, p_Length length, p_Ord ord)
Definition
p_Procs_Impl.h:565
p_Procs_Static
#define p_Procs_Static
Definition
p_Procs_Static.cc:29
p_Procs_Static.h
reporter.h
Generated on
for My Project by
doxygen 1.17.0
for
Singular