/src/llvm-project/llvm/lib/Support/FloatingPointMode.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- FloatingPointMode.cpp ------------------------------------*- C++ -*-===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include "llvm/ADT/FloatingPointMode.h" |
10 | | #include "llvm/ADT/StringExtras.h" |
11 | | |
12 | | using namespace llvm; |
13 | | |
14 | 307 | FPClassTest llvm::fneg(FPClassTest Mask) { |
15 | 307 | FPClassTest NewMask = Mask & fcNan; |
16 | 307 | if (Mask & fcNegInf) |
17 | 268 | NewMask |= fcPosInf; |
18 | 307 | if (Mask & fcNegNormal) |
19 | 269 | NewMask |= fcPosNormal; |
20 | 307 | if (Mask & fcNegSubnormal) |
21 | 269 | NewMask |= fcPosSubnormal; |
22 | 307 | if (Mask & fcNegZero) |
23 | 267 | NewMask |= fcPosZero; |
24 | 307 | if (Mask & fcPosZero) |
25 | 306 | NewMask |= fcNegZero; |
26 | 307 | if (Mask & fcPosSubnormal) |
27 | 300 | NewMask |= fcNegSubnormal; |
28 | 307 | if (Mask & fcPosNormal) |
29 | 301 | NewMask |= fcNegNormal; |
30 | 307 | if (Mask & fcPosInf) |
31 | 298 | NewMask |= fcNegInf; |
32 | 307 | return NewMask; |
33 | 307 | } |
34 | | |
35 | 0 | FPClassTest llvm::inverse_fabs(FPClassTest Mask) { |
36 | 0 | FPClassTest NewMask = Mask & fcNan; |
37 | 0 | if (Mask & fcPosZero) |
38 | 0 | NewMask |= fcZero; |
39 | 0 | if (Mask & fcPosSubnormal) |
40 | 0 | NewMask |= fcSubnormal; |
41 | 0 | if (Mask & fcPosNormal) |
42 | 0 | NewMask |= fcNormal; |
43 | 0 | if (Mask & fcPosInf) |
44 | 0 | NewMask |= fcInf; |
45 | 0 | return NewMask; |
46 | 0 | } |
47 | | |
48 | 0 | FPClassTest llvm::unknown_sign(FPClassTest Mask) { |
49 | 0 | FPClassTest NewMask = Mask & fcNan; |
50 | 0 | if (Mask & fcZero) |
51 | 0 | NewMask |= fcZero; |
52 | 0 | if (Mask & fcSubnormal) |
53 | 0 | NewMask |= fcSubnormal; |
54 | 0 | if (Mask & fcNormal) |
55 | 0 | NewMask |= fcNormal; |
56 | 0 | if (Mask & fcInf) |
57 | 0 | NewMask |= fcInf; |
58 | 0 | return NewMask; |
59 | 0 | } |
60 | | |
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. |
64 | | // |
65 | | // Bits are consumed as printed. Each field should only be represented in one |
66 | | // printed field. |
67 | | static constexpr std::pair<FPClassTest, StringLiteral> NoFPClassName[] = { |
68 | | {fcAllFlags, "all"}, |
69 | | {fcNan, "nan"}, |
70 | | {fcSNan, "snan"}, |
71 | | {fcQNan, "qnan"}, |
72 | | {fcInf, "inf"}, |
73 | | {fcNegInf, "ninf"}, |
74 | | {fcPosInf, "pinf"}, |
75 | | {fcZero, "zero"}, |
76 | | {fcNegZero, "nzero"}, |
77 | | {fcPosZero, "pzero"}, |
78 | | {fcSubnormal, "sub"}, |
79 | | {fcNegSubnormal, "nsub"}, |
80 | | {fcPosSubnormal, "psub"}, |
81 | | {fcNormal, "norm"}, |
82 | | {fcNegNormal, "nnorm"}, |
83 | | {fcPosNormal, "pnorm"} |
84 | | }; |
85 | | |
86 | 0 | raw_ostream &llvm::operator<<(raw_ostream &OS, FPClassTest Mask) { |
87 | 0 | OS << '('; |
88 | |
|
89 | 0 | if (Mask == fcNone) { |
90 | 0 | OS << "none)"; |
91 | 0 | return OS; |
92 | 0 | } |
93 | | |
94 | 0 | ListSeparator LS(" "); |
95 | 0 | for (auto [BitTest, Name] : NoFPClassName) { |
96 | 0 | if ((Mask & BitTest) == BitTest) { |
97 | 0 | OS << LS << Name; |
98 | | |
99 | | // Clear the bits so we don't print any aliased names later. |
100 | 0 | Mask &= ~BitTest; |
101 | 0 | } |
102 | 0 | } |
103 | |
|
104 | 0 | assert(Mask == 0 && "didn't print some mask bits"); |
105 | | |
106 | 0 | OS << ')'; |
107 | 0 | return OS; |
108 | 0 | } |