Changeset 2a4a23 in git


Ignore:
Timestamp:
Apr 20, 2018, 3:03:49 PM (6 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
eb6e1d58eb9834a39221581ba56d2e26f61499cc
Parents:
65c1bd5b526a9447123bf85f32538aff3498501c
Message:
fix: Z/p-arithmetic for all architectures
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/misc_ip.cc

    r65c1bd r2a4a23  
    895895              StringAppendS("AvoidBranching,");
    896896#endif
    897 #ifdef HAVE_MULT_MOD
     897#ifdef HAVE_GENERIC_MULT
    898898              StringAppendS("GenericMult,");
    899899#else
    900900              StringAppendS("TableMult,");
     901#endif
     902#ifdef HAVE_INVTABLE
     903              StringAppendS("invTable,");
     904#else
     905              StringAppendS("no invTable,");
    901906#endif
    902907              StringAppendS("\n\t");
  • libpolys/coeffs/modulop.cc

    r65c1bd r2a4a23  
    207207  s += (s >> 31) & R->ch;
    208208  #endif
     209  return s;
    209210#endif
    210211}
     
    213214{
    214215  n_Test(c, r);
    215 #if !defined(HAVE_MULT_MOD) && (!defined(HAVE_DIV_MOD))
     216#ifndef HAVE_GENERIC_MULT
     217  #ifndef HAVE_INVTABLE
    216218  number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
    217 #else
     219  #else
    218220  long inv=(long)r->npInvTable[(long)c];
    219221  if (inv==0)
    220222  {
    221     #ifndef HAVE_MULT_MOD
    222223    inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
    223     #else
     224    r->npInvTable[(long)c]=inv;
     225  }
     226  number d = (number)inv;
     227  #endif
     228#else
     229  #ifdef HAVE_INVTABLE
     230  long inv=(long)r->npInvTable[(long)c];
     231  if (inv==0)
     232  {
    224233    inv=InvMod((long)c,r);
    225     #endif
    226234    r->npInvTable[(long)c]=inv;
    227235  }
     236  #else
     237  long  inv=InvMod((long)c,r);
     238  #endif
    228239  number d = (number)inv;
    229240#endif
     
    245256
    246257  number d;
    247 #ifndef HAVE_DIV_MOD
     258#ifndef HAVE_GENERIC_MULT
    248259  int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
     260  #ifdef HAVE_GENERIC_ADD
    249261  if (s < 0)
    250262    s += r->npPminus1M;
     263  #else
     264    #if SIZEOF_LONG == 8
     265    s += ((long)s >> 63) & r->npPminus1M;
     266    #else
     267    s += ((long)s >> 31) & r->npPminus1M;
     268    #endif
     269  #endif
    251270  d = (number)(long)r->npExpTable[s];
    252271#else
     
    395414void npKillChar(coeffs r)
    396415{
    397   #ifdef HAVE_DIV_MOD
     416  #ifdef HAVE_INVTABLE
    398417  if (r->npInvTable!=NULL)
    399   omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
    400   r->npInvTable=NULL;
    401   #else
     418  {
     419    omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
     420    r->npInvTable=NULL;
     421  }
     422  #endif
     423  #ifndef HAVE_GENERIC_MULT
    402424  if (r->npExpTable!=NULL)
    403425  {
     
    548570#endif
    549571  {
    550 #ifdef HAVE_DIV_MOD
     572#ifdef HAVE_INVTABLE
    551573    r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
    552 #elif (!defined(HAVE_MULT_MOD)||(!HAVE_DIV_MOD))
     574#endif
     575#ifndef HAVE_GENERIC_MULT
    553576    r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
    554577    r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
     
    801824}
    802825
    803 static inline long nvInvMod(long a, const coeffs R)
    804 {
    805 #ifdef HAVE_DIV_MOD
    806   return InvMod(a, R);
    807 #else
    808 /// TODO: use "long InvMod(long a, const coeffs R)"?!
    809 
    810    long  s;
    811 
    812    long  u, u0, u1, u2, q, r; // v0, v1, v2,
    813 
    814    u1=1; // v1=0;
    815    u2=0; // v2=1;
    816    u = a;
    817 
    818    long v = R->ch;
    819 
    820    while (v != 0)
    821    {
    822       q = u / v;
    823       r = u % v;
    824       u = v;
    825       v = r;
    826       u0 = u2;
    827 //      v0 = v2;
    828       u2 = u1 - q*u2;
    829 //      v2 = v1 - q*v2;
    830       u1 = u0;
    831 //      v1 = v0;
    832    }
    833 
    834    s = u1;
    835    //t = v1;
    836    if (s < 0)
    837       return s + R->ch;
    838    else
    839      return s;
    840 #endif
    841 }
    842 
    843826static inline number nvInversM (number c, const coeffs r)
    844827{
    845   long inv=nvInvMod((long)c,r);
     828  long inv=InvMod((long)c,r);
    846829  return (number)inv;
    847830}
  • libpolys/coeffs/modulop.h

    r65c1bd r2a4a23  
    99#include "misc/auxiliary.h"
    1010
    11 // defines are in struct.h
     11
    1212// 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
     13//#define HAVE_GENERIC_MULT
     14// define if 1/b is from tables
     15//#define HAVE_INVTABLE
    1616// define if an if should be used
    1717//#define HAVE_GENERIC_ADD
     18
     19//#undef HAVE_GENERIC_ADD
     20//#undef HAVE_GENERIC_MULT
     21//#undef HAVE_INVTABLE
     22
     23//#define HAVE_GENERIC_ADD 1
     24//#define HAVE_GENERIC_MULT 1
     25//#define HAVE_INVTABLE 1
    1826
    1927// enable large primes (32749 < p < 2^31-)
     
    4149//    return (number)res;
    4250// }
    43 #ifdef HAVE_MULT_MOD
     51#ifdef HAVE_GENERIC_MULT
    4452static inline number npMultM(number a, number b, const coeffs r)
    4553{
  • m4/cpu-check.m4

    r65c1bd r2a4a23  
    4949
    5050AS_CASE([$host_cpu],
     51dnl the following settings seems to be better on itanium processors
     52  [ia64*], [
     53      AC_DEFINE(HAVE_GENERIC_ADD,1,use branch for addition in Z/p otherwise it uses a generic add)],
    5154dnl the following settings seems to be better on i386 and x86_64 processors
    52   [i*86*|x86_64*], [AC_DEFINE(HAVE_MULT_MOD,1,multiplication is fast on the cpu: a*b is with mod otherwise using tables of logartihms)],
    53 dnl the following settings seems to be better on itanium processors
    54 dnl AC_DEFINE(HAVE_MULT_MOD,1,)
    55   [ia64*], [AC_DEFINE(HAVE_GENERIC_ADD,1,use branch for addition in Z/p otherwise it uses a generic add)],
     55dnl AC_DEFINE(HAVE_GENERIC_MULT,1,)
     56  [i*86*|x86_64*], [
     57            AC_DEFINE(HAVE_GENERIC_ADD,1,use branch for addition in Z/p otherwise it uses a generic add)
     58            AC_DEFINE(HAVE_GENERIC_MULT,1,multiplication is fast on the cpu: a*b is with mod otherwise using tables of logartihms)
     59            ],
    5660dnl the following settings seems to be better on sparc processors
    5761  [sparc*], [
    58             AC_DEFINE(HAVE_MULT_MOD,1,multiplication is fast on the cpu: a*b is with mod otherwise using tables of logartihms)
    59             AC_DEFINE(HAVE_DIV_MOD,1,division using extend euclidian algorithm otherwise using tables of logartihms)
     62            AC_DEFINE(HAVE_GENERIC_ADD,1,use branch for addition in Z/p otherwise it uses a generic add)
    6063            ],
    6164dnl the following settings seems to be better on ppc processors
    6265dnl testet on: ppc_Linux, 740/750 PowerMac G3, 512k L2 cache
    63   [powerpc*|ppc*], [AC_DEFINE(HAVE_MULT_MOD,1,multiplication is fast on the cpu: a*b is with mod otherwise using tables of logartihms)],
     66  [powerpc*|yyppc*], [AC_DEFINE(HAVE_GENERIC_MULT,1,multiplication is fast on the cpu: a*b is with mod otherwise using tables of logartihms)],
    6467  []
    6568)
Note: See TracChangeset for help on using the changeset viewer.