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

spielwiese
Last change on this file since b1d1ab3 was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[35aab3]1#ifndef MODULOP_H
2#define MODULOP_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/*
7* ABSTRACT: numbers modulo p (<=32003)
8*/
[2d805a]9#include <coeffs/coeffs.h>
[35aab3]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
18
19// enable large primes (32003 < p < 2^31-)
20#define NV_OPS
21#define NV_MAX_PRIME 32003
22
[95eb6d]23// extern int npGen; // obsolete
[35aab3]24
[1cce47]25BOOLEAN npInitChar(coeffs r, void* p);
[8c484e]26
[7d90aa]27BOOLEAN npGreaterZero (number k, const coeffs r);
28number  npMult        (number a, number b, const coeffs r);
[2f3764]29number  npInit        (long i, const coeffs r);
[7d90aa]30int     npInt         (number &n, const coeffs r);
31number  npAdd         (number a, number b,const coeffs r);
32number  npSub         (number a, number b,const coeffs r);
33void    npPower       (number a, int i, number * result,const coeffs r);
34BOOLEAN npIsZero      (number a,const coeffs r);
35BOOLEAN npIsOne       (number a,const coeffs r);
36BOOLEAN npIsMOne       (number a,const coeffs r);
37number  npDiv         (number a, number b,const coeffs r);
38number  npNeg         (number c,const coeffs r);
39number  npInvers      (number c,const coeffs r);
40BOOLEAN npGreater     (number a, number b,const coeffs r);
41BOOLEAN npEqual       (number a, number b,const coeffs r);
42void    npWrite       (number &a, const coeffs r);
[03f7b5]43void    npCoeffWrite  (const coeffs r, BOOLEAN details);
[7d90aa]44const char *  npRead  (const char *s, number *a,const coeffs r);
[35aab3]45#ifdef LDEBUG
[2b957a]46BOOLEAN npDBTest      (number a, const char *f, const int l, const coeffs r);
47#define npTest(A,r)     npDBTest(A,__FILE__,__LINE__, r)
[f1e33bb]48#else
[7d90aa]49#define npTest(A,r)     (0)
[35aab3]50#endif
51
52//int     npGetChar();
53
[7d90aa]54nMapFunc npSetMap(const coeffs src, const coeffs dst);
[2336d0]55number  npMapP(number from, const coeffs src, const coeffs r);
[35aab3]56/*-------specials for spolys, do NOT use otherwise--------------------------*/
57/* for npMultM, npSubM, npNegM, npEqualM : */
58#ifdef HAVE_DIV_MOD
[900802]59extern unsigned short *npInvTable;
[35aab3]60#else
61#ifndef HAVE_MULT_MOD
62extern long npPminus1M;
[900802]63extern unsigned short *npExpTable;
64extern unsigned short *npLogTable;
[35aab3]65#endif
66#endif
67
[e77676]68// inline number npMultM(number a, number b, int npPrimeM)
69// // return (a*b)%n
70// {
71//    double ab;
72//    long q, res;
73//
74//    ab = ((double) ((int)a)) * ((double) ((int)b));
75//    q  = (long) (ab/((double) npPrimeM));  // q could be off by (+/-) 1
76//    res = (long) (ab - ((double) q)*((double) npPrimeM));
77//    res += (res >> 31) & npPrimeM;
78//    res -= npPrimeM;
79//    res += (res >> 31) & npPrimeM;
80//    return (number)res;
81// }
[35aab3]82#ifdef HAVE_MULT_MOD
[7d90aa]83static inline number npMultM(number a, number b, const coeffs r)
[35aab3]84{
85  return (number) 
[e77676]86    ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r->ch));
[35aab3]87}
88#else
[7d90aa]89static inline number npMultM(number a, number b, const coeffs r)
[35aab3]90{
[7d90aa]91  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
92  return (number)(long)r->npExpTable[x<r->npPminus1M ? x : x- r->npPminus1M];
[35aab3]93}
94#endif
95
96#if 0
97inline number npAddAsm(number a, number b, int m)
98{
99  number r;
100    asm ("addl %2, %1; cmpl %3, %1; jb 0f; subl %3, %1; 0:"
101         : "=&r" (r)
102         : "%0" (a), "g" (b), "g" (m)
103         : "cc");
104  return r;
105}
106inline number npSubAsm(number a, number b, int m)
107{
108  number r;
109  asm ("subl %2, %1; jnc 0f; addl %3, %1; 0:"
110        : "=&r" (r)
111        : "%0" (a), "g" (b), "g" (m)
112        : "cc");
113  return r;
114}
115#endif
116#ifdef HAVE_GENERIC_ADD
[7d90aa]117static inline number npAddM(number a, number b, const coeffs r)
[35aab3]118{
[7d90aa]119  long R = (long)a + (long)b;
[e77676]120  return (number)(R >= r->ch ? R - r->ch : R);
[35aab3]121}
[7d90aa]122static inline number npSubM(number a, number b, const coeffs r)
[35aab3]123{
[6c56a8]124  return (number)((long)a<(long)b ?
[e77676]125                       r->ch-(long)b+(long)a : (long)a-(long)b);
[35aab3]126}
127#else
[7d90aa]128static inline number npAddM(number a, number b, const coeffs r)
[35aab3]129{
[6c56a8]130   long res = ((long)a + (long)b);
[e77676]131   res -= r->ch;
[6c56a8]132#if SIZEOF_LONG == 8
[e77676]133   res += (res >> 63) & r->ch;
[6c56a8]134#else
[e77676]135   res += (res >> 31) & r->ch;
[6c56a8]136#endif
[35aab3]137   return (number)res;
138}
[7d90aa]139static inline number npSubM(number a, number b, const coeffs r)
[35aab3]140{
[6c56a8]141   long res = ((long)a - (long)b);
142#if SIZEOF_LONG == 8
[e77676]143   res += (res >> 63) & r->ch;
[6c56a8]144#else
[e77676]145   res += (res >> 31) & r->ch;
[6c56a8]146#endif
[35aab3]147   return (number)res;
148}
149#endif
150
[b58d47]151static inline BOOLEAN npIsZeroM (number  a, const coeffs)
[35aab3]152{
153  return 0 == (long)a;
154}
155
[e77676]156// inline number npMultM(number a, number b, int npPrimeM)
157// {
158//   return (number)(((long)a*(long)b) % npPrimeM);
159// }
[35aab3]160
161
[e77676]162#define npNegM(A,r)      (number)(r->ch-(long)(A))
163#define npEqualM(A,B,r)  ((A)==(B))
[35aab3]164
165
166#endif
Note: See TracBrowser for help on using the repository browser.