PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "sub.h"
2 #include <string.h>
3 
4 #include <mdpi/mdpi_user.h>
5 
6 int INPUT_SIZE = sizeof(struct bench_args_t);
7 
8 void run_benchmark(void* vargs)
9 {
10  size_t i;
11  struct bench_args_t* args = (struct bench_args_t*)vargs;
12  for(i = 0; i < TESTS_COUNT; ++i)
13  {
14  vc_t lhs, rhs, res;
15  lhs.d = args->a[i];
16  rhs.d = args->b[i];
17  printf("lhs: %.8e 0x%016llX\nrhs: %.8e 0x%016llX\n", lhs.d, lhs.u, rhs.d, rhs.u);
18  lhs.u = __float_to_in(lhs.u);
19  rhs.u = __float_to_in(rhs.u);
20  printf("lhs: 0x%016llX\nrhs: 0x%016llX\n", lhs.u, rhs.u);
21  res.u = double_prec_subtraction(lhs.u, rhs.u);
22  printf("res: 0x%016llX\n", res.u);
23  res.u = __out_to_float(res.u);
24  printf("res: %.8e 0x%016llX\n\n", res.d, res.u);
25  args->c[i] = res.d;
26  }
27 }
28 
29 /* Input format:
30 %%: Section 1
31 double[TESTS_COUNT]: lhs
32 %%: Section 2
33 double[TESTS_COUNT]: rhs
34 */
35 
36 void input_to_data(int fd, void* vdata)
37 {
38  struct bench_args_t* data = (struct bench_args_t*)vdata;
39  char *p, *s;
40  // Zero-out everything.
41  memset(vdata, 0, sizeof(struct bench_args_t));
42  // Load input string
43  p = readfile(fd);
44  // Section 1: a
45  s = find_section_start(p, 1);
46  parse_double_array(s, data->a, TESTS_COUNT);
47  // Section 2: b
48  s = find_section_start(p, 2);
49  parse_double_array(s, data->b, TESTS_COUNT);
50  free(p);
51 }
52 
53 void data_to_input(int fd, void* vdata)
54 {
55  struct bench_args_t* data = (struct bench_args_t*)vdata;
56  // Section 1
58  write_double_array(fd, data->a, TESTS_COUNT);
59  // Section 2
61  write_double_array(fd, data->b, TESTS_COUNT);
62 }
63 
64 /* Output format:
65 %% Section 1
66 double[TESTS_COUNT]: result
67 */
68 
69 void output_to_data(int fd, void* vdata)
70 {
71  struct bench_args_t* data = (struct bench_args_t*)vdata;
72 
73  char *p, *s;
74  // Zero-out everything.
75  memset(vdata, 0, sizeof(struct bench_args_t));
76  // Load input string
77  p = readfile(fd);
78  // Section 1: c
79  s = find_section_start(p, 1);
80  parse_double_array(s, data->c, TESTS_COUNT);
81  free(p);
82 }
83 
84 void data_to_output(int fd, void* vdata)
85 {
86  struct bench_args_t* data = (struct bench_args_t*)vdata;
87  // Section 1
89  write_double_array(fd, data->c, TESTS_COUNT);
90 }
91 
92 int check_data(void* vdata)
93 {
94  struct bench_args_t* data = (struct bench_args_t*)vdata;
95  int has_errors = 0;
96  int i;
97 
98  for(i = 0; i < TESTS_COUNT; i++)
99  {
100  vc_t lhs, rhs;
101  double ref;
102  lhs.d = data->a[i];
103  rhs.d = data->b[i];
104  lhs.u = __float_recast(lhs.u);
105  rhs.u = __float_recast(rhs.u);
106  ref = lhs.d - rhs.d;
107  has_errors |= m_float_distance(data->c[i], ref) > MAX_ULP;
108  }
109 
110  // Return true if it's correct.
111  return !has_errors;
112 }
TYPE a[SIZE]
Definition: sort.h:16
#define TESTS_COUNT
Definition: add.h:5
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
double u
Definition: support.h:136
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
double d
Definition: support.h:135
int INPUT_SIZE
Definition: local_support.c:4
int write_double_array(int fd, double *arr, int n)
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
#define __out_to_float(out)
Definition: support.h:131
int write_section_header(int fd)
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
double double_prec_subtraction(double a, double b)
Definition: f64sub.c:1
char * readfile(int fd)
Definition: support.c:34
#define __float_recast(in)
Definition: support.h:140
void input_to_data(int fd, void *vdata)
Definition: local_support.c:18
char * find_section_start(char *s, int n)
Definition: support.c:56
#define MAX_ULP
Definition: support.h:60
double c[TESTS_COUNT]
Definition: add.h:16
#define __float_to_in(in)
Definition: support.h:130
int parse_double_array(char *s, double *arr, int n)
Definition: support.h:133
void run_benchmark(void *vargs)
Definition: local_support.c:6
int b[SIZE]
Definition: sort.h:34

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13