Changeset 65c5f5 in git for libpolys


Ignore:
Timestamp:
Feb 8, 2012, 4:29:10 PM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
237b4dda7a8a6ccfcc5966b92c779cebeebc30cc
Parents:
cc3240c506fdb572293019718b6e949f582d6108
Message:
chg: make the simple part of nlInpAdd an inline routine, hide the rest
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/longrat.cc

    rcc3240c r65c5f5  
    16551655}
    16561656
     1657void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b)
     1658{
     1659  if (SR_HDL(b) & SR_INT)
     1660  {
     1661    switch (a->s)
     1662    {
     1663      case 0:
     1664      case 1:/* b:short, a:1 */
     1665      {
     1666        mpz_t x;
     1667        mpz_init(x);
     1668        mpz_mul_si(x,a->n,SR_TO_INT(b));
     1669        mpz_add(a->z,a->z,x);
     1670        mpz_clear(x);
     1671        a->s = 0;
     1672        a=nlShort1(a);
     1673        break;
     1674      }
     1675      case 3:
     1676      {
     1677        if ((long)b>0L)
     1678          mpz_add_ui(a->z,a->z,SR_TO_INT(b));
     1679        else
     1680          mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
     1681        a->s = 3;
     1682        a=nlShort3_noinline(a);
     1683        break;
     1684      }
     1685    }
     1686    return;
     1687  }
     1688  else if (SR_HDL(a) & SR_INT)
     1689  {
     1690    number u=ALLOC_RNUMBER();
     1691    #if defined(LDEBUG)
     1692    u->debug=123456;
     1693    #endif
     1694    mpz_init(u->z);
     1695    switch (b->s)
     1696    {
     1697      case 0:
     1698      case 1:/* a:short, b:1 */
     1699      {
     1700        mpz_t x;
     1701        mpz_init(x);
     1702
     1703        mpz_mul_si(x,b->n,SR_TO_INT(a));
     1704        mpz_add(u->z,b->z,x);
     1705        mpz_clear(x);
     1706        // result cannot be 0, if coeffs are normalized
     1707        mpz_init_set(u->n,b->n);
     1708        u->s = 0;
     1709        u=nlShort1(u);
     1710        break;
     1711      }
     1712      case 3:
     1713      {
     1714        if ((long)a>0L)
     1715          mpz_add_ui(u->z,b->z,SR_TO_INT(a));
     1716        else
     1717          mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
     1718        // result cannot be 0, if coeffs are normalized
     1719        u->s = 3;
     1720        u=nlShort3_noinline(u);
     1721        break;
     1722      }
     1723    }
     1724    a=u;
     1725  }
     1726  else
     1727  {
     1728    switch (a->s)
     1729    {
     1730      case 0:
     1731      case 1:
     1732      {
     1733        switch(b->s)
     1734        {
     1735          case 0:
     1736          case 1: /* a:1 b:1 */
     1737          {
     1738            mpz_t x;
     1739            mpz_t y;
     1740            mpz_init(x);
     1741            mpz_init(y);
     1742            mpz_mul(x,b->z,a->n);
     1743            mpz_mul(y,a->z,b->n);
     1744            mpz_add(a->z,x,y);
     1745            mpz_clear(x);
     1746            mpz_clear(y);
     1747            mpz_mul(a->n,a->n,b->n);
     1748            a->s = 0;
     1749            break;
     1750          }
     1751          case 3: /* a:1 b:3 */
     1752          {
     1753            mpz_t x;
     1754            mpz_init(x);
     1755            mpz_mul(x,b->z,a->n);
     1756            mpz_add(a->z,a->z,x);
     1757            mpz_clear(x);
     1758            a->s = 0;
     1759            break;
     1760          }
     1761        } /*switch (b->s) */
     1762        a=nlShort1(a);
     1763        break;
     1764      }
     1765      case 3:
     1766      {
     1767        switch(b->s)
     1768        {
     1769          case 0:
     1770          case 1:/* a:3, b:1 */
     1771          {
     1772            mpz_t x;
     1773            mpz_init(x);
     1774            mpz_mul(x,a->z,b->n);
     1775            mpz_add(a->z,b->z,x);
     1776            mpz_clear(x);
     1777            mpz_init_set(a->n,b->n);
     1778            a->s = 0;
     1779            a=nlShort1(a);
     1780            break;
     1781          }
     1782          case 3:
     1783          {
     1784            mpz_add(a->z,a->z,b->z);
     1785            a->s = 3;
     1786            a=nlShort3_noinline(a);
     1787            break;
     1788          }
     1789        }
     1790        break;
     1791      }
     1792    }
     1793  }
     1794}
     1795
    16571796number _nlSub_aNoImm_OR_bNoImm(number a, number b)
    16581797{
     
    20922231number  _nlNeg_NoImm(number a);
    20932232number  _nlAdd_aNoImm_OR_bNoImm(number a, number b);
     2233void    _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b);
    20942234number  _nlSub_aNoImm_OR_bNoImm(number a, number b);
    20952235number  _nlMult_aNoImm_OR_bNoImm(number a, number b);
     
    22292369LINLINE void nlInpAdd(number &a, number b, const coeffs r)
    22302370{
     2371  // a=a+b
    22312372  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
    22322373  {
     
    22372378      a=nlRInit(SR_TO_INT(r));
    22382379  }
    2239   // a=a+b
    2240   else if (SR_HDL(b) & SR_INT)
    2241   {
    2242     switch (a->s)
    2243     {
    2244       case 0:
    2245       case 1:/* b:short, a:1 */
    2246       {
    2247         mpz_t x;
    2248         mpz_init(x);
    2249         mpz_mul_si(x,a->n,SR_TO_INT(b));
    2250         mpz_add(a->z,a->z,x);
    2251         mpz_clear(x);
    2252         a->s = 0;
    2253         a=nlShort1(a);
    2254         break;
    2255       }
    2256       case 3:
    2257       {
    2258         if ((long)b>0L)
    2259           mpz_add_ui(a->z,a->z,SR_TO_INT(b));
    2260         else
    2261           mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
    2262         a->s = 3;
    2263         a=nlShort3_noinline(a);
    2264         break;
    2265       }
    2266     }
    2267     return;
    2268   }
    2269   else if (SR_HDL(a) & SR_INT)
    2270   {
    2271     number u=ALLOC_RNUMBER();
    2272     #if defined(LDEBUG)
    2273     u->debug=123456;
    2274     #endif
    2275     mpz_init(u->z);
    2276     switch (b->s)
    2277     {
    2278       case 0:
    2279       case 1:/* a:short, b:1 */
    2280       {
    2281         mpz_t x;
    2282         mpz_init(x);
    2283 
    2284         mpz_mul_si(x,b->n,SR_TO_INT(a));
    2285         mpz_add(u->z,b->z,x);
    2286         mpz_clear(x);
    2287         // result cannot be 0, if coeffs are normalized
    2288         mpz_init_set(u->n,b->n);
    2289         u->s = 0;
    2290         u=nlShort1(u);
    2291         break;
    2292       }
    2293       case 3:
    2294       {
    2295         if ((long)a>0L)
    2296           mpz_add_ui(u->z,b->z,SR_TO_INT(a));
    2297         else
    2298           mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
    2299         // result cannot be 0, if coeffs are normalized
    2300         u->s = 3;
    2301         u=nlShort3_noinline(u);
    2302         break;
    2303       }
    2304     }
    2305     nlTest(u, r);
    2306     a=u;
    2307   }
    23082380  else
    23092381  {
    2310     switch (a->s)
    2311     {
    2312       case 0:
    2313       case 1:
    2314       {
    2315         switch(b->s)
    2316         {
    2317           case 0:
    2318           case 1: /* a:1 b:1 */
    2319           {
    2320             mpz_t x;
    2321             mpz_t y;
    2322             mpz_init(x);
    2323             mpz_init(y);
    2324             mpz_mul(x,b->z,a->n);
    2325             mpz_mul(y,a->z,b->n);
    2326             mpz_add(a->z,x,y);
    2327             mpz_clear(x);
    2328             mpz_clear(y);
    2329             mpz_mul(a->n,a->n,b->n);
    2330             a->s = 0;
    2331             break;
    2332           }
    2333           case 3: /* a:1 b:3 */
    2334           {
    2335             mpz_t x;
    2336             mpz_init(x);
    2337             mpz_mul(x,b->z,a->n);
    2338             mpz_add(a->z,a->z,x);
    2339             mpz_clear(x);
    2340             a->s = 0;
    2341             break;
    2342           }
    2343         } /*switch (b->s) */
    2344         a=nlShort1(a);
    2345         break;
    2346       }
    2347       case 3:
    2348       {
    2349         switch(b->s)
    2350         {
    2351           case 0:
    2352           case 1:/* a:3, b:1 */
    2353           {
    2354             mpz_t x;
    2355             mpz_init(x);
    2356             mpz_mul(x,a->z,b->n);
    2357             mpz_add(a->z,b->z,x);
    2358             mpz_clear(x);
    2359             mpz_init_set(a->n,b->n);
    2360             a->s = 0;
    2361             a=nlShort1(a);
    2362             break;
    2363           }
    2364           case 3:
    2365           {
    2366             mpz_add(a->z,a->z,b->z);
    2367             a->s = 3;
    2368             a=nlShort3_noinline(a);
    2369             break;
    2370           }
    2371         }
    2372         break;
    2373       }
    2374     }
    2375   }
    2376   nlTest(a, r);
     2382    _nlInpAdd_aNoImm_OR_bNoImm(a,b);
     2383    nlTest(a,r);
     2384  }
    23772385}
    23782386
Note: See TracChangeset for help on using the changeset viewer.