Changeset 246d15 in git


Ignore:
Timestamp:
Feb 14, 2011, 4:50:05 PM (13 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
c880c179f5777247d29dc13017c11fc651c7c366
Parents:
6185cc201360857550a263f9769d0c21aca8d208
Message:
prepare for 64bit inline numbers

git-svn-id: file:///usr/local/Singular/svn/trunk@13841 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/longrat.cc

    r6185cc r246d15  
    77*/
    88
     9#include <kernel/mod2.h>
     10#include <kernel/structs.h>
     11#include <kernel/longrat.h>
     12
     13// 64 bit version:
     14#if 0
     15#define MAX_NUM_SIZE 60
     16#define POW_2_28 0x10000000000000L
     17#define LONG long
     18#else
     19#define MAX_NUM_SIZE 28
     20#define POW_2_28 (1L<<28)
     21#define LONG int
     22#endif
     23
     24static inline number nlShort3(number x) // assume x->s==3
     25{
     26  assume(x->s==3);
     27  if ((mpz_cmp_ui(x->z,(long)0)==0)
     28  || (mpz_size1(x->z)<=MP_SMALL))
     29  {
     30    LONG ui=mpz_get_si(x->z);
     31    if ((((ui<<3)>>3)==ui)
     32    && (mpz_cmp_si(x->z,(long)ui)==0))
     33    {
     34      mpz_clear(x->z);
     35      omFreeBin((ADDRESS)x, rnumber_bin);
     36      return INT_TO_SR(ui);
     37    }
     38  }
     39  return x;
     40}
     41
    942#ifndef LONGRAT_CC
    1043#define LONGRAT_CC
     
    1245#include <string.h>
    1346#include <float.h>
    14 #include <kernel/mod2.h>
    15 #include <kernel/structs.h>
    1647#include <omalloc/omalloc.h>
    1748#include <kernel/febase.h>
     
    2152#include <kernel/shortfl.h>
    2253#include <kernel/mpr_complex.h>
    23 #include <kernel/longrat.h>
    2454
    2555
     
    85115#ifndef P_NUMBERS_H
    86116
     117number nlShort3_noinline(number x) // assume x->s==3
     118{
     119  return nlShort3(x);
     120}
     121
    87122omBin rnumber_bin = omGetSpecBin(sizeof(snumber));
    88123
     
    126161  //mpz_init_set_ui(&z->n,1);
    127162  z->s = 3;
    128   if ((mpz_cmp_ui(z->z,(long)0)==0)
    129   || (mpz_size1(z->z)<=MP_SMALL))
    130   {
    131     int ui=(int)mpz_get_si(z->z);
    132     if ((((ui<<3)>>3)==ui)
    133     && (mpz_cmp_si(z->z,(long)ui)==0))
    134     {
    135       mpz_clear(z->z);
    136       omFreeBin((ADDRESS)z, rnumber_bin);
    137       return INT_TO_SR(ui);
    138     }
    139   }
     163  z=nlShort3(z);
    140164  return z;
    141165}
     
    152176  mpz_init_set_ui(z->z,(unsigned long) from);
    153177  z->s = 3;
    154   if ((mpz_cmp_ui(z->z,(long)0)==0)
    155   || (mpz_size1(z->z)<=MP_SMALL))
    156   {
    157     int ui=(int)mpz_get_si(z->z);
    158     if ((((ui<<3)>>3)==ui)
    159     && (mpz_cmp_si(z->z,(long)ui)==0))
    160     {
    161       mpz_clear(z->z);
    162       omFreeBin((ADDRESS)z, rnumber_bin);
    163       return INT_TO_SR(ui);
    164     }
    165   }
     178  z=nlShort3(z);
    166179  return z;
    167180}
     
    216229  if ((((long)a)&3L)==1L)
    217230  {
    218     if (((((long)a)<<1)>>1)!=((long)a))
     231    if (((((LONG)(long)a)<<1)>>1)!=((LONG)(long)a))
    219232    {
    220233      Print(" !!longrat:arith:%lx in %s:%d\n",(long)a, f,l);
     
    264277  //}
    265278  if (mpz_size1(a->z)>MP_SMALL) return TRUE;
    266   int ui=(int)mpz_get_si(a->z);
     279  LONG ui=(int)mpz_get_si(a->z);
    267280  if ((((ui<<3)>>3)==ui)
    268281  && (mpz_cmp_si(a->z,(long)ui)==0))
     
    276289#endif
    277290
    278 number nlRInit (int i);
     291number nlRInit (long i);
    279292
    280293static number nlMapR(number from)
     
    372385  if (res->s==0)
    373386    nlNormalize(res);
    374   else if (mpz_size1(res->z)<=MP_SMALL)
     387  else
    375388  {
    376389    // res is new, res->ref is 1
    377     int ui=(int)mpz_get_si(res->z);
    378     if ((((ui<<3)>>3)==ui)
    379        && (mpz_cmp_si(res->z,(long)ui)==0))
    380     {
    381        mpz_clear(res->z);
    382 #if defined(LDEBUG)
    383        res->debug=654324;
    384 #endif
    385        omFreeBin((ADDRESS)res, rnumber_bin);
    386        return INT_TO_SR(ui);
    387     }
    388   }
    389 #if defined(LDEBUG)
     390    res=nlShort3(res);
     391  }
    390392  nlTest(res);
    391 #endif
    392393  return res;
    393394}
     
    489490int nlInt(number &i, const ring r)
    490491{
    491 #ifdef LDEBUG
    492492  nlTest(i);
    493 #endif
    494493  nlNormalize(i);
    495494  if (SR_HDL(i) &SR_INT) return SR_TO_INT(i);
     
    520519number nlBigInt(number &i)
    521520{
    522 #ifdef LDEBUG
    523521  nlTest(i);
    524 #endif
    525522  nlNormalize(i);
    526523  if (SR_HDL(i) &SR_INT) return (i);
     
    531528  number tmp=nlRInit(1);
    532529  MPZ_DIV(tmp->z,i->z,i->n);
    533   if (mpz_size1(tmp->z)<=MP_SMALL)
    534   {
    535     int ui=mpz_get_si(tmp->z);
    536      if ((((ui<<3)>>3)==ui)
    537      && (mpz_cmp_si(tmp->z,(long)ui)==0))
    538      {
    539        mpz_clear(tmp->z);
    540 #if defined(LDEBUG)
    541        tmp->debug=654324;
    542 #endif
    543        omFreeBin((ADDRESS)tmp, rnumber_bin);
    544        return INT_TO_SR(ui);
    545      }
    546   }
     530  tmp=nlShort3(tmp);
    547531  return tmp;
    548532}
     
    553537number nlInvers(number a)
    554538{
    555 #ifdef LDEBUG
    556539  nlTest(a);
    557 #endif
    558540  number n;
    559541  if (SR_HDL(a) & SR_INT)
    560542  {
    561     if ((a==INT_TO_SR(1)) || (a==INT_TO_SR(-1)))
     543    if ((a==INT_TO_SR(1L)) || (a==INT_TO_SR(-1L)))
    562544    {
    563545      return a;
     
    583565      mpz_init_set_si(n->n,(long)-SR_TO_INT(a));
    584566    }
    585 #ifdef LDEBUG
    586567    nlTest(n);
    587 #endif
    588568    return n;
    589569  }
     
    609589                mpz_clear(n->n);
    610590                n->s=3;
    611                 if (mpz_size1(n->z)<=MP_SMALL)
    612                 {
    613                   int ui=(int)mpz_get_si(n->z);
    614                   if ((((ui<<3)>>3)==ui)
    615                   && (mpz_cmp_si(n->z,(long)ui)==0))
    616                   {
    617                     mpz_clear(n->z);
    618 #if defined(LDEBUG)
    619                     n->debug=654324;
    620 #endif
    621                     omFreeBin((ADDRESS)n, rnumber_bin);
    622                     n=INT_TO_SR(ui);
    623                   }
    624                 }
     591                n=nlShort3(n);
    625592              }
    626593              break;
     
    639606    }
    640607  }
    641 #ifdef LDEBUG
    642608  nlTest(n);
    643 #endif
    644609  return n;
    645610}
     
    662627  {
    663628    /* the small int -(1<<28) divided by -1 is the large int (1<<28)   */
    664     if ((a==INT_TO_SR(-(1<<28)))&&(b==INT_TO_SR(-1)))
    665     {
    666       return nlRInit(1<<28);
    667     }
    668     int aa=SR_TO_INT(a);
    669     int bb=SR_TO_INT(b);
     629    if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
     630    {
     631      return nlRInit(POW_2_28);
     632    }
     633    long aa=SR_TO_INT(a);
     634    long bb=SR_TO_INT(b);
    670635    return INT_TO_SR(aa/bb);
    671636  }
     
    692657    omFreeBin((ADDRESS)bb, rnumber_bin);
    693658  }
    694   if (mpz_size1(u->z)<=MP_SMALL)
    695   {
    696     int ui=(int)mpz_get_si(u->z);
    697     if ((((ui<<3)>>3)==ui)
    698     && (mpz_cmp_si(u->z,(long)ui)==0))
    699     {
    700       mpz_clear(u->z);
    701 #if defined(LDEBUG)
    702       u->debug=654324;
    703 #endif
    704       omFreeBin((ADDRESS)u, rnumber_bin);
    705       u=INT_TO_SR(ui);
    706     }
    707   }
    708 #ifdef LDEBUG
     659  u=nlShort3(u);
    709660  nlTest(u);
    710 #endif
    711661  return u;
    712662}
     
    728678  {
    729679    /* the small int -(1<<28) divided by -1 is the large int (1<<28)   */
    730     if ((a==INT_TO_SR(-(1<<28)))&&(b==INT_TO_SR(-1)))
    731     {
    732       return nlRInit(1<<28);
    733     }
    734     int aa=SR_TO_INT(a);
    735     int bb=SR_TO_INT(b);
     680    if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
     681    {
     682      return nlRInit(POW_2_28);
     683    }
     684    long aa=SR_TO_INT(a);
     685    long bb=SR_TO_INT(b);
    736686    return INT_TO_SR(aa/bb);
    737687  }
     
    739689  {
    740690    /* the small int -(1<<28) divided by 2^28 is 1   */
    741     if (a==INT_TO_SR(-(1<<28)))
    742     {
    743       if(mpz_cmp_si(b->z,(long)(1<<28))==0)
     691    if (a==INT_TO_SR(-(POW_2_28)))
     692    {
     693      if(mpz_cmp_si(b->z,(POW_2_28))==0)
    744694      {
    745695        return INT_TO_SR(-1);
     
    773723    omFreeBin((ADDRESS)bb, rnumber_bin);
    774724  }
    775   if (mpz_size1(u->z)<=MP_SMALL)
    776   {
    777     int ui=(int)mpz_get_si(u->z);
    778     if ((((ui<<3)>>3)==ui)
    779     && (mpz_cmp_si(u->z,(long)ui)==0))
    780     {
    781       mpz_clear(u->z);
    782 #if defined(LDEBUG)
    783       u->debug=654324;
    784 #endif
    785       omFreeBin((ADDRESS)u, rnumber_bin);
    786       u=INT_TO_SR(ui);
    787     }
    788   }
    789 #ifdef LDEBUG
     725  u=nlShort3(u);
    790726  nlTest(u);
    791 #endif
    792727  return u;
    793728}
     
    819754      if ((long)b>0L)
    820755      {
    821         int i=(-SR_TO_INT(a))%SR_TO_INT(b);
    822         if ( i != 0 ) i = (SR_TO_INT(b))-i;
     756        long i=(-SR_TO_INT(a))%SR_TO_INT(b);
     757        if ( i != 0L ) i = (SR_TO_INT(b))-i;
    823758        return INT_TO_SR(i);
    824759      }
    825760      else
    826761      {
    827         int i=(-SR_TO_INT(a))%(-SR_TO_INT(b));
    828         if ( i != 0 ) i = (-SR_TO_INT(b))-i;
     762        long i=(-SR_TO_INT(a))%(-SR_TO_INT(b));
     763        if ( i != 0L ) i = (-SR_TO_INT(b))-i;
    829764        return INT_TO_SR(i);
    830765      }
     
    872807      mpz_add(u->z,u->z,b->z);
    873808  }
    874   if (mpz_size1(u->z)<=MP_SMALL)
    875   {
    876     int ui=(int)mpz_get_si(u->z);
    877     if ((((ui<<3)>>3)==ui)
    878     && (mpz_cmp_si(u->z,(long)ui)==0))
    879     {
    880       mpz_clear(u->z);
    881 #if defined(LDEBUG)
    882       u->debug=654324;
    883 #endif
    884       omFreeBin((ADDRESS)u, rnumber_bin);
    885       u=INT_TO_SR(ui);
    886     }
    887   }
    888 #ifdef LDEBUG
     809  u=nlShort3(u);
    889810  nlTest(u);
    890 #endif
    891811  return u;
    892812}
     
    911831  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
    912832  {
    913     int i=SR_TO_INT(a);
    914     int j=SR_TO_INT(b);
    915     int r=i%j;
     833    long i=SR_TO_INT(a);
     834    long j=SR_TO_INT(b);
     835    long r=i%j;
    916836    if (r==0)
    917837    {
     
    986906  {
    987907    mpz_clear(u->n);
    988     if (mpz_size1(u->z)<=MP_SMALL)
    989     {
    990       int ui=(int)mpz_get_si(u->z);
    991       if ((((ui<<3)>>3)==ui)
    992       && (mpz_cmp_si(u->z,(long)ui)==0))
    993       {
    994         mpz_clear(u->z);
    995         omFreeBin((ADDRESS)u, rnumber_bin);
    996         return INT_TO_SR(ui);
    997       }
    998     }
    999908    u->s=3;
    1000   }
    1001 #ifdef LDEBUG
     909    u=nlShort3(u);
     910  }
    1002911  nlTest(u);
    1003 #endif
    1004912  return u;
    1005913}
     
    1013921  if (!nlIsZero(x))
    1014922  {
    1015 #ifdef LDEBUG
    1016923    nlTest(x);
    1017 #endif
    1018924    number aa=NULL;
    1019925    if (SR_HDL(x) & SR_INT)
     
    1044950    }
    1045951    (*u)->s = x->s;
    1046     if (((*u)->s==3) && (mpz_size1((*u)->z)<=MP_SMALL))
    1047     {
    1048       int ui=(int)mpz_get_si((*u)->z);
    1049       if ((((ui<<3)>>3)==ui)
    1050       && (mpz_cmp_si((*u)->z,(long)ui)==0))
    1051       {
    1052         mpz_clear((*u)->z);
    1053         omFreeBin((ADDRESS)*u, rnumber_bin);
    1054         *u=INT_TO_SR(ui);
    1055       }
    1056     }
     952    if ((*u)->s==3) *u=nlShort3(*u);
    1057953    if (aa!=NULL)
    1058954    {
     
    1075971BOOLEAN nlGreaterZero (number a)
    1076972{
    1077 #ifdef LDEBUG
    1078973  nlTest(a);
    1079 #endif
    1080   if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1 /* represents number(0) */;
     974  if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1L /* represents number(0) */;
    1081975  return (!mpz_isNeg(a->z));
    1082976}
     
    1087981BOOLEAN nlGreater (number a, number b)
    1088982{
    1089 #ifdef LDEBUG
    1090983  nlTest(a);
    1091984  nlTest(b);
    1092 #endif
    1093985  number r;
    1094986  BOOLEAN rr;
     
    11081000  nlTest(a);
    11091001#endif
    1110   //if (SR_HDL(a) & SR_INT) return (a==INT_TO_SR(-1));
     1002  //if (SR_HDL(a) & SR_INT) return (a==INT_TO_SR(-1L));
    11111003  //return FALSE;
    1112   return  (a==INT_TO_SR(-1));
     1004  return  (a==INT_TO_SR(-1L));
    11131005}
    11141006
     
    11191011{
    11201012  number result;
    1121 #ifdef LDEBUG
    11221013  nlTest(a);
    11231014  nlTest(b);
    1124 #endif
    11251015  //nlNormalize(a);
    11261016  //nlNormalize(b);
    1127   if ((a==INT_TO_SR(1))||(a==INT_TO_SR(-1))
    1128   ||  (b==INT_TO_SR(1))||(b==INT_TO_SR(-1)))
    1129     return INT_TO_SR(1);
     1017  if ((a==INT_TO_SR(1L))||(a==INT_TO_SR(-1L))
     1018  ||  (b==INT_TO_SR(1L))||(b==INT_TO_SR(-1L)))
     1019    return INT_TO_SR(1L);
    11301020  if (a==INT_TO_SR(0)) /* gcd(0,b) ->b */
    11311021    return nlCopy(b);
     
    11341024  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
    11351025  {
    1136     int i=SR_TO_INT(a);
    1137     int j=SR_TO_INT(b);
    1138     if((i==0)||(j==0))
     1026    long i=SR_TO_INT(a);
     1027    long j=SR_TO_INT(b);
     1028    if((i==0L)||(j==0L))
    11391029      return INT_TO_SR(1);
    1140     int l;
     1030    long l;
    11411031    i=ABS(i);
    11421032    j=ABS(j);
     
    11461036      i=j;
    11471037      j=l;
    1148     } while (l!=0);
     1038    } while (l!=0L);
    11491039    return INT_TO_SR(i);
    11501040  }
     
    11541044  {
    11551045    unsigned long t=mpz_gcd_ui(NULL,b->z,ABS(SR_TO_INT(a)));
    1156     return INT_TO_SR((int)t);
     1046    return INT_TO_SR(t);
    11571047  }
    11581048  else
     
    11601050  {
    11611051    unsigned long t=mpz_gcd_ui(NULL,a->z,ABS(SR_TO_INT(b)));
    1162     return INT_TO_SR((int)t);
     1052    return INT_TO_SR(t);
    11631053  }
    11641054  else
     
    11671057    mpz_init(result->z);
    11681058    mpz_gcd(result->z,a->z,b->z);
    1169     if (mpz_size1(result->z)<=MP_SMALL)
    1170     {
    1171       int ui=(int)mpz_get_si(result->z);
    1172       if ((((ui<<3)>>3)==ui)
    1173       && (mpz_cmp_si(result->z,(long)ui)==0))
    1174       {
    1175         mpz_clear(result->z);
    1176         omFreeBin((ADDRESS)result, rnumber_bin);
    1177         return INT_TO_SR(ui);
    1178       }
    1179     }
    11801059    result->s = 3;
    11811060  #ifdef LDEBUG
    11821061    result->debug=123456;
    1183     nlTest(result);
    11841062  #endif
    1185   }
     1063    result=nlShort3(result);
     1064  }
     1065  nlTest(result);
    11861066  return result;
    11871067}
     
    12011081      _nlDelete_NoImm(&x);
    12021082      return INT_TO_SR(1);
    1203     }
    1204   }
    1205   return x;
    1206 }
    1207 number nlShort3(number x) // assume x->s==3
    1208 {
    1209   assume(x->s==3);
    1210   if ((mpz_cmp_ui(x->z,(long)0)==0)
    1211   || (mpz_size1(x->z)<=MP_SMALL))
    1212   {
    1213     int ui=(int)mpz_get_si(x->z);
    1214     if ((((ui<<3)>>3)==ui)
    1215     && (mpz_cmp_si(x->z,(long)ui)==0))
    1216     {
    1217       mpz_clear(x->z);
    1218       omFreeBin((ADDRESS)x, rnumber_bin);
    1219       return INT_TO_SR(ui);
    12201083    }
    12211084  }
     
    12381101  if (x->s==3)
    12391102  {
    1240     x=nlShort3(x);
     1103    x=nlShort3_noinline(x);
    12411104    return;
    12421105  }
     
    12461109    {
    12471110      mpz_clear(x->n);
    1248       if (mpz_size1(x->z)<=MP_SMALL)
    1249       {
    1250         int ui=(int)mpz_get_si(x->z);
    1251         if ((((ui<<3)>>3)==ui)
    1252         && (mpz_cmp_si(x->z,(long)ui)==0))
    1253         {
    1254           mpz_clear(x->z);
    1255 #if defined(LDEBUG)
    1256           x->debug=654324;
    1257 #endif
    1258           omFreeBin((ADDRESS)x, rnumber_bin);
    1259           x=INT_TO_SR(ui);
    1260           return;
    1261         }
    1262       }
    12631111      x->s=3;
     1112      x=nlShort3(x);
    12641113    }
    12651114    else
     
    12811130        {
    12821131          mpz_clear(x->n);
    1283           if (mpz_size1(x->z)<=MP_SMALL)
    1284           {
    1285             int ui=(int)mpz_get_si(x->z);
    1286             if ((((ui<<3)>>3)==ui)
    1287             && (mpz_cmp_si(x->z,(long)ui)==0))
    1288             {
    1289               mpz_clear(x->z);
    1290               mpz_clear(gcd);
    1291 #if defined(LDEBUG)
    1292               x->debug=654324;
    1293 #endif
    1294               omFreeBin((ADDRESS)x, rnumber_bin);
    1295               x=INT_TO_SR(ui);
    1296               return;
    1297             }
    1298           }
    12991132          x->s=3;
     1133          x=nlShort3_noinline(x);
    13001134        }
    13011135      }
     
    13031137    }
    13041138  }
    1305 #ifdef LDEBUG
    13061139  nlTest(x);
    1307 #endif
    13081140}
    13091141
     
    13141146{
    13151147  number result;
    1316 #ifdef LDEBUG
    13171148  nlTest(a);
    13181149  nlTest(b);
    1319 #endif
    13201150  if ((SR_HDL(b) & SR_INT)
    13211151  || (b->s==3))
     
    13531183      mpz_mul(result->z,b->n,a->z);
    13541184  mpz_clear(gcd);
    1355   if (mpz_size1(result->z)<=MP_SMALL)
    1356   {
    1357     int ui=(int)mpz_get_si(result->z);
    1358     if ((((ui<<3)>>3)==ui)
    1359     && (mpz_cmp_si(result->z,(long)ui)==0))
    1360     {
    1361       mpz_clear(result->z);
    1362       omFreeBin((ADDRESS)result, rnumber_bin);
    1363       return INT_TO_SR(ui);
    1364     }
    1365   }
    1366 #ifdef LDEBUG
     1185  result=nlShort3(result);
    13671186  nlTest(result);
    1368 #endif
    13691187  return result;
    13701188}
     
    13741192  if (SR_HDL(n) & SR_INT)
    13751193  {
    1376     int i=SR_TO_INT(n);
    1377     if (i<0) return (p-((-i)%p));
    1378     return i%p;
     1194    long i=SR_TO_INT(n);
     1195    if (i<0L) return (((long)p)-((-i)%((long)p)));
     1196    return i%((long)p);
    13791197  }
    13801198  int iz=(int)mpz_fdiv_ui(n->z,(unsigned long)p);
     
    13981216{
    13991217  // Hier brauche ich einfach die GMP Zahl
    1400 #ifdef LDEBUG
    14011218  nlTest(i);
    1402 #endif
    14031219  nlNormalize(i);
    14041220  if (SR_HDL(i) & SR_INT)
    14051221  {
    1406     mpz_set_si((mpz_ptr) n, (long) SR_TO_INT(i));
     1222    mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
    14071223    return;
    14081224  }
     
    14361252#endif
    14371253        mpz_init_set(u->z,n->n);
    1438         {
    1439           int ui=(int)mpz_get_si(u->z);
    1440           if ((((ui<<3)>>3)==ui)
    1441           && (mpz_cmp_si(u->z,(long)ui)==0))
    1442           {
    1443             mpz_clear(u->z);
    1444             omFreeBin((ADDRESS)u, rnumber_bin);
    1445             return INT_TO_SR(ui);
    1446           }
    1447         }
     1254        u=nlShort3_noinline(u);
    14481255        return u;
    14491256      }
     
    14741281      if (n->s!=3)
    14751282      {
    1476         int ui=(int)mpz_get_si(u->z);
    1477         if ((((ui<<3)>>3)==ui)
    1478         && (mpz_cmp_si(u->z,(long)ui)==0))
    1479         {
    1480           mpz_clear(u->z);
    1481           omFreeBin((ADDRESS)u, rnumber_bin);
    1482           return INT_TO_SR(ui);
    1483         }
     1283        u=nlShort3_noinline(u);
    14841284      }
    14851285      return u;
     
    15441344{
    15451345  assume(!((SR_HDL(a) & SR_INT)||(a==NULL)));
    1546 #ifdef LDEBUG
    15471346  nlTest(a);
    1548 #endif
    15491347  number b=(number)omAllocBin(rnumber_bin);
    15501348#if defined(LDEBUG)
     
    15611359  }
    15621360  b->s = a->s;
    1563 #ifdef LDEBUG
    15641361  nlTest(b);
    1565 #endif
    15661362  return b;
    15671363}
     
    15891385  {
    15901386    mpz_neg(a->z,a->z);
    1591     if ((a->s==3) && (mpz_size1(a->z)<=MP_SMALL))
    1592     {
    1593       int ui=(int)mpz_get_si(a->z);
    1594       if ((((ui<<3)>>3)==ui)
    1595         && (mpz_cmp_si(a->z,(long)ui)==0))
    1596       {
    1597         mpz_clear(a->z);
    1598         omFreeBin((ADDRESS)a, rnumber_bin);
    1599         a=INT_TO_SR(ui);
    1600       }
    1601     }
    1602   }
    1603 #ifdef LDEBUG
     1387    if (a->s==3)
     1388    {
     1389      a=nlShort3(a);
     1390    }
     1391  }
    16041392  nlTest(a);
    1605 #endif
    16061393  return a;
    16071394}
     
    16601447          return INT_TO_SR(0);
    16611448        }
    1662         //u->s = 3;
    1663         if (mpz_size1(u->z)<=MP_SMALL)
    1664         {
    1665           int ui=(int)mpz_get_si(u->z);
    1666           if ((((ui<<3)>>3)==ui)
    1667           && (mpz_cmp_si(u->z,(long)ui)==0))
    1668           {
    1669             mpz_clear(u->z);
    1670             omFreeBin((ADDRESS)u, rnumber_bin);
    1671             return INT_TO_SR(ui);
    1672           }
    1673         }
    16741449        u->s = 3;
     1450        u=nlShort3(u);
    16751451        break;
    16761452      }
     
    17721548              return INT_TO_SR(0);
    17731549            }
    1774             if (mpz_size1(u->z)<=MP_SMALL)
    1775             {
    1776               int ui=(int)mpz_get_si(u->z);
    1777               if ((((ui<<3)>>3)==ui)
    1778               && (mpz_cmp_si(u->z,(long)ui)==0))
    1779               {
    1780                 mpz_clear(u->z);
    1781                 omFreeBin((ADDRESS)u, rnumber_bin);
    1782                 return INT_TO_SR(ui);
    1783               }
    1784             }
    17851550            u->s = 3;
     1551            u=nlShort3(u);
    17861552            break;
    17871553          }
     
    17911557    }
    17921558  }
    1793 #ifdef LDEBUG
    17941559  nlTest(u);
    1795 #endif
    17961560  return u;
    17971561}
     
    18501614          return INT_TO_SR(0);
    18511615        }
    1852         if (mpz_size1(u->z)<=MP_SMALL)
    1853         {
    1854           int ui=(int)mpz_get_si(u->z);
    1855           if ((((ui<<3)>>3)==ui)
    1856           && (mpz_cmp_si(u->z,(long)ui)==0))
    1857           {
    1858             mpz_clear(u->z);
    1859             omFreeBin((ADDRESS)u, rnumber_bin);
    1860             return INT_TO_SR(ui);
    1861           }
    1862         }
    18631616        u->s = 3;
     1617        u=nlShort3(u);
    18641618        break;
    18651619      }
     
    19101664          return INT_TO_SR(0);
    19111665        }
    1912         //u->s = 3;
    1913         if (mpz_size1(u->z)<=MP_SMALL)
    1914         {
    1915           int ui=(int)mpz_get_si(u->z);
    1916           if ((((ui<<3)>>3)==ui)
    1917           && (mpz_cmp_si(u->z,(long)ui)==0))
    1918           {
    1919             mpz_clear(u->z);
    1920             omFreeBin((ADDRESS)u, rnumber_bin);
    1921             return INT_TO_SR(ui);
    1922           }
    1923         }
    19241666        u->s = 3;
     1667        u=nlShort3(u);
    19251668        break;
    19261669      }
     
    20291772              return INT_TO_SR(0);
    20301773            }
    2031             //u->s = 3;
    2032             if (mpz_size1(u->z)<=MP_SMALL)
    2033             {
    2034               int ui=(int)mpz_get_si(u->z);
    2035               if ((((ui<<3)>>3)==ui)
    2036               && (mpz_cmp_si(u->z,(long)ui)==0))
    2037               {
    2038                 mpz_clear(u->z);
    2039                 omFreeBin((ADDRESS)u, rnumber_bin);
    2040                 return INT_TO_SR(ui);
    2041               }
    2042             }
    20431774            u->s = 3;
     1775            u=nlShort3(u);
    20441776            break;
    20451777          }
     
    20491781    }
    20501782  }
    2051 #ifdef LDEBUG
    20521783  nlTest(u);
    2053 #endif
    20541784  return u;
    20551785}
     
    20631793#endif
    20641794  u->s=3;
    2065   mpz_init_set_si(u->z,(long)SR_TO_INT(a));
    2066   mpz_mul_si(u->z,u->z,(long)SR_TO_INT(b));
    2067 #ifdef LDEBUG
     1795  mpz_init_set_si(u->z,SR_TO_INT(a));
     1796  mpz_mul_si(u->z,u->z,SR_TO_INT(b));
    20681797  nlTest(u);
    2069 #endif
    20701798  return u;
    20711799}
     
    21201848    else //u->s==3
    21211849    {
    2122       if (mpz_size1(u->z)<=MP_SMALL)
    2123       {
    2124         int ui=(int)mpz_get_si(u->z);
    2125         if ((((ui<<3)>>3)==ui)
    2126             && (mpz_cmp_si(u->z,(long)ui)==0))
    2127         {
    2128           mpz_clear(u->z);
    2129           omFreeBin((ADDRESS)u, rnumber_bin);
    2130           return INT_TO_SR(ui);
    2131         }
    2132       }
     1850      u=nlShort3(u);
    21331851    }
    21341852  }
     
    21801898    }
    21811899  }
    2182 #ifdef LDEBUG
    21831900  nlTest(u);
    2184 #endif
    21851901  return u;
    21861902}
     
    21891905* z := i
    21901906*/
    2191 number nlRInit (int i)
     1907number nlRInit (long i)
    21921908{
    21931909  number z=(number)omAllocBin(rnumber_bin);
     
    21951911  z->debug=123456;
    21961912#endif
    2197   mpz_init_set_si(z->z,(long)i);
     1913  mpz_init_set_si(z->z,i);
    21981914  z->s = 3;
    21991915  return z;
     
    22571973LINLINE BOOLEAN nlEqual (number a, number b)
    22581974{
    2259 #ifdef LDEBUG
    22601975  nlTest(a);
    22611976  nlTest(b);
    2262 #endif
    22631977// short - short
    22641978  if (SR_HDL(a) & SR_HDL(b) & SR_INT) return a==b;
     
    22701984{
    22711985  number n;
    2272   if ( ((i << 3) >> 3) == i ) n=INT_TO_SR(i);
    2273   else                        n=nlRInit(i);
    2274 #ifdef LDEBUG
     1986  LONG ii=(LONG)i;
     1987  if ( ((ii << 3) >> 3) == ii ) n=INT_TO_SR(ii);
     1988  else                          n=nlRInit(ii);
    22751989  nlTest(n);
    2276 #endif
    22771990  return n;
    22781991}
     
    23172030  if (*a!=NULL)
    23182031  {
    2319 #ifdef LDEBUG
    23202032    nlTest(*a);
    2321 #endif
    23222033    if ((SR_HDL(*a) & SR_INT)==0)
    23232034    {
     
    23332044LINLINE number nlNeg (number a)
    23342045{
    2335 #ifdef LDEBUG
    23362046  nlTest(a);
    2337 #endif
    23382047  if(SR_HDL(a) &SR_INT)
    23392048  {
    23402049    int r=SR_TO_INT(a);
    2341     if (r==(-(1<<28))) a=nlRInit(1<<28);
     2050    if (r==(-(POW_2_28))) a=nlRInit(POW_2_28);
    23422051    else               a=INT_TO_SR(-r);
    23432052    return a;
     
    23542063  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
    23552064  {
    2356     int r=SR_HDL(a)+SR_HDL(b)-1;
     2065    LONG r=SR_HDL(a)+SR_HDL(b)-1L;
    23572066    if ( ((r << 1) >> 1) == r )
    23582067      return (number)(long)r;
     
    23642073
    23652074number nlShort1(number a);
    2366 number nlShort3(number a);
     2075number nlShort3_noinline(number x);
    23672076
    23682077LINLINE number nlInpAdd (number a, number b, const ring r)
     
    23702079  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
    23712080  {
    2372     int r=SR_HDL(a)+SR_HDL(b)-1;
     2081    LONG r=SR_HDL(a)+SR_HDL(b)-1L;
    23732082    if ( ((r << 1) >> 1) == r )
    23742083      return (number)(long)r;
     
    24002109          mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
    24012110        a->s = 3;
    2402         a=nlShort3(a);
    2403         //nlNormalize(a);
     2111        a=nlShort3_noinline(a);
    24042112        break;
    24052113      }
     
    24392147        // result cannot be 0, if coeffs are normalized
    24402148        u->s = 3;
    2441         u=nlShort3(u);
     2149        u=nlShort3_noinline(u);
    24422150        break;
    24432151      }
    24442152    }
    2445     #ifdef LDEBUG
    24462153    nlTest(u);
    2447     #endif
    24482154    return u;
    24492155  }
     
    25082214            mpz_add(a->z,a->z,b->z);
    25092215            a->s = 3;
    2510             a=nlShort3(a);
     2216            a=nlShort3_noinline(a);
    25112217            break;
    25122218          }
     
    25152221      }
    25162222    }
    2517     #ifdef LDEBUG
    25182223    nlTest(a);
    2519     #endif
    25202224    return a;
    25212225  }
     
    25242228LINLINE number nlMult (number a, number b)
    25252229{
    2526 #ifdef LDEBUG
    25272230  nlTest(a);
    25282231  nlTest(b);
    2529 #endif
     2232
    25302233  if (a==INT_TO_SR(0)) return INT_TO_SR(0);
    25312234  if (b==INT_TO_SR(0)) return INT_TO_SR(0);
    25322235  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
    25332236  {
    2534     int r=(SR_HDL(a)-1)*(SR_HDL(b)>>1);
    2535     if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1))
     2237    LONG r=(SR_HDL(a)-1L)*(SR_HDL(b)>>1);
     2238    if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L))
    25362239    {
    25372240      number u=((number) ((r>>1)+SR_INT));
    2538       if (((SR_HDL(u)<<1)>>1)==SR_HDL(u)) return (u);
     2241      if (((((LONG)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u);
    25392242      return nlRInit(SR_HDL(u)>>2);
    25402243    }
     
    25522255  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
    25532256  {
    2554     int r=SR_HDL(a)-SR_HDL(b)+1;
     2257    LONG r=SR_HDL(a)-SR_HDL(b)+1;
    25552258    if ( ((r << 1) >> 1) == r )
    25562259    {
    2557       return (number)r;
     2260      return (number)(long)r;
    25582261    }
    25592262    else
     
    25782281  {
    25792282    mpz_gcd(a->z,a->z,b->z);
    2580     if (mpz_size1(a->z)<=MP_SMALL)
    2581     {
    2582       int ui=(int)mpz_get_si(a->z);
    2583       if ((((ui<<3)>>3)==ui)
    2584       && (mpz_cmp_si(a->z,(long)ui)==0))
    2585       {
    2586         mpz_clear(a->z);
    2587         omFreeBin((ADDRESS)a, rnumber_bin);
    2588         a=INT_TO_SR(ui);
    2589       }
    2590     }
     2283    a=nlShort3_noinline(a);
    25912284  }
    25922285}
     
    26262319    }
    26272320    MPZ_DIV(a->z,a->z,b->z);
    2628     if (mpz_size1(a->z)<=MP_SMALL)
    2629     {
    2630       int ui=(int)mpz_get_si(a->z);
    2631       if ((((ui<<3)>>3)==ui)
    2632       && (mpz_cmp_si(a->z,(long)ui)==0))
    2633       {
    2634         mpz_clear(a->z);
    2635         omFreeBin((ADDRESS)a, rnumber_bin);
    2636         a=INT_TO_SR(ui);
    2637       }
    2638     }
     2321    a=nlShort3_noinline(a);
    26392322  }
    26402323}
     
    27522435  if (mpz_size1(&r->z)<=MP_SMALL)
    27532436  {
    2754     int ui=(int)mpz_get_si(&r->z);
     2437    LONG ui=(int)mpz_get_si(&r->z);
    27552438    if ((((ui<<3)>>3)==ui)
    27562439    && (mpz_cmp_si(x->z,(long)ui)==0))
Note: See TracChangeset for help on using the changeset viewer.