Page 285 - ARM 64 Bit Assembly Language
P. 285

274 Chapter 8


                44  int i=0;
                45  sum = (long long)x << 31;   // initialize 64-bit sum to x
                46  xsq = (long long)x*(long long)x; // calculate x^2 as an S(3,60)
                47  xsq >>= 31;                 // convert x^2 to an S(2,29)
                48  do
                49    {
                50      // calculate x^(2n-1) as an S(3,28)
                51      curpower = ((curpower * xsq) >> 31);
                52      // multiply x^(2n-1) by coefficient from the table
                53      tmp = curpower * sintab[i].coeff;
                54      if(tmp < 0) // if resulting term in negative
                55        tmp++;    //  add one to avoid round-off error
                56      tmp >>= sintab[i].shift; // convert the term to S(2,61)
                57      sum += tmp; // add it to running total
                58    }
                59  while(++i<TABSIZE);
                60  return (sum >> 33);  // convert result to S(3,28) and return
                61  }
                62
                63  //*************************************************************
                64  // fixed_sin_C applies symmetries to reduce the range of
                65  // the input, then calls sinq and adjusts the result.
                66  int fixed_sin_C(int x)
                67  {
                68  while(x<0)
                69    x += pi_x2;
                70  while(x>pi_x2)
                71    x -= pi_x2;
                72  if(x<=pi_2)
                73    return sinq(x<<2);
                74  if(x<=pi)
                75    return sinq((pi-x)<<2);
                76  if(x<=(pi+pi_2))
                77    return -sinq((x-pi)<<2);
                78  return  -sinq((pi_x2 -x)<<2);
                79  }
                80
                81  //*************************************************************
                82  // fixed_cos_C applies the sin/cos relation to
                83  // the input, then calls fixed_sin_C
                84  int fixed_cos_C(int x)
                85  {
                86  if(x<=0)
                87    x += pi_x2;
                88  x = pi_2 - x;
                89  return fixed_sin_C(x);
                90  }
   280   281   282   283   284   285   286   287   288   289   290