Changeset b45ae02 in git


Ignore:
Timestamp:
Oct 12, 2018, 3:07:52 PM (6 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
c5079ecb99f453ef9b68c8f71391a4d24e9f9122ccc4a179b32a4db6b33e8a45864fd61e8e78aaad
Parents:
a6ea1d3a85e5c6294a5867c84399d54d8f5651ae
Message:
opt: letterpace: move alloc/free out of inner loops
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/shiftop.cc

    ra6ea1d rb45ae02  
    1212 * -> wait until the new interface is released
    1313*/
    14 #define SHIFT_MULT_COMPAT_MODE 
     14#define SHIFT_MULT_COMPAT_MODE
    1515
    1616#ifdef SHIFT_MULT_DEBUG
     
    5555  p_GetExpV(_m,mExpV,ri);
    5656  int mLength = p_mLastVblock(_m, mExpV, ri) * lV;
     57  int *pExpV = (int *) omAlloc((ri->N+1)*sizeof(int));
    5758  do
    5859  {
     60    memset(pExpV,0,(ri->N+1)*sizeof(int));
    5961    p_AllocBin(pNext(q), bin, ri);
    6062    pIter(q);
    6163    pSetCoeff0(q, n_Mult(mCoeff, pGetCoeff(p), ri->cf));
    6264
    63     int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int));
    6465    p_GetExpV(p, pExpV, ri);
    6566    p_LPExpVappend(pExpV, mExpV, p_mLastVblock(p, pExpV, ri) * lV, mLength, ri);
    6667    p_MemCopy_LengthGeneral(q->exp, p->exp, ri->ExpL_Size); // otherwise q is not initialized correctly
    6768    p_SetExpV(q, pExpV, ri);
    68     omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    6969
    7070    pIter(p);
    7171  }
    7272  while (p != NULL);
     73  omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    7374  omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int));
    7475  pNext(q) = NULL;
     
    116117  p_GetExpV(_m,mExpV,ri);
    117118  int mLength = p_mLastVblock(_m, mExpV, ri) * lV;
     119  int *pExpV = (int *) omAlloc((ri->N+1)*sizeof(int));
    118120  while (p != NULL)
    119121  {
     122    memset(pExpV,0,(ri->N+1)*sizeof(int));
    120123    pCoeff = pGetCoeff(p);
    121124    pSetCoeff0(p, n_Mult(mCoeff, pCoeff, ri->cf));
    122125    n_Delete(&pCoeff, ri->cf); // delete the old coeff
    123126
    124     int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int));
    125127    p_GetExpV(p,pExpV,ri);
    126128    p_LPExpVappend(pExpV, mExpV, p_mLastVblock(p, pExpV, ri) * lV, mLength, ri);
    127129    p_SetExpV(p, pExpV, ri);
    128     omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    129130
    130131    pIter(p);
    131132  }
     133  omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    132134  omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int));
    133135#ifdef SHIFT_MULT_COMPAT_MODE
     
    178180  p_GetExpV(_m,mExpV,ri);
    179181  int mLength = p_mLastVblock(_m, mExpV, ri) * lV;
     182  int *pExpV = (int *) omAlloc((ri->N+1)*sizeof(int));
    180183  do
    181184  {
     185    memset(pExpV,0,(ri->N+1)*sizeof(int));
    182186    p_AllocBin(pNext(q), bin, ri);
    183187    pIter(q);
    184188    pSetCoeff0(q, n_Mult(mCoeff, pGetCoeff(p), ri->cf));
    185189
    186     int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int));
    187190    p_GetExpV(p, pExpV, ri);
    188191    p_LPExpVprepend(pExpV, mExpV, p_mLastVblock(p, pExpV, ri) * lV, mLength, ri);
    189192    p_MemCopy_LengthGeneral(q->exp, p->exp, ri->ExpL_Size); // otherwise q is not initialized correctly
    190193    p_SetExpV(q, pExpV, ri);
    191     omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    192194
    193195    pIter(p);
    194196  }
    195197  while (p != NULL);
     198  omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    196199  omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int));
    197200  pNext(q) = NULL;
     
    239242  p_GetExpV(_m,mExpV,ri);
    240243  int mLength = p_mLastVblock(_m, mExpV, ri) * lV;
     244  int *pExpV = (int *) omAlloc((ri->N+1)*sizeof(int));
    241245  while (p != NULL)
    242246  {
     247    memset(pExpV,0,(ri->N+1)*sizeof(int));
    243248    pCoeff = pGetCoeff(p);
    244249    pSetCoeff0(p, n_Mult(mCoeff, pCoeff, ri->cf));
    245250    n_Delete(&pCoeff, ri->cf); // delete the old coeff
    246251
    247     int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int));
    248252    p_GetExpV(p,pExpV,ri);
    249253    p_LPExpVprepend(pExpV, mExpV, p_mLastVblock(p, pExpV, ri) * lV, mLength, ri);
    250254    p_SetExpV(p, pExpV, ri);
    251     omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    252255
    253256    pIter(p);
    254257  }
     258  omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int));
    255259  omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int));
    256260#ifdef SHIFT_MULT_COMPAT_MODE
     
    286290
    287291  int pLen = 0;
    288   if (ll >= 0) {
     292  if (ll >= 0)
     293  {
    289294    pLen = pLength(p);
    290295  }
     
    292297  p = shift_pp_Mult_mm(p, m, ri);
    293298
    294   if (ll >= 0) {
     299  if (ll >= 0)
     300  {
    295301    ll = pLen - pLength(p);
    296   } else {
     302  }
     303  else
     304  {
    297305    ll = pLength(p);
    298306  }
     
    516524
    517525// prepends m2ExpV to m1ExpV, also adds their components (one of them is always zero)
    518 void p_LPExpVprepend(int *m1ExpV, int *m2ExpV, int m1Length, int m2Length, const ring ri) {
     526void p_LPExpVprepend(int *m1ExpV, int *m2ExpV, int m1Length, int m2Length, const ring ri)
     527{
    519528#ifdef SHIFT_MULT_DEBUG
    520529  PrintLn(); PrintS("Prepend");
     
    544553}
    545554
    546 void WriteLPExpV(int *expV, ring ri) {
    547   for (int i = 0; i <= ri->N; ++i) {
     555void WriteLPExpV(int *expV, ring ri)
     556{
     557  for (int i = 0; i <= ri->N; ++i)
     558  {
    548559    Print("%d", expV[i]);
    549     if (i == 0) {
     560    if (i == 0)
     561    {
    550562      Print("| ");
    551563    }
    552     if (i % ri->isLPring == 0) {
     564    if (i % ri->isLPring == 0)
     565    {
    553566      Print(" ");
    554567    }
Note: See TracChangeset for help on using the changeset viewer.