diff options
-rw-r--r-- | test/monniaux/mod_int_mat/int_mat.c | 53 | ||||
-rw-r--r-- | test/monniaux/mod_int_mat/int_mat_run.c | 15 | ||||
-rw-r--r-- | test/monniaux/mod_int_mat/modint.h | 5 |
3 files changed, 68 insertions, 5 deletions
diff --git a/test/monniaux/mod_int_mat/int_mat.c b/test/monniaux/mod_int_mat/int_mat.c index 58f968c1..0e51d7ba 100644 --- a/test/monniaux/mod_int_mat/int_mat.c +++ b/test/monniaux/mod_int_mat/int_mat.c @@ -122,13 +122,12 @@ void modint_mat_mul6(unsigned m, unsigned n, unsigned p, unsigned j2=0, n2=n/2; if (n2 > 0) { do { - modint p0 = *pa_i_j * *pb_j_k; + total += *pa_i_j * *pb_j_k; pa_i_j ++; pb_j_k += stride_b; - modint p1 = *pa_i_j * *pb_j_k; + total += *pa_i_j * *pb_j_k; pa_i_j ++; pb_j_k += stride_b; - total += p0 + p1; j2++; } while (j2 < n2); } @@ -142,6 +141,54 @@ void modint_mat_mul6(unsigned m, unsigned n, unsigned p, } } +void modint_mat_mul7(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 j4=0, n4=n/4; + if (n4 > 0) { + do { + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + j4++; + } while (j4 < n4); + } + } + { + unsigned j4=0, n4=n%4; + if (n4 > 0) { + do { + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + j4++; + } while (j4 < n4); + } + } + 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 20d564cc..42cb54fb 100644 --- a/test/monniaux/mod_int_mat/int_mat_run.c +++ b/test/monniaux/mod_int_mat/int_mat_run.c @@ -69,28 +69,39 @@ int main() { modint_mat_mul6(m, n, p, c6, p, a, n, b, p); c6_time = get_cycle()-c6_time; + modint *c7 = malloc(sizeof(modint) * m * p); + cycle_t c7_time = get_cycle(); + modint_mat_mul7(m, n, p, c7, p, a, n, b, p); + c7_time = get_cycle()-c7_time; + printf("c1==c2: %s\n" "c1==c3: %s\n" "c1==c4: %s\n" "c1==c5: %s\n" "c1==c6: %s\n" + "c1==c7: %s\n" "c1_time = %" PRIu64 "\n" "c2_time = %" PRIu64 "\n" "c3_time = %" PRIu64 "\n" "c4_time = %" PRIu64 "\n" "c5_time = %" PRIu64 "\n" - "c6_time = %" PRIu64 "\n", + "c6_time = %" PRIu64 "\n" + "c7_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", + modint_mat_equal(m, n, c1, p, c7, p)?"true":"false", + c1_time, c2_time, c3_time, c4_time, c5_time, - c6_time); + c6_time, + c7_time); free(a); free(b); diff --git a/test/monniaux/mod_int_mat/modint.h b/test/monniaux/mod_int_mat/modint.h index 92005455..15c70a15 100644 --- a/test/monniaux/mod_int_mat/modint.h +++ b/test/monniaux/mod_int_mat/modint.h @@ -34,6 +34,11 @@ void modint_mat_mul6(unsigned m, unsigned n, unsigned p, const modint *a, unsigned stride_a, const modint *b, unsigned stride_b); +void modint_mat_mul7(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, |