]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gccint/sizes-and-offsets-as-runtime-invariants/consequences-of-using-polyint.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / sizes-and-offsets-as-runtime-invariants / consequences-of-using-polyint.rst
CommitLineData
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
6Consequences of using poly_int
7******************************
8
9The 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
16For example, if :samp:`{x}` is a runtime invariant, we cannot tell at
17compile time whether:
18
19.. code-block:: c++
20
21 3 + 4x <= 1 + 5x
22
23since the condition is false when :samp:`{x}` <= 1 and true when :samp:`{x}` >= 2.
24
25Similarly, ``poly_int`` cannot represent the result of:
26
27.. code-block:: c++
28
29 (3 + 4x) * (1 + 5x)
30
31since it cannot (and in practice does not need to) store powers greater
32than one. It also cannot represent the result of:
33
34.. code-block:: c++
35
36 (3 + 4x) / (1 + 5x)
37
38The following sections describe how we deal with these restrictions.
39
40.. index:: poly_int, use in target-independent code
41
42As described earlier, a ``poly_int<1, T>`` has no indeterminates
43and so degenerates to a compile-time constant of type :samp:`{T}`. It would
44be possible in that case to do all normal arithmetic on the :samp:`{T}`,
45and to compare the :samp:`{T}` using the normal C++ operators. We deliberately
46prevent target-independent code from doing this, since the compiler needs
47to support other ``poly_int<n, T>`` as well, regardless of
48the current target's ``NUM_POLY_INT_COEFFS``.
49
50.. index:: poly_int, use in target-specific code
51
52However, it would be very artificial to force target-specific code
53to follow these restrictions if the target has no runtime indeterminates.
54There is therefore an implicit conversion from ``poly_int<1, T>``
3ed1b4ce 55to :samp:`{T}` when compiling target-specific translation units.