[PATCH] D146188: [Clang][DOC] Add documentation in for __builtin_flt_rounds and __builtin_set_flt_rounds

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 21 14:06:26 PDT 2023


rjmccall added a comment.

Okay.  I was looking at a version of the standard that makes reading the environment UB.  If that's been relaxed, then I agree that it would be much more natural to talk about *changing* the environment than just *accessing* it.

And yeah, I agree it would make sense to break this out into a separate section under "Controlling floating-point behavior".  We can cross-reference to that section from the Language Extensions document with something like:

  These builtins read and modify the floating-point environment, which is not always allowed and may have unexpected behavior.  Please see the section on `accessing the floating point environment <UsersManual.html#floating-point-environment>`_.

And then you just need to set up the corresponding anchor in the user's manual:

  .. _floating-point-environment:
  
  Accessing the floating point environment
  ----------------------
  
  Many targets allow floating point operations to be configured to control things such as how inexact results should be rounded and how exceptional conditions should be handled.  This configuration is called the floating point environment.  C and C++ restrict access to the floating point environment by default, and the compiler is allowed to assume that all operations are performed in the default environment.  When code is compiled in this default mode, operations that depend on the environment (such as floating-point arithmetic and `FLT_ROUNDS`) may have undefined behavior if the dynamic environment is not the default environment; for example, `FLT_ROUNDS` may or may not simply return its default value for the target instead of reading the dynamic environment, and floating-point operations may be optimized as if the dynamic environment were the default.  Similarly, it is undefined behavior to change the floating point environment in this default mode, for example by calling the `fesetround` function.
  
  Clang supports three ways to change how floating point operations behave:
  ...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146188/new/

https://reviews.llvm.org/D146188



More information about the cfe-commits mailing list