1 #include <immintrin.h>
2 #include "m256-check.h"
3 
4 typedef union
5 {
6   __m512i x;
7   char a[64];
8 } union512i_b;
9 
10 typedef union
11 {
12   __m512i x;
13   short a[32];
14 } union512i_w;
15 
16 typedef union
17 {
18   __m512i x;
19   int a[16];
20 } union512i_d;
21 
22 typedef union
23 {
24   __m512i x;
25   long long a[8];
26 } union512i_q;
27 
28 typedef union
29 {
30   __m512 x;
31   float a[16];
32 } union512;
33 
34 typedef union
35 {
36   __m512d x;
37   double a[8];
38 } union512d;
39 
40 CHECK_EXP (union512i_b, char, "%d")
41 CHECK_EXP (union512i_w, short, "%d")
42 CHECK_EXP (union512i_d, int, "0x%x")
43 CHECK_EXP (union512i_q, long long, "0x%llx")
44 CHECK_EXP (union512, float, "%f")
45 CHECK_EXP (union512d, double, "%f")
46 
47 CHECK_FP_EXP (union512, float, ESP_FLOAT, "%f")
48 CHECK_FP_EXP (union512d, double, ESP_DOUBLE, "%f")
49 
50 #define CHECK_ROUGH_EXP(UINON_TYPE, VALUE_TYPE, FMT)		\
51 static int							\
52 __attribute__((noinline, unused))				\
53 check_rough_##UINON_TYPE (UINON_TYPE u, const VALUE_TYPE *v,	\
54 			  VALUE_TYPE eps)			\
55 {								\
56   int i;							\
57   int err = 0;							\
58 								\
59   for (i = 0; i < ARRAY_SIZE (u.a); i++)			\
60     {								\
61       /* We can have have v[i] == 0 == u.a[i]  for some i,	\
62          when we test zero-masking.  */				\
63       if (v[i] == 0.0 && u.a[i] == 0.0)				\
64 	continue;						\
65       if (v[i] == 0.0 && u.a[i] != 0.0)				\
66 	{							\
67 	  err++;						\
68 	  PRINTF ("%i: " FMT " != " FMT "\n",			\
69 		  i, v[i], u.a[i]);				\
70 	}							\
71       VALUE_TYPE rel_err = (u.a[i] - v[i]) / v[i];		\
72       if (((rel_err < 0) ? -rel_err : rel_err) > eps)		\
73 	{							\
74 	  err++;						\
75 	  PRINTF ("%i: " FMT " != " FMT "\n",			\
76 		  i, v[i], u.a[i]);				\
77 	}							\
78     }								\
79   return err;							\
80 }
81 
82 CHECK_ROUGH_EXP (union512, float, "%f")
83 CHECK_ROUGH_EXP (union512d, double, "%f")
84