/* * A pipeline similar to that of GRAPE-6. * * . it has higher accuracy and wider dynamic range than * that of GRAPE-5's. * * . it calculates jerk (time derivative of acceleration) * as well as acceleration. */ // configuration parameters parameter ARCH "GRAPE7M100"; parameter NPIPE 1; parameter JMEMSIZE 2048; parameter PREFIX "g6"; float34.23 mj jpin; int64 xj[3] jpin; int64 xi[3] ipin; float29.18 vj[3] jpin; float29.18 vi[3] ipin; float34.23 epsi2 ipin; int10 fshift (int)ipin; // direct the user library to handle them as vars of type 'int' int10 jshift (int)ipin; // (the library handles I/O ports as 'double' by default). int64 acc[3] fout; int32 jerk[3] fout; /* declarations of intermediate variables are recognized, but are not necessary in most cases. they can be used just for type checking purpose. intermediate variables are automatically created if no declaration found. float34.23 dx[3]; float34.23 r2, r5inv, r3inv, r1inv; float29.18 dv[3]; float29.18 s, j1[3], j1a[3], j1b[3], j2[3], j[3]; float29.18 mjr5inv; */ // force calculation dx = (float34.23)(xj - xi); r2 = dx * dx + epsi2; r5inv = (float34.23)pg_pow(r2, -5, 2, 9); r3inv = r5inv * r2; r1inv = r3inv * r2; acc += (int64)((mj * r3inv * dx) << fshift); // jerk calculation dv = (float29.18)(vj - vi); s = (dv * (float29.18)dx); mjr5inv = (float29.18)mj * (float29.18)r5inv; j1 = s * mjr5inv * (float29.18)dx; j1a = j1 << 1; j1b = j1 + j1a; // you can write 'j1b = j1 * 3' to do the same calculation, // but it would consume more hardware resource. mjr3inv = (float29.18)mj * (float29.18)r3inv; j2 = mjr3inv * dv; jerk += (int32)((j2 - j1b) << jshift);