source: git/libpolys/coeffs/modulop.h @ 2206753

spielwiese
Last change on this file since 2206753 was 2206753, checked in by Oleksandr Motsak <motsak@…>, 9 years ago
Hiding all the implementation details (or adding the counting) mostly by moving internal declarations from private headers into corresponding source files rm: Remove internal includes (hiding privates) + cleanup chg: cleanup internal headers fix the usage of internal implementation functions of coeffs from outside of libpolys/coeffs (or libpolys/polys/ext_fiels) fix header includes for coeffs/AE*.{h,cc} add: FIXME&TODO mark reused privates also starting to fix bigint handling
  • Property mode set to 100644
File size: 3.3 KB
Line 
1#ifndef MODULOP_H
2#define MODULOP_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/*
7* ABSTRACT: numbers modulo p (<=32003)
8*/
9#include <misc/auxiliary.h>
10
11// defines are in struct.h
12// define if a*b is with mod instead of tables
13//#define HAVE_MULT_MOD
14// define if a/b is with mod instead of tables
15//#define HAVE_DIV_MOD
16// define if an if should be used
17//#define HAVE_GENERIC_ADD
18struct n_Procs_s; typedef struct  n_Procs_s  *coeffs;
19struct snumber; typedef struct snumber *   number;
20
21BOOLEAN npInitChar(coeffs r, void* p);
22
23// inline number npMultM(number a, number b, int npPrimeM)
24// // return (a*b)%n
25// {
26//    double ab;
27//    long q, res;
28//
29//    ab = ((double) ((int)a)) * ((double) ((int)b));
30//    q  = (long) (ab/((double) npPrimeM));  // q could be off by (+/-) 1
31//    res = (long) (ab - ((double) q)*((double) npPrimeM));
32//    res += (res >> 31) & npPrimeM;
33//    res -= npPrimeM;
34//    res += (res >> 31) & npPrimeM;
35//    return (number)res;
36// }
37#ifdef HAVE_MULT_MOD
38static inline number npMultM(number a, number b, const coeffs r)
39{
40  return (number)
41    ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r->ch));
42}
43#else
44static inline number npMultM(number a, number b, const coeffs r)
45{
46  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
47  return (number)(long)r->npExpTable[x<r->npPminus1M ? x : x- r->npPminus1M];
48}
49#endif
50
51#if 0
52inline number npAddAsm(number a, number b, int m)
53{
54  number r;
55    asm ("addl %2, %1; cmpl %3, %1; jb 0f; subl %3, %1; 0:"
56         : "=&r" (r)
57         : "%0" (a), "g" (b), "g" (m)
58         : "cc");
59  return r;
60}
61inline number npSubAsm(number a, number b, int m)
62{
63  number r;
64  asm ("subl %2, %1; jnc 0f; addl %3, %1; 0:"
65        : "=&r" (r)
66        : "%0" (a), "g" (b), "g" (m)
67        : "cc");
68  return r;
69}
70#endif
71#ifdef HAVE_GENERIC_ADD
72static inline number npAddM(number a, number b, const coeffs r)
73{
74  unsigned long R = (unsigned long)a + (unsigned long)b;
75  return (number)(R >= r->ch ? R - r->ch : R);
76}
77static inline number npSubM(number a, number b, const coeffs r)
78{
79  return (number)((long)a<(long)b ?
80                       r->ch-(long)b+(long)a : (long)a-(long)b);
81}
82#else
83static inline number npAddM(number a, number b, const coeffs r)
84{
85   unsigned long res = (long)((unsigned long)a + (unsigned long)b);
86   res -= r->ch;
87#if SIZEOF_LONG == 8
88   res += ((long)res >> 63) & r->ch;
89#else
90   res += ((long)res >> 31) & r->ch;
91#endif
92   return (number)res;
93}
94static inline number npSubM(number a, number b, const coeffs r)
95{
96   long res = ((long)a - (long)b);
97#if SIZEOF_LONG == 8
98   res += (res >> 63) & r->ch;
99#else
100   res += (res >> 31) & r->ch;
101#endif
102   return (number)res;
103}
104#endif
105
106static inline number npNegM(number a, const coeffs r)
107{
108  return (number)((long)(r->ch)-(long)(a));
109}
110
111static inline BOOLEAN npIsZeroM (number  a, const coeffs)
112{
113  return 0 == (long)a;
114}
115
116// inline number npMultM(number a, number b, int npPrimeM)
117// {
118//   return (number)(((long)a*(long)b) % npPrimeM);
119// }
120
121// The folloing is reused inside gnumpc.cc, gnumpfl.cc and longrat.cc
122int     npInt         (number &n, const coeffs r);
123
124// The following is currently used in OPAE.cc, OPAEQ.cc and OPAEp.cc for setting their SetMap...
125nMapFunc npSetMap(const coeffs src, const coeffs dst); // FIXME! BUG?
126
127#define npEqualM(A,B,r)  ((A)==(B))
128
129
130#endif
Note: See TracBrowser for help on using the repository browser.