2 #include "gcc-plugin.h"
7 int plugin_is_GPL_compatible
;
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 };
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
)
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
)
27 test_wide_int_round_sdiv (void)
29 if (wi::ne_p (wi::div_round (2, 3, SIGNED
), 1))
31 if (wi::ne_p (wi::div_round (1, 3, SIGNED
), 0))
33 if (wi::ne_p (wi::mod_round (2, 3, SIGNED
), -1))
35 if (wi::ne_p (wi::mod_round (1, 3, SIGNED
), 1))
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)
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
)
60 if (wi::smod_trunc (a
, b
) != c
)
62 if (wi::smod_trunc (-a
, b
) != -c
)
64 if (wi::smod_trunc (a
, -b
) != c
)
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 ();