1 /* { dg-do run { target aarch64_sve_hw } } */
2 /* { dg-options "-O2 -ftree-vectorize" } */
3 /* { dg-require-effective-target fenv_exceptions } */
4 
5 #ifndef TEST_EXCEPTIONS
6 #define TEST_EXCEPTIONS 1
7 #endif
8 
9 #include <fenv.h>
10 
11 #include "vcond_4.c"
12 
13 #define N 401
14 
15 #define RUN_LOOP(TYPE1, TYPE2, CMP, EXPECT_INVALID)			\
16   {									\
17     TYPE1 dest[N], src[N];						\
18     TYPE2 a[N], b[N];							\
19     for (int i = 0; i < N; ++i)						\
20       {									\
21 	src[i] = i * i;							\
22 	if (i % 5 == 0)							\
23 	  a[i] = 0;							\
24 	else if (i % 3)							\
25 	  a[i] = i * 0.1;						\
26 	else								\
27 	  a[i] = i;							\
28 	if (i % 7 == 0)							\
29 	  b[i] = __builtin_nan ("");					\
30 	else if (i % 6)							\
31 	  b[i] = i * 0.1;						\
32 	else								\
33 	  b[i] = i;							\
34 	asm volatile ("" ::: "memory");					\
35       }									\
36     feclearexcept (FE_ALL_EXCEPT);					\
37     test_##TYPE1##_##TYPE2##_##CMP##_var (dest, src, 11, a, b, N);	\
38     if (TEST_EXCEPTIONS							\
39 	&& !fetestexcept (FE_INVALID) != !(EXPECT_INVALID))		\
40       __builtin_abort ();						\
41     for (int i = 0; i < N; ++i)						\
42       if (dest[i] != (CMP (a[i], b[i]) ? src[i] : 11))			\
43 	__builtin_abort ();						\
44   }
45 
46 #define RUN_CMP(CMP, EXPECT_INVALID) \
47   RUN_LOOP (int32_t, float, CMP, EXPECT_INVALID) \
48   RUN_LOOP (uint32_t, float, CMP, EXPECT_INVALID) \
49   RUN_LOOP (float, float, CMP, EXPECT_INVALID) \
50   RUN_LOOP (int64_t, double, CMP, EXPECT_INVALID) \
51   RUN_LOOP (uint64_t, double, CMP, EXPECT_INVALID) \
52   RUN_LOOP (double, double, CMP, EXPECT_INVALID)
53 
54 int __attribute__ ((optimize (1)))
main(void)55 main (void)
56 {
57   RUN_CMP (eq, 0)
58   RUN_CMP (ne, 0)
59   RUN_CMP (olt, 1)
60   RUN_CMP (ole, 1)
61   RUN_CMP (oge, 1)
62   RUN_CMP (ogt, 1)
63   RUN_CMP (ordered, 0)
64   RUN_CMP (unordered, 0)
65   RUN_CMP (ueq, 0)
66   RUN_CMP (ult, 0)
67   RUN_CMP (ule, 0)
68   RUN_CMP (uge, 0)
69   RUN_CMP (ugt, 0)
70   RUN_CMP (nueq, 0)
71   RUN_CMP (nult, 0)
72   RUN_CMP (nule, 0)
73   RUN_CMP (nuge, 0)
74   RUN_CMP (nugt, 0)
75   return 0;
76 }
77