Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Array {
- double * restrict data;
- long n;
- };
- #define X 0
- #define Y 1
- #define Z 2
- void __attribute__((noinline))
- func1(double * restrict d, double * restrict out, const long n)
- {
- for (long i = 0; i < n; ++ i) {
- for (long j = i + 1; j < n; ++ j) {
- const double rx = d[i * 3 + 0] * d[j * 3 + 0];
- const double ry = d[i * 3 + 1] * d[j * 3 + 1];
- const double rz = d[i * 3 + 2] * d[j * 3 + 2];
- out[i * 3 + X] += rx;
- out[i * 3 + Y] += ry;
- out[i * 3 + Z] += rz;
- out[j * 3 + X] -= rx;
- out[j * 3 + Y] -= ry;
- out[j * 3 + Z] -= rz;
- }
- }
- }
- void __attribute__((noinline))
- func2(struct Array * restrict d, struct Array * restrict out, const long n)
- {
- for (long i = 0; i < n; ++ i) {
- for (long j = i + 1; j < n; ++ j) {
- const double rx = d->data[i * 3 + X] * d->data[j * 3 + X];
- const double ry = d->data[i * 3 + Y] * d->data[j * 3 + Y];
- const double rz = d->data[i * 3 + Z] * d->data[j * 3 + Z];
- out->data[i * 3 + X] += rx;
- out->data[i * 3 + Y] += ry;
- out->data[i * 3 + Z] += rz;
- out->data[j * 3 + X] -= rx;
- out->data[j * 3 + Y] -= ry;
- out->data[j * 3 + Z] -= rz;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement