source: git/kernel/p_Procs_Dynamic.cc @ bc669c

fieker-DuValspielwiese
Last change on this file since bc669c was 341696, checked in by Hans Schönemann <hannes@…>, 15 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    p_Procs_Dynamic.cc
6 *  Purpose: source for dynamically loaded version of p_Procs
7 *  Author:  obachman (Olaf Bachmann)
8 *  Created: 12/00
9 *  Version: $Id$
10 *******************************************************************/
11#include "mod2.h"
12#include "structs.h"
13#include "p_polys.h"
14#include "ring.h"
15#include "p_Procs.h"
16#include "p_Numbers.h"
17#include "p_MemCmp.h"
18#include "p_MemAdd.h"
19#include "p_MemCopy.h"
20#include "kbuckets.h"
21#include "dError.h"
22
23#ifdef HAVE_DL
24BOOLEAN p_procs_dynamic = TRUE;
25
26#define WARN_MSG "Singular will work properly, but much slower."
27
28// need external linkage, so that dynl_sym works
29#undef LINKAGE
30#define LINKAGE extern "C"
31#define p_Procs_Kernel
32#include "p_Procs_Dynamic.inc"
33
34#include "p_Procs_Dynamic.h"
35// include general p_Proc stuff
36#include "p_Procs_Impl.h"
37#include "mod_raw.h"
38
39// define to bound for length of p_Proc name
40#define MAX_PROCNAME_LEN 200
41
42static void* p_procs_handle_FieldIndep = NULL;
43static void* p_procs_handle_FieldZp = NULL;
44static void* p_procs_handle_FieldQ = NULL;
45static void* p_procs_handle_FieldGeneral = NULL;
46
47static void* p_ProcInitHandle(void** handle, const char* module)
48{
49  if (*handle == NULL)
50  {
51    char name[25];
52    sprintf(name, "p_Procs_%s", module);
53    *handle = dynl_open_binary_warn(name, WARN_MSG);
54  }
55  return *handle;
56}
57
58static inline void* p_ProcGetHandle(p_Proc proc, p_Field field)
59{
60  const char* module =  p_ProcField_2_Module(proc, field);
61
62  if (strcmp(module, "FieldIndep") == 0)
63    return p_ProcInitHandle(&p_procs_handle_FieldIndep, module);
64  else if (strcmp(module, "FieldZp") == 0)
65    return p_ProcInitHandle(&p_procs_handle_FieldZp, module);
66  else if (strcmp(module, "FieldQ") == 0)
67    return p_ProcInitHandle(&p_procs_handle_FieldQ, module);
68  else if (strcmp(module, "FieldGeneral") == 0)
69    return p_ProcInitHandle(&p_procs_handle_FieldGeneral, module);
70  else
71  {
72    assume(0);
73    return NULL;
74  }
75}
76
77
78#define InitSetProcs(f, l, o) ((void)0)
79
80static void* GetGeneralProc(p_Proc proc)
81{
82  switch(proc)
83  {
84      case p_Copy_Proc:
85        return (void *)p_Copy__FieldGeneral_LengthGeneral_OrdGeneral;
86      case p_Delete_Proc:
87        return (void *)p_Delete__FieldGeneral_LengthGeneral_OrdGeneral;
88      case p_ShallowCopyDelete_Proc:
89        return (void *)p_ShallowCopyDelete__FieldGeneral_LengthGeneral_OrdGeneral;
90      case p_Mult_nn_Proc:
91        return (void *)p_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral;
92      case pp_Mult_nn_Proc:
93        return (void *)pp_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral;
94      case pp_Mult_mm_Proc:
95        return (void *)pp_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral;
96      case pp_Mult_mm_Noether_Proc:
97        return (void *)pp_Mult_mm_Noether__FieldGeneral_LengthGeneral_OrdGeneral;
98      case p_Mult_mm_Proc:
99        return (void *)p_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral;
100      case p_Add_q_Proc:
101        return (void *)p_Add_q__FieldGeneral_LengthGeneral_OrdGeneral;
102      case p_Minus_mm_Mult_qq_Proc:
103        return (void *)p_Minus_mm_Mult_qq__FieldGeneral_LengthGeneral_OrdGeneral;
104      case p_Neg_Proc:
105        return (void *)p_Neg__FieldGeneral_LengthGeneral_OrdGeneral;
106      case pp_Mult_Coeff_mm_DivSelect_Proc:
107        return (void *)pp_Mult_Coeff_mm_DivSelect__FieldGeneral_LengthGeneral_OrdGeneral;
108      case pp_Mult_Coeff_mm_DivSelectMult_Proc:
109        return (void *)pp_Mult_Coeff_mm_DivSelectMult__FieldGeneral_LengthGeneral_OrdGeneral;
110      case p_Merge_q_Proc:
111        return (void *)p_Merge_q__FieldGeneral_LengthGeneral_OrdGeneral;
112      case p_kBucketSetLm_Proc:
113        return (void *)p_kBucketSetLm__FieldGeneral_LengthGeneral_OrdGeneral;
114      case p_Unknown_Proc:
115        break;
116  }
117  dReportBug("p_Unknown_Proc");
118  return NULL;
119}
120
121#ifdef RDEBUG
122#include "omalloc.h"
123
124static const char* GetGeneralProcName(p_Proc proc)
125{
126  switch(proc)
127  {
128      case p_Copy_Proc:
129        return "p_Copy__FieldGeneral_LengthGeneral_OrdGeneral";
130      case p_Delete_Proc:
131        return "p_Delete__FieldGeneral_LengthGeneral_OrdGeneral";
132      case p_ShallowCopyDelete_Proc:
133        return "p_ShallowCopyDelete__FieldGeneral_LengthGeneral_OrdGeneral";
134      case p_Mult_nn_Proc:
135        return "p_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral";
136      case pp_Mult_nn_Proc:
137        return "pp_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral";
138      case pp_Mult_mm_Proc:
139        return "pp_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral";
140      case pp_Mult_mm_Noether_Proc:
141        return "pp_Mult_mm_Noether__FieldGeneral_LengthGeneral_OrdGeneral";
142      case p_Mult_mm_Proc:
143        return "p_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral";
144      case p_Add_q_Proc:
145        return "p_Add_q__FieldGeneral_LengthGeneral_OrdGeneral";
146      case p_Minus_mm_Mult_qq_Proc:
147        return "p_Minus_mm_Mult_qq__FieldGeneral_LengthGeneral_OrdGeneral";
148      case p_Neg_Proc:
149        return "p_Neg__FieldGeneral_LengthGeneral_OrdGeneral";
150      case pp_Mult_Coeff_mm_DivSelect_Proc:
151        return "pp_Mult_Coeff_mm_DivSelect__FieldGeneral_LengthGeneral_OrdGeneral";
152      case pp_Mult_Coeff_mm_DivSelectMult_Proc:
153        return "pp_Mult_Coeff_mm_DivSelectMult__FieldGeneral_LengthGeneral_OrdGeneral";
154      case p_Merge_q_Proc:
155        return "p_Merge_q__FieldGeneral_LengthGeneral_OrdGeneral";
156      case p_kBucketSetLm_Proc:
157        return "p_kBucketSetLm__FieldGeneral_LengthGeneral_OrdGeneral";
158      case p_Unknown_Proc:
159        break;
160  }
161  return "p_Unknown_Proc";
162}
163#endif
164
165
166static void* GetDynamicProc(const char* proc_s, p_Proc proc,
167                            p_Field field, p_Length length, p_Ord ord
168#ifdef RDEBUG
169                     , int get_name = 0
170#endif
171                     )
172{
173  void* proc_ptr = NULL;
174  char proc_name[MAX_PROCNAME_LEN];
175  sprintf(proc_name, "%s__%s_%s_%s", proc_s,
176          p_FieldEnum_2_String(field),
177          p_LengthEnum_2_String(length),
178          p_OrdEnum_2_String(ord));
179  // printf("set %s\n",proc_name);
180  // first, try to get the proc from the kernel
181  proc_ptr = dynl_sym(DYNL_KERNEL_HANDLE, proc_name);
182  if (proc_ptr == NULL)
183  {
184    proc_ptr = dynl_sym_warn(p_ProcGetHandle(proc, field), proc_name, WARN_MSG);
185    // last but not least use general proc
186    if (proc_ptr == NULL)
187    {
188      proc_ptr = GetGeneralProc(proc);
189#ifdef RDEBUG
190      sprintf(proc_name,"%s", GetGeneralProcName(proc));
191#endif
192    }
193  }
194#ifdef RDEBUG
195  if (get_name)
196  {
197    char* name = omStrDup(proc_name);
198    omMarkAsStaticAddr(name);
199    return (void*) name;
200  }
201#endif
202  return  proc_ptr;
203}
204
205
206#define DoReallySetProc(what, field, length, ord)           \
207  _p_procs->what = (what##_Proc_Ptr)                        \
208     GetDynamicProc(#what, what##_Proc, field, length, ord)
209
210#ifdef RDEBUG
211#define DoSetProc(what, field, length, ord)                         \
212do                                                                  \
213{                                                                   \
214  if (set_names)                                                    \
215    _p_procs->what = (what##_Proc_Ptr)                              \
216       GetDynamicProc(#what,  what##_Proc, field, length, ord, 1);  \
217  else                                                              \
218    DoReallySetProc(what, field, length, ord);                      \
219}                                                                   \
220while(0)
221#else
222#define DoSetProc DoReallySetProc
223#endif
224
225
226#include "p_Procs_Set.h"
227
228#endif
Note: See TracBrowser for help on using the repository browser.