1 /* { dg-do run } */ 2 /* { dg-require-effective-target avx512er } */ 3 /* { dg-options "-O2 -ffast-math -ftree-vectorize -mavx512er" } */ 4 5 #include <math.h> 6 #include "avx512er-check.h" 7 8 #define MAX 1000 9 #define EPS 0.00001 10 11 __attribute__ ((noinline, optimize (1))) 12 void static compute_rsqrt_ref(float * a,float * r)13compute_rsqrt_ref (float *a, float *r) 14 { 15 for (int i = 0; i < MAX; i++) 16 r[i] = 1.0 / sqrtf (a[i]); 17 } 18 19 __attribute__ ((noinline)) 20 void static compute_rsqrt_exp(float * a,float * r)21compute_rsqrt_exp (float *a, float *r) 22 { 23 for (int i = 0; i < MAX; i++) 24 r[i] = 1.0 / sqrtf (a[i]); 25 } 26 27 void static avx512er_test(void)28avx512er_test (void) 29 { 30 float in[MAX]; 31 float ref[MAX]; 32 float exp[MAX]; 33 34 for (int i = 0; i < MAX; i++) 35 in[i] = 8765.987 - 8.6756 * i; 36 37 compute_rsqrt_ref (in, ref); 38 compute_rsqrt_exp (in, exp); 39 40 for (int i = 0; i < MAX; i++) 41 { 42 float rel_err = (ref[i] - exp[i]) / ref[i]; 43 rel_err = rel_err > 0.0 ? rel_err : -rel_err; 44 if (rel_err > EPS) 45 abort (); 46 } 47 } 48