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 typedef union
41 {
42   __m512i x;
43   unsigned char a[64];
44 } union512i_ub;
45 
46 typedef union
47 {
48  __m512i x;
49  unsigned short a[32];
50  } union512i_uw;
51 
52 typedef union
53 {
54  __m512i x;
55  unsigned int a[16];
56 } union512i_ud;
57 
58 typedef union
59 {
60  __m512i x;
61  unsigned long long a[8];
62 } union512i_uq;
63 
64 
65 CHECK_EXP (union512i_b, char, "%d")
66 CHECK_EXP (union512i_w, short, "%d")
67 CHECK_EXP (union512i_d, int, "0x%x")
68 CHECK_EXP (union512i_q, long long, "0x%llx")
69 CHECK_EXP (union512, float, "%f")
70 CHECK_EXP (union512d, double, "%f")
71 CHECK_EXP (union512i_ub, unsigned char, "%d")
72 CHECK_EXP (union512i_uw, unsigned short, "%d")
73 CHECK_EXP (union512i_ud, unsigned int, "0x%x")
74 CHECK_EXP (union512i_uq, unsigned long long, "0x%llx")
75 
76 
77 CHECK_FP_EXP (union512, float, ESP_FLOAT, "%f")
78 CHECK_FP_EXP (union512d, double, ESP_DOUBLE, "%f")
79 
80 #define CHECK_ROUGH_EXP(UINON_TYPE, VALUE_TYPE, FMT)		\
81 static int							\
82 __attribute__((noinline, unused))				\
83 check_rough_##UINON_TYPE (UINON_TYPE u, const VALUE_TYPE *v,	\
84 			  VALUE_TYPE eps)			\
85 {								\
86   int i;							\
87   int err = 0;							\
88 								\
89   for (i = 0; i < ARRAY_SIZE (u.a); i++)			\
90     {								\
91       /* We can have have v[i] == 0 == u.a[i]  for some i,	\
92          when we test zero-masking.  */				\
93       if (v[i] == 0.0 && u.a[i] == 0.0)				\
94 	continue;						\
95       if (v[i] == 0.0 && u.a[i] != 0.0)				\
96 	{							\
97 	  err++;						\
98 	  PRINTF ("%i: " FMT " != " FMT "\n",			\
99 		  i, v[i], u.a[i]);				\
100 	}							\
101       VALUE_TYPE rel_err = (u.a[i] - v[i]) / v[i];		\
102       if (((rel_err < 0) ? -rel_err : rel_err) > eps)		\
103 	{							\
104 	  err++;						\
105 	  PRINTF ("%i: " FMT " != " FMT "\n",			\
106 		  i, v[i], u.a[i]);				\
107 	}							\
108     }								\
109   return err;							\
110 }
111 
112 CHECK_ROUGH_EXP (union512, float, "%f")
113 CHECK_ROUGH_EXP (union512d, double, "%f")
114 CHECK_ROUGH_EXP (union256, float, "%f")
115 CHECK_ROUGH_EXP (union256d, double, "%f")
116 CHECK_ROUGH_EXP (union128, float, "%f")
117 CHECK_ROUGH_EXP (union128d, double, "%f")
118