Pass newly updated -march, -mabi options to gcc
[riscv-tests.git] / benchmarks / mt-vvadd / mt-vvadd.c
1 // See LICENSE for license details.
2
3 //**************************************************************************
4 // Vector-vector add benchmark
5 //--------------------------------------------------------------------------
6 // Author : Andrew Waterman
7 // TA : Christopher Celio
8 // Student :
9 //
10 // This benchmark adds two vectors and writes the results to a
11 // third vector. The input data (and reference data) should be
12 // generated using the vvadd_gendata.pl perl script and dumped
13 // to a file named dataset.h
14
15 // to print out arrays, etc.
16 //#define DEBUG
17
18 //--------------------------------------------------------------------------
19 // Includes
20
21 #include <string.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24
25
26 //--------------------------------------------------------------------------
27 // Input/Reference Data
28
29 #include "dataset.h"
30
31
32 //--------------------------------------------------------------------------
33 // Basic Utilities and Multi-thread Support
34
35 #include "util.h"
36
37
38 //--------------------------------------------------------------------------
39 // vvadd function
40
41 extern void __attribute__((noinline)) vvadd(int coreid, int ncores, size_t n, const data_t* x, const data_t* y, data_t* z);
42
43
44 //--------------------------------------------------------------------------
45 // Main
46 //
47 // all threads start executing thread_entry(). Use their "coreid" to
48 // differentiate between threads (each thread is running on a separate core).
49
50 void thread_entry(int cid, int nc)
51 {
52 // static allocates data in the binary, which is visible to both threads
53 static data_t results_data[DATA_SIZE];
54
55 // First do out-of-place vvadd
56 barrier(nc);
57 stats(vvadd(cid, nc, DATA_SIZE, input1_data, input2_data, results_data); barrier(nc), DATA_SIZE);
58
59 if(cid == 0) {
60 #ifdef DEBUG
61 printDoubleArray("out-of-place results: ", DATA_SIZE, results_data);
62 printDoubleArray("out-of-place verify : ", DATA_SIZE, verify_data);
63 #endif
64 int res = verifyDouble(DATA_SIZE, results_data, verify_data);
65 if(res) exit(res);
66 }
67
68 // Second do in-place vvadd
69 // Copying input
70 size_t i;
71 if(cid == 0) {
72 for (i = 0; i < DATA_SIZE; i++)
73 results_data[i] = input1_data[i];
74 }
75 barrier(nc);
76 stats(vvadd(cid, nc, DATA_SIZE, results_data, input2_data, results_data); barrier(nc), DATA_SIZE);
77
78 if(cid == 0) {
79 #ifdef DEBUG
80 printDoubleArray("in-place results: ", DATA_SIZE, results_data);
81 printDoubleArray("in-place verify : ", DATA_SIZE, verify_data);
82 #endif
83 int res = verifyDouble(DATA_SIZE, results_data, verify_data);
84 if(res) exit(res);
85 }
86
87 barrier(nc);
88 exit(0);
89 }