diff options
author | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-01-17 20:52:25 +0100 |
---|---|---|
committer | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-01-17 20:52:25 +0100 |
commit | e470d6f582e381da781f1bf33612aa2f429a1a87 (patch) | |
tree | 24da48cb96a3264bf988d5093653562991e53799 /test/monniaux | |
parent | 34595a9b0a2a4f7314a894294b8a9f92baa497c2 (diff) | |
download | compcert-kvx-e470d6f582e381da781f1bf33612aa2f429a1a87.tar.gz compcert-kvx-e470d6f582e381da781f1bf33612aa2f429a1a87.zip |
show cycle counts
Diffstat (limited to 'test/monniaux')
-rw-r--r-- | test/monniaux/int_mat_run.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/test/monniaux/int_mat_run.c b/test/monniaux/int_mat_run.c index ec68d719..3091f929 100644 --- a/test/monniaux/int_mat_run.c +++ b/test/monniaux/int_mat_run.c @@ -1,19 +1,61 @@ #include <stdbool.h> #include <stdlib.h> #include <stdio.h> +#include <inttypes.h> #include "modint.h" +typedef uint64_t cycle_t; + +#ifdef __K1C__ +#include <mppa_bare_runtime/k1c/registers.h> +static inline void cycle_count_config(void) +{ + /* config pmc for cycle count */ + uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); + + pmc_value &= ~(0xfULL); + __builtin_k1_set(K1_SFR_PMC, pmc_value); +} + +static inline uint64_t get_cycle(void) +{ + return __builtin_k1_get(K1_SFR_PM0); +} +#else +static inline void cycle_count_config(void) { } +#ifdef __x86_64__ +#include <x86intrin.h> +static inline cycle_t get_cycle(void) { return __rdtsc(); } +#else +static inline cycle_t get_cycle(void) { return 0; } +#endif +#endif + int main() { const unsigned m = 40, n = 20, p = 30; + cycle_count_config(); modint *a = malloc(sizeof(modint) * m * n); modint_mat_random(m, n, a, n); modint *b = malloc(sizeof(modint) * n * p); modint_mat_random(n, p, b, p); + modint *c1 = malloc(sizeof(modint) * m * p); - modint_mat_mul1(m, n, p, c1, p, a, n, b, p); + cycle_t c1_time = get_cycle(); + modint_mat_mul1(m, n, p, c1, p, a, n, b, p); + c1_time = get_cycle()-c1_time; + modint *c2 = malloc(sizeof(modint) * m * p); + cycle_t c2_time = get_cycle(); modint_mat_mul2(m, n, p, c2, p, a, n, b, p); - printf("equal = %s\n", modint_mat_equal(m, n, c1, p, c2, p)?"true":"false"); + c2_time = get_cycle()-c2_time; + + printf("equal = %s\n" + "c1_time = %" PRIu64 "\n" + "c2_time = %" PRIu64 "\n", + modint_mat_equal(m, n, c1, p, c2, p)?"true":"false", + c1_time, + c2_time); + free(a); free(b); free(c1); |