Small ChangeLog tweak.
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / wide-int_plugin.c
blobeea56be5e7c2a3661786bd8dad3a474f09688538
1 #include "config.h"
2 #include "gcc-plugin.h"
3 #include "system.h"
4 #include "coretypes.h"
5 #include "tree.h"
7 int plugin_is_GPL_compatible;
9 static void
10 test_double_int_round_udiv (void)
12 double_int dmin = { 0, HOST_WIDE_INT_MIN };
13 double_int dmax = { (unsigned HOST_WIDE_INT)-1, HOST_WIDE_INT_MAX };
14 double_int dnegone = { (unsigned HOST_WIDE_INT)-1, -1 };
15 double_int mod, div;
16 div = dmin.udivmod (dnegone, ROUND_DIV_EXPR, &mod);
17 if (div.low != 1 || div.high != 0
18 || mod.low != 1 || mod.high != HOST_WIDE_INT_MIN)
19 abort ();
20 div = dmax.udivmod (dnegone, ROUND_DIV_EXPR, &mod);
21 if (div.low != 0 || div.high != 0
22 || mod.low != dmax.low || mod.high != dmax.high)
23 abort ();
26 static void
27 test_wide_int_round_sdiv (void)
29 if (wi::ne_p (wi::div_round (2, 3, SIGNED), 1))
30 abort ();
31 if (wi::ne_p (wi::div_round (1, 3, SIGNED), 0))
32 abort ();
33 if (wi::ne_p (wi::mod_round (2, 3, SIGNED), -1))
34 abort ();
35 if (wi::ne_p (wi::mod_round (1, 3, SIGNED), 1))
36 abort ();
39 static void
40 test_wide_int_mod_trunc (void)
42 for (unsigned int i = 1; i < MAX_BITSIZE_MODE_ANY_INT; ++i)
44 if (wi::smod_trunc (wi::lshift (1, i + 1) - 3,
45 wi::lshift (1, i) - 1)
46 != wi::lshift (1, i) - 2)
47 abort ();
48 for (unsigned int base = 32; base <= MAX_BITSIZE_MODE_ANY_INT; base *= 2)
49 for (int bias = -1; bias <= 1; ++bias)
51 unsigned int precision = base + bias;
52 if (i + 1 < precision && precision <= MAX_BITSIZE_MODE_ANY_INT)
54 wide_int one = wi::uhwi (1, precision);
55 wide_int a = wi::lshift (one, i + 1) - 3;
56 wide_int b = wi::lshift (one, i) - 1;
57 wide_int c = wi::lshift (one, i) - 2;
58 if (wi::umod_trunc (a, b) != c)
59 abort ();
60 if (wi::smod_trunc (a, b) != c)
61 abort ();
62 if (wi::smod_trunc (-a, b) != -c)
63 abort ();
64 if (wi::smod_trunc (a, -b) != c)
65 abort ();
71 int
72 plugin_init (struct plugin_name_args *plugin_info,
73 struct plugin_gcc_version *version)
75 test_double_int_round_udiv ();
76 test_wide_int_round_sdiv ();
77 test_wide_int_mod_trunc ();
78 return 0;