[clang] Add __builtin_isfpclass
authorSerge Pavlov <sepavloff@gmail.com>
Sun, 18 Jun 2023 15:53:32 +0000 (22:53 +0700)
committerSerge Pavlov <sepavloff@gmail.com>
Sun, 18 Jun 2023 15:53:32 +0000 (22:53 +0700)
commit7dd387d2971d7759cadfffeb2082439f6c7ddd49
tree547dbe0f1395a132122a32c90d7433b9496d163a
parent315e3001c0ebe1a76c0cb6109d29a3a5e22376de
[clang] Add __builtin_isfpclass

A new builtin function __builtin_isfpclass is added. It is called as:

    __builtin_isfpclass(<floating point value>, <test>)

and returns an integer value, which is non-zero if the floating point
argument falls into one of the classes specified by the second argument,
and zero otherwise. The set of classes is an integer value, where each
value class is represented by a bit. There are ten data classes, as
defined by the IEEE-754 standard, they are represented by bits:

    0x0001 (__FPCLASS_SNAN)         - Signaling NaN
    0x0002 (__FPCLASS_QNAN)         - Quiet NaN
    0x0004 (__FPCLASS_NEGINF)       - Negative infinity
    0x0008 (__FPCLASS_NEGNORMAL)    - Negative normal
    0x0010 (__FPCLASS_NEGSUBNORMAL) - Negative subnormal
    0x0020 (__FPCLASS_NEGZERO)      - Negative zero
    0x0040 (__FPCLASS_POSZERO)      - Positive zero
    0x0080 (__FPCLASS_POSSUBNORMAL) - Positive subnormal
    0x0100 (__FPCLASS_POSNORMAL)    - Positive normal
    0x0200 (__FPCLASS_POSINF)       - Positive infinity

They have corresponding builtin macros to facilitate using the builtin
function:

    if (__builtin_isfpclass(x, __FPCLASS_NEGZERO | __FPCLASS_POSZERO) {
      // x is any zero.
    }

The data class encoding is identical to that used in llvm.is.fpclass
function.

Differential Revision: https://reviews.llvm.org/D152351
15 files changed:
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins.c
clang/test/CodeGen/isfpclass.c [new file with mode: 0644]
clang/test/Preprocessor/init-aarch64.c
clang/test/Preprocessor/init.c
clang/test/Sema/builtins.c
clang/test/Sema/constant-builtins-2.c
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/IRBuilder.cpp