1 /* { dg-do run } */
2 /* { dg-require-effective-target avx512f } */
3 /* { dg-options "-O2 -mavx512f" } */
4
5 #include "avx512f-check.h"
6
7 static inline void __attribute__ ((__always_inline__))
check_cmp(float s1,float s2,const int imm,int expected)8 check_cmp (float s1, float s2, const int imm, int expected)
9 {
10 __m128 source1 = _mm_load_ss (&s1);
11 __m128 source2 = _mm_load_ss (&s2);
12 int res = _mm_comi_round_ss (source1, source2, imm,
13 _MM_FROUND_NO_EXC);
14 if (expected != res)
15 abort();
16 }
17
18 static void
do_check(float s1,float s2)19 do_check (float s1, float s2)
20 {
21 check_cmp (s1, s2, _CMP_EQ_OQ,
22 !__builtin_isunordered (s1, s2) && s1 == s2);
23 check_cmp (s1, s2, _CMP_LT_OS,
24 !__builtin_isunordered (s1, s2) && s1 < s2);
25 check_cmp (s1, s2, _CMP_LE_OS,
26 !__builtin_isunordered (s1, s2) && s1 <= s2);
27 check_cmp (s1, s2, _CMP_UNORD_Q,
28 __builtin_isunordered (s1, s2));
29 check_cmp (s1, s2, _CMP_NEQ_UQ,
30 __builtin_isunordered (s1, s2) || s1 != s2);
31 check_cmp (s1, s2, _CMP_NLT_US,
32 __builtin_isunordered (s1, s2) || s1 >= s2);
33 check_cmp (s1, s2, _CMP_NLE_US,
34 __builtin_isunordered (s1, s2) || s1 > s2);
35 check_cmp (s1, s2, _CMP_ORD_Q,
36 !__builtin_isunordered (s1, s2));
37 check_cmp (s1, s2, _CMP_EQ_UQ,
38 __builtin_isunordered (s1, s2) || s1 == s2);
39 check_cmp (s1, s2, _CMP_NGE_US,
40 __builtin_isunordered (s1, s2) || s1 < s2);
41 check_cmp (s1, s2, _CMP_NGT_US,
42 __builtin_isunordered (s1, s2) || s1 <= s2);
43 check_cmp (s1, s2, _CMP_FALSE_OQ, 0);
44 check_cmp (s1, s2, _CMP_NEQ_OQ,
45 !__builtin_isunordered (s1, s2) && s1 != s2);
46 check_cmp (s1, s2, _CMP_GE_OS,
47 !__builtin_isunordered (s1, s2) && s1 >= s2);
48 check_cmp (s1, s2, _CMP_GT_OS,
49 !__builtin_isunordered (s1, s2) && s1 > s2);
50 check_cmp (s1, s2, _CMP_TRUE_UQ, 1);
51 check_cmp (s1, s2, _CMP_EQ_OS,
52 !__builtin_isunordered (s1, s2) && s1 == s2);
53 check_cmp (s1, s2, _CMP_LT_OQ,
54 !__builtin_isunordered (s1, s2) && s1 < s2);
55 check_cmp (s1, s2, _CMP_LE_OQ,
56 !__builtin_isunordered (s1, s2) && s1 <= s2);
57 check_cmp (s1, s2, _CMP_UNORD_S,
58 __builtin_isunordered (s1, s2));
59 check_cmp (s1, s2, _CMP_NEQ_US,
60 __builtin_isunordered (s1, s2) || s1 != s2);
61 check_cmp (s1, s2, _CMP_NLT_UQ,
62 __builtin_isunordered (s1, s2) || s1 >= s2);
63 check_cmp (s1, s2, _CMP_NLE_UQ,
64 __builtin_isunordered (s1, s2) || s1 > s2);
65 check_cmp (s1, s2, _CMP_ORD_S, !__builtin_isunordered (s1, s2));
66 check_cmp (s1, s2, _CMP_EQ_US,
67 __builtin_isunordered (s1, s2) || s1 == s2);
68 check_cmp (s1, s2, _CMP_NGE_UQ,
69 __builtin_isunordered (s1, s2) || s1 < s2);
70 check_cmp (s1, s2, _CMP_NGT_UQ,
71 __builtin_isunordered (s1, s2) || s1 <= s2);
72 check_cmp (s1, s2, _CMP_FALSE_OS, 0);
73 check_cmp (s1, s2, _CMP_NEQ_OS,
74 !__builtin_isunordered (s1, s2) && s1 != s2);
75 check_cmp (s1, s2, _CMP_GE_OQ,
76 !__builtin_isunordered (s1, s2) && s1 >= s2);
77 check_cmp (s1, s2, _CMP_GT_OQ,
78 !__builtin_isunordered (s1, s2) && s1 > s2);
79 check_cmp (s1, s2, _CMP_TRUE_US, 1);
80 }
81
82 static void
avx512f_test(void)83 avx512f_test (void)
84 {
85 struct
86 {
87 float x1;
88 float x2;
89 }
90 inputs[] =
91 {
92 { 4.3, 2.18 },
93 { -4.3, 3.18 },
94 { __builtin_nanf (""), -5.8 },
95 { -4.8, __builtin_nansf ("") },
96 { 3.8, __builtin_nansf ("") },
97 { 4.2, 4.2 },
98 { __builtin_nanf (""), __builtin_nansf ("") },
99 };
100 int i;
101
102 for (i = 0; i < sizeof (inputs) / sizeof (inputs[0]); i++)
103 do_check (inputs[i].x1, inputs[i].x2);
104 }
105