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

fieker-DuValspielwiese
Last change on this file since f0797c was b58d47, checked in by Mohamed Barakat <mohamed.barakat@…>, 13 years ago
start eliminating `unused parameter' warnings
  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[35aab3]1#ifndef MODULOP_H
2#define MODULOP_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
[341696]6/* $Id$ */
[35aab3]7/*
8* ABSTRACT: numbers modulo p (<=32003)
9*/
[2d805a]10#include <coeffs/coeffs.h>
[35aab3]11
12// defines are in struct.h
13// define if a*b is with mod instead of tables
14//#define HAVE_MULT_MOD
15// define if a/b is with mod instead of tables
16//#define HAVE_DIV_MOD
17// define if an if should be used
18//#define HAVE_GENERIC_ADD
19
20// enable large primes (32003 < p < 2^31-)
21#define NV_OPS
22#define NV_MAX_PRIME 32003
23
24extern int npGen;
25
[1cce47]26BOOLEAN npInitChar(coeffs r, void* p);
[8c484e]27
[7d90aa]28BOOLEAN npGreaterZero (number k, const coeffs r);
29number  npMult        (number a, number b, const coeffs r);
30number  npInit        (int i, const coeffs r);
31int     npInt         (number &n, const coeffs r);
32number  npAdd         (number a, number b,const coeffs r);
33number  npSub         (number a, number b,const coeffs r);
34void    npPower       (number a, int i, number * result,const coeffs r);
35BOOLEAN npIsZero      (number a,const coeffs r);
36BOOLEAN npIsOne       (number a,const coeffs r);
37BOOLEAN npIsMOne       (number a,const coeffs r);
38number  npDiv         (number a, number b,const coeffs r);
39number  npNeg         (number c,const coeffs r);
40number  npInvers      (number c,const coeffs r);
41BOOLEAN npGreater     (number a, number b,const coeffs r);
42BOOLEAN npEqual       (number a, number b,const coeffs r);
43void    npWrite       (number &a, const coeffs r);
[c7e3d7]44void    npCoeffWrite  (const coeffs r);
[7d90aa]45const char *  npRead  (const char *s, number *a,const coeffs r);
[35aab3]46#ifdef LDEBUG
[2b957a]47BOOLEAN npDBTest      (number a, const char *f, const int l, const coeffs r);
48#define npTest(A,r)     npDBTest(A,__FILE__,__LINE__, r)
[f1e33bb]49#else
[7d90aa]50#define npTest(A,r)     (0)
[35aab3]51#endif
52
53//int     npGetChar();
54
[7d90aa]55nMapFunc npSetMap(const coeffs src, const coeffs dst);
[2336d0]56number  npMapP(number from, const coeffs src, const coeffs r);
57number  npMap0(number from, const coeffs src, const coeffs r);
[35aab3]58/*-------specials for spolys, do NOT use otherwise--------------------------*/
59/* for npMultM, npSubM, npNegM, npEqualM : */
60#ifdef HAVE_DIV_MOD
[900802]61extern unsigned short *npInvTable;
[35aab3]62#else
63#ifndef HAVE_MULT_MOD
64extern long npPminus1M;
[900802]65extern unsigned short *npExpTable;
66extern unsigned short *npLogTable;
[35aab3]67#endif
68#endif
69
70#if 0
71inline number npMultM(number a, number b)
72// return (a*b)%n
73{
74   double ab;
75   long q, res;
76
77   ab = ((double) ((int)a)) * ((double) ((int)b));
78   q  = (long) (ab/((double) npPrimeM));  // q could be off by (+/-) 1
79   res = (long) (ab - ((double) q)*((double) npPrimeM));
80   res += (res >> 31) & npPrimeM;
81   res -= npPrimeM;
82   res += (res >> 31) & npPrimeM;
83   return (number)res;
84}
85#endif
86#ifdef HAVE_MULT_MOD
[7d90aa]87static inline number npMultM(number a, number b, const coeffs r)
[35aab3]88{
89  return (number) 
[7d90aa]90    ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r->npPrimeM));
[35aab3]91}
92#else
[7d90aa]93static inline number npMultM(number a, number b, const coeffs r)
[35aab3]94{
[7d90aa]95  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
96  return (number)(long)r->npExpTable[x<r->npPminus1M ? x : x- r->npPminus1M];
[35aab3]97}
98#endif
99
100#if 0
101inline number npAddAsm(number a, number b, int m)
102{
103  number r;
104    asm ("addl %2, %1; cmpl %3, %1; jb 0f; subl %3, %1; 0:"
105         : "=&r" (r)
106         : "%0" (a), "g" (b), "g" (m)
107         : "cc");
108  return r;
109}
110inline number npSubAsm(number a, number b, int m)
111{
112  number r;
113  asm ("subl %2, %1; jnc 0f; addl %3, %1; 0:"
114        : "=&r" (r)
115        : "%0" (a), "g" (b), "g" (m)
116        : "cc");
117  return r;
118}
119#endif
120#ifdef HAVE_GENERIC_ADD
[7d90aa]121static inline number npAddM(number a, number b, const coeffs r)
[35aab3]122{
[7d90aa]123  long R = (long)a + (long)b;
124  return (number)(R >= r->npPrimeM ? R - r->npPrimeM : R);
[35aab3]125}
[7d90aa]126static inline number npSubM(number a, number b, const coeffs r)
[35aab3]127{
[6c56a8]128  return (number)((long)a<(long)b ?
[7d90aa]129                       r->npPrimeM-(long)b+(long)a : (long)a-(long)b);
[35aab3]130}
131#else
[7d90aa]132static inline number npAddM(number a, number b, const coeffs r)
[35aab3]133{
[6c56a8]134   long res = ((long)a + (long)b);
[7d90aa]135   res -= r->npPrimeM;
[6c56a8]136#if SIZEOF_LONG == 8
[7d90aa]137   res += (res >> 63) & r->npPrimeM;
[6c56a8]138#else
[7d90aa]139   res += (res >> 31) & r->npPrimeM;
[6c56a8]140#endif
[35aab3]141   return (number)res;
142}
[7d90aa]143static inline number npSubM(number a, number b, const coeffs r)
[35aab3]144{
[6c56a8]145   long res = ((long)a - (long)b);
146#if SIZEOF_LONG == 8
[7d90aa]147   res += (res >> 63) & r->npPrimeM;
[6c56a8]148#else
[7d90aa]149   res += (res >> 31) & r->npPrimeM;
[6c56a8]150#endif
[35aab3]151   return (number)res;
152}
153#endif
154
[b58d47]155static inline BOOLEAN npIsZeroM (number  a, const coeffs)
[35aab3]156{
157  return 0 == (long)a;
158}
159
160/*
161*inline number npMultM(number a, number b)
162*{
163*  return (number)(((long)a*(long)b) % npPrimeM);
164*}
165*/
166
[7d90aa]167#define npNegM(A,r)      (number)(r->npPrimeM-(long)(A))
168#define npEqualM(A,B,r)  ((A)==(B))
[35aab3]169
170
171#ifdef NV_OPS
[7f7b2a]172#pragma GCC diagnostic ignored "-Wlong-long"
[7d90aa]173static inline number nvMultM(number a, number b, const coeffs r)
[35aab3]174{
175#if SIZEOF_LONG == 4
[cccd36]176#define ULONG64 (unsigned long long)(unsigned long)
[35aab3]177#else
[cccd36]178#define ULONG64 (unsigned long)
[35aab3]179#endif
180  return (number) 
[7d90aa]181    (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->npPrimeM));
[35aab3]182}
[7d90aa]183number  nvMult        (number a, number b, const coeffs r);
184number  nvDiv         (number a, number b, const coeffs r);
185number  nvInvers      (number c, const coeffs r);
186void    nvPower       (number a, int i, number * result, const coeffs r);
[35aab3]187#endif
188
189#endif
Note: See TracBrowser for help on using the repository browser.