]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
2 | Copyright 1988-2022 Free Software Foundation, Inc. | |
3 | This is part of the GCC manual. | |
4 | For copying conditions, see the copyright.rst file. | |
5 | ||
6 | Consequences of using poly_int | |
7 | ****************************** | |
8 | ||
9 | The two main consequences of using polynomial sizes and offsets are that: | |
10 | ||
11 | * there is no total ordering between the values at compile time, and | |
12 | ||
13 | * some operations might yield results that cannot be expressed as a | |
14 | ``poly_int``. | |
15 | ||
16 | For example, if :samp:`{x}` is a runtime invariant, we cannot tell at | |
17 | compile time whether: | |
18 | ||
19 | .. code-block:: c++ | |
20 | ||
21 | 3 + 4x <= 1 + 5x | |
22 | ||
23 | since the condition is false when :samp:`{x}` <= 1 and true when :samp:`{x}` >= 2. | |
24 | ||
25 | Similarly, ``poly_int`` cannot represent the result of: | |
26 | ||
27 | .. code-block:: c++ | |
28 | ||
29 | (3 + 4x) * (1 + 5x) | |
30 | ||
31 | since it cannot (and in practice does not need to) store powers greater | |
32 | than one. It also cannot represent the result of: | |
33 | ||
34 | .. code-block:: c++ | |
35 | ||
36 | (3 + 4x) / (1 + 5x) | |
37 | ||
38 | The following sections describe how we deal with these restrictions. | |
39 | ||
40 | .. index:: poly_int, use in target-independent code | |
41 | ||
42 | As described earlier, a ``poly_int<1, T>`` has no indeterminates | |
43 | and so degenerates to a compile-time constant of type :samp:`{T}`. It would | |
44 | be possible in that case to do all normal arithmetic on the :samp:`{T}`, | |
45 | and to compare the :samp:`{T}` using the normal C++ operators. We deliberately | |
46 | prevent target-independent code from doing this, since the compiler needs | |
47 | to support other ``poly_int<n, T>`` as well, regardless of | |
48 | the current target's ``NUM_POLY_INT_COEFFS``. | |
49 | ||
50 | .. index:: poly_int, use in target-specific code | |
51 | ||
52 | However, it would be very artificial to force target-specific code | |
53 | to follow these restrictions if the target has no runtime indeterminates. | |
54 | There is therefore an implicit conversion from ``poly_int<1, T>`` | |
3ed1b4ce | 55 | to :samp:`{T}` when compiling target-specific translation units. |