PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "sqrt.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, res;
15  lhs.d = args->a[i];
16  printf("lhs: %.8e 0x%016llX\n", lhs.d, lhs.u);
17  lhs.u = __float_to_in(lhs.u);
18  printf("lhs: 0x%016llX\n", lhs.u);
19  res.u = double_prec_sqrt(lhs.u);
20  printf("res: 0x%016llX\n", res.u);
21  res.u = __out_to_float(res.u);
22  printf("res: %.8e 0x%016llX\n\n", res.d, res.u);
23  args->c[i] = res.d;
24  }
25 }
26 
27 /* Input format:
28 %%: Section 1
29 double[TESTS_COUNT]: lhs
30 */
31 
32 void input_to_data(int fd, void* vdata)
33 {
34  struct bench_args_t* data = (struct bench_args_t*)vdata;
35  char *p, *s;
36  // Zero-out everything.
37  memset(vdata, 0, sizeof(struct bench_args_t));
38  // Load input string
39  p = readfile(fd);
40  // Section 1: a
41  s = find_section_start(p, 1);
42  parse_double_array(s, data->a, TESTS_COUNT);
43  free(p);
44 }
45 
46 void data_to_input(int fd, void* vdata)
47 {
48  struct bench_args_t* data = (struct bench_args_t*)vdata;
49  // Section 1
51  write_double_array(fd, data->a, TESTS_COUNT);
52 }
53 
54 /* Output format:
55 %% Section 1
56 double[TESTS_COUNT]: result
57 */
58 
59 void output_to_data(int fd, void* vdata)
60 {
61  struct bench_args_t* data = (struct bench_args_t*)vdata;
62 
63  char *p, *s;
64  // Zero-out everything.
65  memset(vdata, 0, sizeof(struct bench_args_t));
66  // Load input string
67  p = readfile(fd);
68  // Section 1: c
69  s = find_section_start(p, 1);
70  parse_double_array(s, data->c, TESTS_COUNT);
71  free(p);
72 }
73 
74 void data_to_output(int fd, void* vdata)
75 {
76  struct bench_args_t* data = (struct bench_args_t*)vdata;
77  // Section 1
79  write_double_array(fd, data->c, TESTS_COUNT);
80 }
81 
82 int check_data(void* vdata)
83 {
84  struct bench_args_t* data = (struct bench_args_t*)vdata;
85  int has_errors = 0;
86  int i;
87 
88  for(i = 0; i < TESTS_COUNT; i++)
89  {
90  vc_t lhs;
91  double ref;
92  lhs.d = data->a[i];
93  lhs.u = __float_recast(lhs.u);
94  ref = __builtin_sqrt(lhs.d);
95  has_errors |= m_float_distance(data->c[i], ref) > MAX_ULP;
96  }
97 
98  // Return true if it's correct.
99  return !has_errors;
100 }
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
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
double double_prec_sqrt(double a)
Definition: sqrt.c:1
#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

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