Debian Codegraph @

gcc/testsuite/gcc.target/loongarch/fclass-run.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fsignaling-nans -D_GNU_SOURCE -std=c23" } */
3 /* { dg-require-effective-target fenv_exceptions } */
4
5 #include <fenv.h>
6 #include "fclass-compile.c"
7
8 #define ASSERT_EQ(x, y) (void)(x == y || (__builtin_abort (), 1))
9
10 int
11 main (void)
12 {
13 volatile float f_inf = __builtin_inff ();
14 volatile float f_zero = 0;
15 volatile float f_normal = 114.514;
16 volatile float f_subnormal = 1e-40;
17 volatile float f_qnan = __builtin_nanf ("");
18 volatile float f_snan = __builtin_nansf ("");
19 volatile double d_inf = __builtin_inf ();
20 volatile double d_zero = 0;
21 volatile double d_normal = 1919.810;
22 volatile double d_subnormal = 1e-320;
23 volatile double d_qnan = __builtin_nan ("");
24 volatile double d_snan = __builtin_nans ("");
25
26 #if __loongarch_frlen >= 64
27 /* With fclass.{s/d} we shouldn't signal, even if the input is sNaN.
28 PR 66462. */
29 feenableexcept (FE_INVALID);
30 #endif
31
32 ASSERT_EQ (test_fclass_f (f_inf), 0b001);
33 ASSERT_EQ (test_fclass_f (-f_inf), 0b001);
34 ASSERT_EQ (test_fclass_f (f_zero), 0b100);
35 ASSERT_EQ (test_fclass_f (-f_zero), 0b100);
36 ASSERT_EQ (test_fclass_f (f_normal), 0b110);
37 ASSERT_EQ (test_fclass_f (-f_normal), 0b110);
38 ASSERT_EQ (test_fclass_f (f_subnormal), 0b100);
39 ASSERT_EQ (test_fclass_f (-f_subnormal), 0b100);
40 ASSERT_EQ (test_fclass_f (f_qnan), 0);
41 ASSERT_EQ (test_fclass_f (f_snan), 0);
42
43 ASSERT_EQ (test_fclass_d (d_inf), 0b001);
44 ASSERT_EQ (test_fclass_d (-d_inf), 0b001);
45 ASSERT_EQ (test_fclass_d (d_zero), 0b100);
46 ASSERT_EQ (test_fclass_d (-d_zero), 0b100);
47 ASSERT_EQ (test_fclass_d (d_normal), 0b110);
48 ASSERT_EQ (test_fclass_d (-d_normal), 0b110);
49 ASSERT_EQ (test_fclass_d (d_subnormal), 0b100);
50 ASSERT_EQ (test_fclass_d (-d_subnormal), 0b100);
51 ASSERT_EQ (test_fclass_d (d_qnan), 0);
52 ASSERT_EQ (test_fclass_d (d_snan), 0);
53 }