32 #ifdef POK_NEEDS_LIBMATH
35 #include "math_private.h"
40 static const int init_jk[] = {4,7,9};
42 static const float PIo2[] = {
59 two8 = 2.5600000000e+02,
60 twon8 = 3.9062500000e-03;
63 __kernel_rem_pio2f(
float *x,
float *y,
int e0,
int nx,
int prec,
const int *ipio2)
65 int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
66 float z,fw,f[20],fq[20],q[20];
74 jv = (e0-3)/8;
if(jv<0) jv=0;
79 for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (float) ipio2[j];
83 for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
89 for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
90 fw = (float)((int32_t)(twon8* z));
91 iq[i] = (int32_t)(z-two8*fw);
97 z -= (float)8.0*floorf(z*(
float)0.125);
102 i = (iq[jz-1]>>(8-q0)); n += i;
103 iq[jz-1] -= i<<(8-q0);
104 ih = iq[jz-1]>>(7-q0);
106 else if(q0==0) ih = iq[jz-1]>>8;
107 else if(z>=(
float)0.5) ih=2;
115 carry = 1; iq[i] = 0x100- j;
117 }
else iq[i] = 0xff - j;
122 iq[jz-1] &= 0x7f;
break;
124 iq[jz-1] &= 0x3f;
break;
129 if(carry!=0) z -= scalbnf(one,q0);
136 for (i=jz-1;i>=jk;i--) j |= iq[i];
138 for(k=1;iq[jk-k]==0;k++);
140 for(i=jz+1;i<=jz+k;i++) {
141 f[jx+i] = (float) ipio2[jv+i];
142 for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
153 while(iq[jz]==0) { jz--; q0-=8;}
157 fw = (float)((int32_t)(twon8*z));
158 iq[jz] = (int32_t)(z-two8*fw);
160 iq[jz] = (int32_t) fw;
161 }
else iq[jz] = (int32_t) z ;
165 fw = scalbnf(one,q0);
167 q[i] = fw*(float)iq[i]; fw*=twon8;
172 for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
180 for (i=jz;i>=0;i--) fw += fq[i];
181 y[0] = (ih==0)? fw: -fw;
186 for (i=jz;i>=0;i--) fw += fq[i];
187 y[0] = (ih==0)? fw: -fw;
189 for (i=1;i<=jz;i++) fw += fq[i];
190 y[1] = (ih==0)? fw: -fw;
203 for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
205 y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
207 y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;