diff options
author | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-01-18 17:17:23 +0100 |
---|---|---|
committer | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-01-18 17:17:23 +0100 |
commit | a873e3fb7164db2be4641b244a63895dfc0660dd (patch) | |
tree | 2ab12813a5081d498aadb3e57b923c1fcac9485a /test/monniaux/mod_int_mat | |
parent | 2a1db308610355d66c6baff004702fd00816e25a (diff) | |
download | compcert-kvx-a873e3fb7164db2be4641b244a63895dfc0660dd.tar.gz compcert-kvx-a873e3fb7164db2be4641b244a63895dfc0660dd.zip |
loop transformation
Diffstat (limited to 'test/monniaux/mod_int_mat')
-rw-r--r-- | test/monniaux/mod_int_mat/int_mat.c | 33 | ||||
-rw-r--r-- | test/monniaux/mod_int_mat/int_mat_run.c | 14 | ||||
-rw-r--r-- | test/monniaux/mod_int_mat/modint.h | 5 |
3 files changed, 50 insertions, 2 deletions
diff --git a/test/monniaux/mod_int_mat/int_mat.c b/test/monniaux/mod_int_mat/int_mat.c index d3e14e26..58f968c1 100644 --- a/test/monniaux/mod_int_mat/int_mat.c +++ b/test/monniaux/mod_int_mat/int_mat.c @@ -109,6 +109,39 @@ void modint_mat_mul5(unsigned m, unsigned n, unsigned p, } } +void modint_mat_mul6(unsigned m, unsigned n, unsigned p, + modint * c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + const modint *pa_i = a; + modint * pc_i = c; + for(unsigned i=0; i<m; i++) { + for(unsigned k=0; k<p; k++) { + const modint *pb_j_k = b+k, *pa_i_j = pa_i; + modint total = 0; + unsigned j2=0, n2=n/2; + if (n2 > 0) { + do { + modint p0 = *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + modint p1 = *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += p0 + p1; + j2++; + } while (j2 < n2); + } + if (n%2) { + total += *pa_i_j * *pb_j_k; + } + pc_i[k] = total % MODULUS; + } + pa_i += stride_a; + pc_i += stride_c; + } +} + modint modint_random(void) { static uint64_t next = 1325997111; next = next * 1103515245 + 12345; diff --git a/test/monniaux/mod_int_mat/int_mat_run.c b/test/monniaux/mod_int_mat/int_mat_run.c index 9d5c0c57..20d564cc 100644 --- a/test/monniaux/mod_int_mat/int_mat_run.c +++ b/test/monniaux/mod_int_mat/int_mat_run.c @@ -64,24 +64,33 @@ int main() { modint_mat_mul5(m, n, p, c5, p, a, n, b, p); c5_time = get_cycle()-c5_time; + modint *c6 = malloc(sizeof(modint) * m * p); + cycle_t c6_time = get_cycle(); + modint_mat_mul6(m, n, p, c6, p, a, n, b, p); + c6_time = get_cycle()-c6_time; + printf("c1==c2: %s\n" "c1==c3: %s\n" "c1==c4: %s\n" "c1==c5: %s\n" + "c1==c6: %s\n" "c1_time = %" PRIu64 "\n" "c2_time = %" PRIu64 "\n" "c3_time = %" PRIu64 "\n" "c4_time = %" PRIu64 "\n" - "c5_time = %" PRIu64 "\n", + "c5_time = %" PRIu64 "\n" + "c6_time = %" PRIu64 "\n", modint_mat_equal(m, n, c1, p, c2, p)?"true":"false", modint_mat_equal(m, n, c1, p, c3, p)?"true":"false", modint_mat_equal(m, n, c1, p, c4, p)?"true":"false", modint_mat_equal(m, n, c1, p, c5, p)?"true":"false", + modint_mat_equal(m, n, c1, p, c6, p)?"true":"false", c1_time, c2_time, c3_time, c4_time, - c5_time); + c5_time, + c6_time); free(a); free(b); @@ -90,5 +99,6 @@ int main() { free(c3); free(c4); free(c5); + free(c6); return 0; } diff --git a/test/monniaux/mod_int_mat/modint.h b/test/monniaux/mod_int_mat/modint.h index 5295258b..92005455 100644 --- a/test/monniaux/mod_int_mat/modint.h +++ b/test/monniaux/mod_int_mat/modint.h @@ -29,6 +29,11 @@ void modint_mat_mul5(unsigned m, unsigned n, unsigned p, const modint *a, unsigned stride_a, const modint *b, unsigned stride_b); +void modint_mat_mul6(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + modint modint_random(void); void modint_mat_random(unsigned m, |