1 //===- FloatingPointMode.cpp ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/FloatingPointMode.h"
10 #include "llvm/ADT/StringExtras.h"
14 FPClassTest
llvm::fneg(FPClassTest Mask
) {
15 FPClassTest NewMask
= Mask
& fcNan
;
18 if (Mask
& fcNegNormal
)
19 NewMask
|= fcPosNormal
;
20 if (Mask
& fcNegSubnormal
)
21 NewMask
|= fcPosSubnormal
;
26 if (Mask
& fcPosSubnormal
)
27 NewMask
|= fcNegSubnormal
;
28 if (Mask
& fcPosNormal
)
29 NewMask
|= fcNegNormal
;
35 FPClassTest
llvm::inverse_fabs(FPClassTest Mask
) {
36 FPClassTest NewMask
= Mask
& fcNan
;
39 if (Mask
& fcPosSubnormal
)
40 NewMask
|= fcSubnormal
;
41 if (Mask
& fcPosNormal
)
48 FPClassTest
llvm::unknown_sign(FPClassTest Mask
) {
49 FPClassTest NewMask
= Mask
& fcNan
;
52 if (Mask
& fcSubnormal
)
53 NewMask
|= fcSubnormal
;
61 // Every bitfield has a unique name and one or more aliasing names that cover
62 // multiple bits. Names should be listed in order of preference, with higher
63 // popcounts listed first.
65 // Bits are consumed as printed. Each field should only be represented in one
67 static constexpr std::pair
<FPClassTest
, StringLiteral
> NoFPClassName
[] = {
79 {fcNegSubnormal
, "nsub"},
80 {fcPosSubnormal
, "psub"},
82 {fcNegNormal
, "nnorm"},
83 {fcPosNormal
, "pnorm"}
86 raw_ostream
&llvm::operator<<(raw_ostream
&OS
, FPClassTest Mask
) {
94 ListSeparator
LS(" ");
95 for (auto [BitTest
, Name
] : NoFPClassName
) {
96 if ((Mask
& BitTest
) == BitTest
) {
99 // Clear the bits so we don't print any aliased names later.
104 assert(Mask
== 0 && "didn't print some mask bits");