Print this page




  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 /*
  26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 #include <sys/isa_defs.h>

  31 
  32 #ifdef _LITTLE_ENDIAN
  33 #define HI(x)   *(1+(int*)x)
  34 #define LO(x)   *(unsigned*)x
  35 #else
  36 #define HI(x)   *(int*)x
  37 #define LO(x)   *(1+(unsigned*)x)
  38 #endif
  39 
  40 #ifdef __RESTRICT
  41 #define restrict _Restrict
  42 #else
  43 #define restrict
  44 #endif
  45 
  46 extern const double __vlibm_TBL_sincos_hi[], __vlibm_TBL_sincos_lo[];
  47 
  48 static const double
  49         half[2] = { 0.5, -0.5 },
  50         one             = 1.0,


  61                                 -4.999999999999931701464060878888294524481e-0001 },
  62         poly2[2]= {  8.333333332390951295683993455280336376663e-0003,
  63                                  4.166666666394861917535640593963708222319e-0002 },
  64         poly3[2]= { -1.984126237997976692791551778230098403960e-0004,
  65                                 -1.388888552656142867832756687736851681462e-0003 },
  66         poly4[2]= {  2.753403624854277237649987622848330351110e-0006,
  67                                  2.478519423681460796618128289454530524759e-0005 };
  68 
  69 static const unsigned thresh[2] = { 0x3fc90000, 0x3fc40000 };
  70 
  71 /* Don't __ the following; acomp will handle it */
  72 extern double fabs( double );
  73 extern void __vlibm_vsin_big( int, double *, int, double *, int, int );
  74 
  75 void
  76 __vsin( int n, double * restrict x, int stridex, double * restrict y,
  77         int stridey )
  78 {
  79         double          x0_or_one[4], x1_or_one[4], x2_or_one[4];
  80         double          y0_or_zero[4], y1_or_zero[4], y2_or_zero[4];
  81         double          x0, x1, x2, *py0, *py1, *py2, *xsave, *ysave;
  82         unsigned        hx0, hx1, hx2, xsb0, xsb1, xsb2;
  83         int                     i, biguns, nsave, sxsave, sysave;
  84 
  85         nsave = n;
  86         xsave = x;
  87         sxsave = stridex;
  88         ysave = y;
  89         sysave = stridey;
  90         biguns = 0;
  91 
  92         do
  93         {
  94 LOOP0:
  95                 xsb0 = HI(x);
  96                 hx0 = xsb0 & ~0x80000000;
  97                 if ( hx0 > 0x3fe921fb )
  98                 {
  99                         biguns = 1;
 100                         goto MEDIUM;
 101                 }
 102                 if ( hx0 < 0x3e400000 )
 103                 {
 104                         volatile int v = *x;
 105                         *y = *x;
 106                         x += stridex;
 107                         y += stridey;
 108                         i = 0;
 109                         if ( --n <= 0 )
 110                                 break;
 111                         goto LOOP0;
 112                 }
 113                 x0 = *x;
 114                 py0 = y;
 115                 x += stridex;
 116                 y += stridey;
 117                 i = 1;
 118                 if ( --n <= 0 )
 119                         break;
 120 
 121 LOOP1:
 122                 xsb1 = HI(x);
 123                 hx1 = xsb1 & ~0x80000000;
 124                 if ( hx1 > 0x3fe921fb )
 125                 {
 126                         biguns = 2;
 127                         goto MEDIUM;
 128                 }
 129                 if ( hx1 < 0x3e400000 )
 130                 {
 131                         volatile int v = *x;
 132                         *y = *x;
 133                         x += stridex;
 134                         y += stridey;
 135                         i = 1;
 136                         if ( --n <= 0 )
 137                                 break;
 138                         goto LOOP1;
 139                 }
 140                 x1 = *x;
 141                 py1 = y;
 142                 x += stridex;
 143                 y += stridey;
 144                 i = 2;
 145                 if ( --n <= 0 )
 146                         break;
 147 
 148 LOOP2:
 149                 xsb2 = HI(x);
 150                 hx2 = xsb2 & ~0x80000000;
 151                 if ( hx2 > 0x3fe921fb )
 152                 {
 153                         biguns = 3;
 154                         goto MEDIUM;
 155                 }
 156                 if ( hx2 < 0x3e400000 )
 157                 {
 158                         volatile int v = *x;
 159                         *y = *x;
 160                         x += stridex;
 161                         y += stridey;
 162                         i = 2;
 163                         if ( --n <= 0 )
 164                                 break;
 165                         goto LOOP2;
 166                 }
 167                 x2 = *x;
 168                 py2 = y;
 169 
 170                 i = ( hx0 - 0x3fc90000 ) >> 31;
 171                 i |= ( ( hx1 - 0x3fc90000 ) >> 30 ) & 2;
 172                 i |= ( ( hx2 - 0x3fc90000 ) >> 29 ) & 4;
 173                 switch ( i )
 174                 {
 175                         double          a0, a1, a2, w0, w1, w2;
 176                         double          t0, t1, t2, z0, z1, z2;
 177                         unsigned        j0, j1, j2;
 178 


 501         else if ( biguns == 2 ) 
 502         {
 503                 xsb0 = xsb0 >> 31;
 504                 biguns = 0;
 505                 goto loop1;
 506         }
 507         biguns = 0;
 508 
 509         do
 510         {
 511                 double          fn0, fn1, fn2, a0, a1, a2, w0, w1, w2, y0, y1, y2;
 512                 unsigned        hx;
 513                 int                     n0, n1, n2;
 514 
 515 loop0:
 516                 hx = HI(x);
 517                 xsb0 = hx >> 31;
 518                 hx &= ~0x80000000;
 519                 if ( hx < 0x3e400000 )
 520                 {
 521                         volatile int v = *x;
 522                         *y = *x;
 523                         x += stridex;
 524                         y += stridey;
 525                         i = 0;
 526                         if ( --n <= 0 )
 527                                 break;
 528                         goto loop0;
 529                 }
 530                 if ( hx > 0x413921fb )
 531                 {
 532                         if ( hx >= 0x7ff00000 )
 533                         {
 534                                 x0 = *x;
 535                                 *y = x0 - x0;
 536                         }
 537                         else
 538                                 biguns = 1;
 539                         x += stridex;
 540                         y += stridey;
 541                         i = 0;
 542                         if ( --n <= 0 )
 543                                 break;
 544                         goto loop0;
 545                 }
 546                 x0 = *x;
 547                 py0 = y;
 548                 x += stridex;
 549                 y += stridey;
 550                 i = 1;
 551                 if ( --n <= 0 )
 552                         break;
 553 
 554 loop1:
 555                 hx = HI(x);
 556                 xsb1 = hx >> 31;
 557                 hx &= ~0x80000000;
 558                 if ( hx < 0x3e400000 )
 559                 {
 560                         volatile int v = *x;
 561                         *y = *x;
 562                         x += stridex;
 563                         y += stridey;
 564                         i = 1;
 565                         if ( --n <= 0 )
 566                                 break;
 567                         goto loop1;
 568                 }
 569                 if ( hx > 0x413921fb )
 570                 {
 571                         if ( hx >= 0x7ff00000 )
 572                         {
 573                                 x1 = *x;
 574                                 *y = x1 - x1;
 575                         }
 576                         else
 577                                 biguns = 1;
 578                         x += stridex;
 579                         y += stridey;
 580                         i = 1;
 581                         if ( --n <= 0 )
 582                                 break;
 583                         goto loop1;
 584                 }
 585                 x1 = *x;
 586                 py1 = y;
 587                 x += stridex;
 588                 y += stridey;
 589                 i = 2;
 590                 if ( --n <= 0 )
 591                         break;
 592 
 593 loop2:
 594                 hx = HI(x);
 595                 xsb2 = hx >> 31;
 596                 hx &= ~0x80000000;
 597                 if ( hx < 0x3e400000 )
 598                 {
 599                         volatile int v = *x;
 600                         *y = *x;
 601                         x += stridex;
 602                         y += stridey;
 603                         i = 2;
 604                         if ( --n <= 0 )
 605                                 break;
 606                         goto loop2;
 607                 }
 608                 if ( hx > 0x413921fb )
 609                 {
 610                         if ( hx >= 0x7ff00000 )
 611                         {
 612                                 x2 = *x;
 613                                 *y = x2 - x2;
 614                         }
 615                         else
 616                                 biguns = 1;
 617                         x += stridex;
 618                         y += stridey;
 619                         i = 2;




  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 /*
  26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 #include <sys/isa_defs.h>
  31 #include <sys/ccompile.h>
  32 
  33 #ifdef _LITTLE_ENDIAN
  34 #define HI(x)   *(1+(int*)x)
  35 #define LO(x)   *(unsigned*)x
  36 #else
  37 #define HI(x)   *(int*)x
  38 #define LO(x)   *(1+(unsigned*)x)
  39 #endif
  40 
  41 #ifdef __RESTRICT
  42 #define restrict _Restrict
  43 #else
  44 #define restrict
  45 #endif
  46 
  47 extern const double __vlibm_TBL_sincos_hi[], __vlibm_TBL_sincos_lo[];
  48 
  49 static const double
  50         half[2] = { 0.5, -0.5 },
  51         one             = 1.0,


  62                                 -4.999999999999931701464060878888294524481e-0001 },
  63         poly2[2]= {  8.333333332390951295683993455280336376663e-0003,
  64                                  4.166666666394861917535640593963708222319e-0002 },
  65         poly3[2]= { -1.984126237997976692791551778230098403960e-0004,
  66                                 -1.388888552656142867832756687736851681462e-0003 },
  67         poly4[2]= {  2.753403624854277237649987622848330351110e-0006,
  68                                  2.478519423681460796618128289454530524759e-0005 };
  69 
  70 static const unsigned thresh[2] = { 0x3fc90000, 0x3fc40000 };
  71 
  72 /* Don't __ the following; acomp will handle it */
  73 extern double fabs( double );
  74 extern void __vlibm_vsin_big( int, double *, int, double *, int, int );
  75 
  76 void
  77 __vsin( int n, double * restrict x, int stridex, double * restrict y,
  78         int stridey )
  79 {
  80         double          x0_or_one[4], x1_or_one[4], x2_or_one[4];
  81         double          y0_or_zero[4], y1_or_zero[4], y2_or_zero[4];
  82         double          x0, x1, x2, *py0 = 0, *py1 = 0, *py2, *xsave, *ysave;
  83         unsigned        hx0, hx1, hx2, xsb0, xsb1 = 0, xsb2;
  84         int             i, biguns, nsave, sxsave, sysave;

  85         nsave = n;
  86         xsave = x;
  87         sxsave = stridex;
  88         ysave = y;
  89         sysave = stridey;
  90         biguns = 0;
  91 
  92         do
  93         {
  94 LOOP0:
  95                 xsb0 = HI(x);
  96                 hx0 = xsb0 & ~0x80000000;
  97                 if ( hx0 > 0x3fe921fb )
  98                 {
  99                         biguns = 1;
 100                         goto MEDIUM;
 101                 }
 102                 if ( hx0 < 0x3e400000 )
 103                 {

 104                         *y = *x;
 105                         x += stridex;
 106                         y += stridey;
 107                         i = 0;
 108                         if ( --n <= 0 )
 109                                 break;
 110                         goto LOOP0;
 111                 }
 112                 x0 = *x;
 113                 py0 = y;
 114                 x += stridex;
 115                 y += stridey;
 116                 i = 1;
 117                 if ( --n <= 0 )
 118                         break;
 119 
 120 LOOP1:
 121                 xsb1 = HI(x);
 122                 hx1 = xsb1 & ~0x80000000;
 123                 if ( hx1 > 0x3fe921fb )
 124                 {
 125                         biguns = 2;
 126                         goto MEDIUM;
 127                 }
 128                 if ( hx1 < 0x3e400000 )
 129                 {

 130                         *y = *x;
 131                         x += stridex;
 132                         y += stridey;
 133                         i = 1;
 134                         if ( --n <= 0 )
 135                                 break;
 136                         goto LOOP1;
 137                 }
 138                 x1 = *x;
 139                 py1 = y;
 140                 x += stridex;
 141                 y += stridey;
 142                 i = 2;
 143                 if ( --n <= 0 )
 144                         break;
 145 
 146 LOOP2:
 147                 xsb2 = HI(x);
 148                 hx2 = xsb2 & ~0x80000000;
 149                 if ( hx2 > 0x3fe921fb )
 150                 {
 151                         biguns = 3;
 152                         goto MEDIUM;
 153                 }
 154                 if ( hx2 < 0x3e400000 )
 155                 {

 156                         *y = *x;
 157                         x += stridex;
 158                         y += stridey;
 159                         i = 2;
 160                         if ( --n <= 0 )
 161                                 break;
 162                         goto LOOP2;
 163                 }
 164                 x2 = *x;
 165                 py2 = y;
 166 
 167                 i = ( hx0 - 0x3fc90000 ) >> 31;
 168                 i |= ( ( hx1 - 0x3fc90000 ) >> 30 ) & 2;
 169                 i |= ( ( hx2 - 0x3fc90000 ) >> 29 ) & 4;
 170                 switch ( i )
 171                 {
 172                         double          a0, a1, a2, w0, w1, w2;
 173                         double          t0, t1, t2, z0, z1, z2;
 174                         unsigned        j0, j1, j2;
 175 


 498         else if ( biguns == 2 ) 
 499         {
 500                 xsb0 = xsb0 >> 31;
 501                 biguns = 0;
 502                 goto loop1;
 503         }
 504         biguns = 0;
 505 
 506         do
 507         {
 508                 double          fn0, fn1, fn2, a0, a1, a2, w0, w1, w2, y0, y1, y2;
 509                 unsigned        hx;
 510                 int             n0, n1, n2;
 511 
 512 loop0:
 513                 hx = HI(x);
 514                 xsb0 = hx >> 31;
 515                 hx &= ~0x80000000;
 516                 if ( hx < 0x3e400000 )
 517                 {

 518                         *y = *x;
 519                         x += stridex;
 520                         y += stridey;
 521                         i = 0;
 522                         if ( --n <= 0 )
 523                                 break;
 524                         goto loop0;
 525                 }
 526                 if ( hx > 0x413921fb )
 527                 {
 528                         if ( hx >= 0x7ff00000 )
 529                         {
 530                                 x0 = *x;
 531                                 *y = x0 - x0;
 532                         }
 533                         else
 534                                 biguns = 1;
 535                         x += stridex;
 536                         y += stridey;
 537                         i = 0;
 538                         if ( --n <= 0 )
 539                                 break;
 540                         goto loop0;
 541                 }
 542                 x0 = *x;
 543                 py0 = y;
 544                 x += stridex;
 545                 y += stridey;
 546                 i = 1;
 547                 if ( --n <= 0 )
 548                         break;
 549 
 550 loop1:
 551                 hx = HI(x);
 552                 xsb1 = hx >> 31;
 553                 hx &= ~0x80000000;
 554                 if ( hx < 0x3e400000 )
 555                 {

 556                         *y = *x;
 557                         x += stridex;
 558                         y += stridey;
 559                         i = 1;
 560                         if ( --n <= 0 )
 561                                 break;
 562                         goto loop1;
 563                 }
 564                 if ( hx > 0x413921fb )
 565                 {
 566                         if ( hx >= 0x7ff00000 )
 567                         {
 568                                 x1 = *x;
 569                                 *y = x1 - x1;
 570                         }
 571                         else
 572                                 biguns = 1;
 573                         x += stridex;
 574                         y += stridey;
 575                         i = 1;
 576                         if ( --n <= 0 )
 577                                 break;
 578                         goto loop1;
 579                 }
 580                 x1 = *x;
 581                 py1 = y;
 582                 x += stridex;
 583                 y += stridey;
 584                 i = 2;
 585                 if ( --n <= 0 )
 586                         break;
 587 
 588 loop2:
 589                 hx = HI(x);
 590                 xsb2 = hx >> 31;
 591                 hx &= ~0x80000000;
 592                 if ( hx < 0x3e400000 )
 593                 {

 594                         *y = *x;
 595                         x += stridex;
 596                         y += stridey;
 597                         i = 2;
 598                         if ( --n <= 0 )
 599                                 break;
 600                         goto loop2;
 601                 }
 602                 if ( hx > 0x413921fb )
 603                 {
 604                         if ( hx >= 0x7ff00000 )
 605                         {
 606                                 x2 = *x;
 607                                 *y = x2 - x2;
 608                         }
 609                         else
 610                                 biguns = 1;
 611                         x += stridex;
 612                         y += stridey;
 613                         i = 2;