Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
963 changes: 362 additions & 601 deletions changelog.in

Large diffs are not rendered by default.

467 changes: 169 additions & 298 deletions docs/cmake-build.md

Large diffs are not rendered by default.

571 changes: 225 additions & 346 deletions docs/code-style.md

Large diffs are not rendered by default.

379 changes: 217 additions & 162 deletions docs/gecode-7-migration.md

Large diffs are not rendered by default.

60 changes: 19 additions & 41 deletions gecode/float.hh
Original file line number Diff line number Diff line change
Expand Up @@ -144,49 +144,27 @@ namespace Gecode {
namespace Gecode::Float {

/**
* \brief Floating point rounding operations without state saving
* \brief Floating-point rounding operations without state saving
*
* Every lower bound is rounded toward \f$-\infty\f$ and every upper bound
* toward \f$+\infty\f$, also when the compiler optimizes and when the
* operands are compile-time constants.
* Rounds lower bounds toward \f$-\infty\f$ and upper bounds toward
* \f$+\infty\f$ without requiring `-frounding-math`, `/fp:strict`, or
* `#pragma STDC FENV_ACCESS`. Operands and results pass through barrier()
* (an empty volatile `asm` register constraint on GCC/Clang, or a volatile
* round-trip on other compilers) to prevent constant folding, result
* sharing across directions, and reordering across mode changes. Assumes
* IEEE binary64 arithmetic in SSE2 or AArch64 registers; x87 arithmetic
* and `-ffast-math` are unsupported.
*
* Neither Gecode nor applications need floating-point compiler flags or
* pragmas for this: no `-frounding-math`, `-ffp-model=strict`,
* `/fp:strict`, or `#pragma STDC FENV_ACCESS`. Compilers assume
* round-to-nearest without them, so each operand and each result of the
* arithmetic operations passes through barrier(). With GCC and Clang the
* barrier is an empty `__asm__ __volatile__` statement with the value as a
* floating-point register operand (`"+w"` on AArch64, `"+x"` on x86-64).
* Other compilers, including MSVC, use a volatile store and reload. The
* barrier hides the value from the optimizer, so constants are not
* folded, one result is not shared between the two directions, a negation
* is not fused into the operation, and no operation moves across a
* rounding-mode change. This relies on GCC and Clang keeping volatile
* `asm` statements, and every compiler keeping volatile accesses, in
* order with the opaque calls that change the mode (`fesetround` or
* `_control87`). IEEE binary64 arithmetic in SSE2 or AArch64 registers is
* assumed; x87 arithmetic and `-ffast-math` are not supported.
*
* The rounding mode is read and set with `std::fegetround` and
* `std::fesetround`. Under GECODE_FLOAT_MODE_CONTROL87 (cl.exe on x86 and
* x64) it is read and set with `_control87`, which also masks all
* floating-point exceptions while Gecode sets a mode and, on x86, selects
* 64-bit precision and affine infinity; restoring a mode writes back the
* caller's bits. Without GECODE_FLOAT_DIRECTED_PER_OPERATION, the mode
* stays upward between operations. An upper bound is computed directly,
* and a lower bound as the negated upper bound of the negated operation;
* sqrt_down() and median() switch the mode and switch back to upward.
* With it (MSVC on x64, or on x86 with SSE), each operation sets its own
* direction. int_down() and int_up() use `std::floor` and `std::ceil`,
* which do not depend on the mode.
*
* A RoundingBase sets no mode on construction. Without
* GECODE_FLOAT_DIRECTED_PER_OPERATION, its operations need the upward
* mode, so use a Rounding, which sets that mode and restores the
* caller's mode on destruction.
*
* The test Float::Arithmetic::DirectedRounding checks the bounds with
* literal and runtime operands under every caller mode.
* Uses `std::fegetround`/`std::fesetround`, or `_control87` under
* GECODE_FLOAT_MODE_CONTROL87 (MSVC on x86/x64, masking FP exceptions and
* selecting 64-bit precision on x86 while active). Without
* GECODE_FLOAT_DIRECTED_PER_OPERATION, operations assume upward rounding
* between calls (computing lower bounds via negation, except sqrt_down()
* and median() which switch temporarily); with it, each operation sets
* its own direction. int_down() and int_up() use `std::floor` and
* `std::ceil`. RoundingBase never changes the mode on construction; use
* Rounding to save the caller's mode, enter upward mode when required,
* and restore the saved mode on destruction.
*
* \ingroup TaskModelFloatVars
*/
Expand Down
59 changes: 17 additions & 42 deletions gecode/float/interval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,51 +38,26 @@
namespace Gecode::Float {

/**
* \brief Closed interval of floating-point numbers with directed rounding
* \brief Closed floating-point interval with directed rounding
*
* An interval \f$[l,u]\f$ stands for every real number between its
* bounds. Arithmetic rounds each lower bound toward \f$-\infty\f$ and each
* upper bound toward \f$+\infty\f$, so a result contains the exact result
* of the operation for all members of its operands.
* Represents \f$[l,u]\f$ with \f$l\leq u\f$. Arithmetic rounds lower bounds
* toward \f$-\infty\f$ and upper bounds toward \f$+\infty\f$, so each
* result encloses the exact image of its operands. Trivially copyable.
*
* Contract:
* - An interval is never empty. Interval(l,u) and assign() throw
* std::runtime_error unless \f$l\leq u\f$, which also rejects NaN
* bounds. An operation whose exact result is empty throws the same
* exception: division by \f$[0,0]\f$ or by 0, pow() of \f$[0,0]\f$
* with an exponent of at most 0, sqrt() of an interval without a
* nonnegative member, log() of one without a positive member, an even
* nth_root() of a negative interval, a disjoint intersect(), and
* asin(), acos(), acosh(), and atanh() outside their domains.
* - Interval(v) and unchecked() check nothing. Results keep NaN bounds,
* for example from \f$0\cdot\infty\f$ or \f$\infty-\infty\f$.
* - Each operation that rounds opens one Rounding for its whole
* computation, so the caller's rounding mode is restored afterwards,
* also when the operation throws.
* - There are no comparison operators. FloatVal's relations hold only
* when they hold for all members of both operands, such as
* certainly_less(), while its equality compares bounds, as equal()
* does. Named functions keep the two meanings apart.
* Intervals are never empty: Interval(l,u) and assign() throw
* std::runtime_error unless \f$l\leq u\f$ (rejecting NaN bounds).
* Operations whose exact result is empty throw the same exception:
* division by \f$[0,0]\f$ or 0, pow() of \f$[0,0]\f$ with nonpositive
* exponent, sqrt() without a nonnegative member, log() without a positive
* member, even nth_root() of a negative interval, disjoint intersect(),
* and asin(), acos(), acosh(), and atanh() outside their domains.
* Interval(v) and unchecked() perform no checks and preserve NaN bounds
* (e.g. from \f$0\cdot\infty\f$ or \f$\infty-\infty\f$).
*
* \par Design decision
* Gecode implements the interval arithmetic it needs itself, for double
* bounds, with no external dependency. Directed rounding switches the
* floating-point rounding mode through RoundingBase and Rounding. The
* measured alternatives were a script-refreshed copy of Boost 1.92.0's
* interval library, the 2012 copy of Boost 1.47.0 made reproducible, and
* outward rounding with std::nextafter, either always widening or
* widening only by the sign of an error term. The nextafter variants
* loosen bounds, which was not accepted, and an installed Boost was ruled
* out as a dependency. This implementation was chosen because it
* reproduces the Boost copy's bounds, truth values, and search statistics
* bit for bit on arm64 and x86-64. Without the copy, Gecode installs 95
* fewer headers and no third-party code, exports the same symbols, and
* runs as fast or faster. The interval type is trivially copyable.
*
* \par Acknowledgement
* The operations reproduce the results of the Boost Interval Arithmetic
* Library (Boost.Interval), which Gecode has used since 2012 and which
* served as the reference during development.
* Rounding operations open a Rounding scope and restore the caller's
* rounding mode on return or exception. Named comparisons (such as
* certainly_less() and equal()) are used instead of operators to separate
* memberwise relations from bound equality. Results match Boost.Interval.
*
* \ingroup TaskModelFloatVars
*/
Expand Down
Loading