Changeset 6e969c in git
- Timestamp:
- Apr 23, 2018, 6:10:26 PM (5 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- 2a26e5cb4fa3b3a9830c9062444f5d6051880a5f
- Parents:
- eb6e1d58eb9834a39221581ba56d2e26f61499cc
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/GBEngine/tgb_internal.h
reb6e1d r6e969c 71 71 72 72 #define npInit n_Init 73 #define npNeg n _InpNeg74 #define npInvers n _Invers75 #define npMult n _Mult76 #define npIsOne n_IsOne77 #define npIsZero n _IsZero73 #define npNeg npNegM 74 #define npInvers npInversM 75 #define npMult npMultM 76 //#define npIsOne n_IsOne 77 #define npIsZero npIsZeroM 78 78 79 79 #else -
libpolys/coeffs/modulop.cc
reb6e1d r6e969c 141 141 } 142 142 143 BOOLEAN npIsOne (number a, const coeffs r)144 {145 n_Test(a, r);146 147 return 1 == (long)a;148 }149 150 143 BOOLEAN npIsMOne (number a, const coeffs r) 151 144 { … … 153 146 154 147 return ((r->npPminus1M == (long)a) &&(1L!=(long)a))/*for char 2*/; 155 }156 157 #ifdef USE_NTL_XGCD158 159 //ifdef HAVE_NTL // in ntl.a160 //extern void XGCD(long& d, long& s, long& t, long a, long b);161 #include <NTL/ZZ.h>162 #ifdef NTL_CLIENT163 NTL_CLIENT164 #endif165 166 #endif167 168 static inline long InvMod(long a, const coeffs R)169 {170 long s, t;171 172 #ifdef USE_NTL_XGCD173 long d;174 XGCD(d, s, t, a, R->ch);175 assume (d == 1);176 #else177 long u, v, u0, v0, u1, v1, u2, v2, q, r;178 179 assume(a>0);180 u1=1; u2=0;181 u = a; v = R->ch;182 183 while (v != 0)184 {185 q = u / v;186 //r = u % v;187 r = u - q*v;188 u = v;189 v = r;190 u0 = u2;191 u2 = u1 - q*u2;192 u1 = u0;193 }194 195 assume(u==1);196 s = u1;197 #endif198 #ifdef HAVE_GENERIC_ADD199 if (s < 0)200 return s + R->ch;201 else202 return s;203 #else204 #if SIZEOF_LONG == 8205 s += (s >> 63) & R->ch;206 #else207 s += (s >> 31) & R->ch;208 #endif209 return s;210 #endif211 }212 213 static inline number npInversM (number c, const coeffs r)214 {215 n_Test(c, r);216 #ifndef HAVE_GENERIC_MULT217 #ifndef HAVE_INVTABLE218 number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];219 #else220 long inv=(long)r->npInvTable[(long)c];221 if (inv==0)222 {223 inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];224 r->npInvTable[(long)c]=inv;225 }226 number d = (number)inv;227 #endif228 #else229 #ifdef HAVE_INVTABLE230 long inv=(long)r->npInvTable[(long)c];231 if (inv==0)232 {233 inv=InvMod((long)c,r);234 r->npInvTable[(long)c]=inv;235 }236 #else237 long inv=InvMod((long)c,r);238 #endif239 number d = (number)inv;240 #endif241 n_Test(d, r);242 return d;243 148 } 244 149 … … 826 731 static inline number nvInversM (number c, const coeffs r) 827 732 { 828 long inv= InvMod((long)c,r);733 long inv=npInvMod((long)c,r); 829 734 return (number)inv; 830 735 } -
libpolys/coeffs/modulop.h
reb6e1d r6e969c 29 29 #define NV_MAX_PRIME 32749 30 30 #define FACTORY_MAX_PRIME 536870909 31 32 #ifdef USE_NTL_XGCD 33 //ifdef HAVE_NTL // in ntl.a 34 //extern void XGCD(long& d, long& s, long& t, long a, long b); 35 #include <NTL/ZZ.h> 36 #ifdef NTL_CLIENT 37 NTL_CLIENT 38 #endif 39 #endif 31 40 32 41 struct n_Procs_s; typedef struct n_Procs_s *coeffs; … … 173 182 return 0 == (long)a; 174 183 } 175 176 // inline number npMultM(number a, number b, int npPrimeM) 177 // { 178 // return (number)(((long)a*(long)b) % npPrimeM); 179 // } 184 static inline BOOLEAN npIsOne (number a, const coeffs) 185 { 186 return 1 == (long)a; 187 } 188 189 static inline long npInvMod(long a, const coeffs R) 190 { 191 long s, t; 192 193 #ifdef USE_NTL_XGCD 194 long d; 195 XGCD(d, s, t, a, R->ch); 196 assume (d == 1); 197 #else 198 long u, v, u0, v0, u1, v1, u2, v2, q, r; 199 200 assume(a>0); 201 u1=1; u2=0; 202 u = a; v = R->ch; 203 204 while (v != 0) 205 { 206 q = u / v; 207 //r = u % v; 208 r = u - q*v; 209 u = v; 210 v = r; 211 u0 = u2; 212 u2 = u1 - q*u2; 213 u1 = u0; 214 } 215 216 assume(u==1); 217 s = u1; 218 #endif 219 #ifdef HAVE_GENERIC_ADD 220 if (s < 0) 221 return s + R->ch; 222 else 223 return s; 224 #else 225 #if SIZEOF_LONG == 8 226 s += (s >> 63) & R->ch; 227 #else 228 s += (s >> 31) & R->ch; 229 #endif 230 return s; 231 #endif 232 } 233 234 static inline number npInversM (number c, const coeffs r) 235 { 236 n_Test(c, r); 237 #ifndef HAVE_GENERIC_MULT 238 #ifndef HAVE_INVTABLE 239 number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]]; 240 #else 241 long inv=(long)r->npInvTable[(long)c]; 242 if (inv==0) 243 { 244 inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]]; 245 r->npInvTable[(long)c]=inv; 246 } 247 number d = (number)inv; 248 #endif 249 #else 250 #ifdef HAVE_INVTABLE 251 long inv=(long)r->npInvTable[(long)c]; 252 if (inv==0) 253 { 254 inv=npInvMod((long)c,r); 255 r->npInvTable[(long)c]=inv; 256 } 257 #else 258 long inv=npInvMod((long)c,r); 259 #endif 260 number d = (number)inv; 261 #endif 262 n_Test(d, r); 263 return d; 264 } 265 180 266 181 267 // The folloing is reused inside gnumpc.cc, gnumpfl.cc and longrat.cc
Note: See TracChangeset
for help on using the changeset viewer.