FloatingPointMode.cpp
5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//===- llvm/unittest/ADT/FloatingPointMode.cpp ----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/FloatingPointMode.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
TEST(FloatingPointModeTest, ParseDenormalFPAttributeComponent) {
EXPECT_EQ(DenormalMode::IEEE, parseDenormalFPAttributeComponent("ieee"));
EXPECT_EQ(DenormalMode::IEEE, parseDenormalFPAttributeComponent(""));
EXPECT_EQ(DenormalMode::PreserveSign,
parseDenormalFPAttributeComponent("preserve-sign"));
EXPECT_EQ(DenormalMode::PositiveZero,
parseDenormalFPAttributeComponent("positive-zero"));
EXPECT_EQ(DenormalMode::Invalid, parseDenormalFPAttributeComponent("foo"));
}
TEST(FloatingPointModeTest, DenormalAttributeName) {
EXPECT_EQ("ieee", denormalModeKindName(DenormalMode::IEEE));
EXPECT_EQ("preserve-sign", denormalModeKindName(DenormalMode::PreserveSign));
EXPECT_EQ("positive-zero", denormalModeKindName(DenormalMode::PositiveZero));
EXPECT_EQ("", denormalModeKindName(DenormalMode::Invalid));
}
TEST(FloatingPointModeTest, ParseDenormalFPAttribute) {
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
parseDenormalFPAttribute("ieee"));
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
parseDenormalFPAttribute("ieee,ieee"));
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
parseDenormalFPAttribute("ieee,"));
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
parseDenormalFPAttribute(""));
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
parseDenormalFPAttribute(","));
EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
parseDenormalFPAttribute("preserve-sign"));
EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
parseDenormalFPAttribute("preserve-sign,"));
EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
parseDenormalFPAttribute("preserve-sign,preserve-sign"));
EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
parseDenormalFPAttribute("positive-zero"));
EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
parseDenormalFPAttribute("positive-zero,positive-zero"));
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::PositiveZero),
parseDenormalFPAttribute("ieee,positive-zero"));
EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::IEEE),
parseDenormalFPAttribute("positive-zero,ieee"));
EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE),
parseDenormalFPAttribute("preserve-sign,ieee"));
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign),
parseDenormalFPAttribute("ieee,preserve-sign"));
EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
parseDenormalFPAttribute("foo"));
EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
parseDenormalFPAttribute("foo,foo"));
EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
parseDenormalFPAttribute("foo,bar"));
}
TEST(FloatingPointModeTest, RenderDenormalFPAttribute) {
EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
parseDenormalFPAttribute("foo"));
EXPECT_EQ("ieee,ieee",
DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).str());
EXPECT_EQ(",",
DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid).str());
EXPECT_EQ(
"preserve-sign,preserve-sign",
DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign).str());
EXPECT_EQ(
"positive-zero,positive-zero",
DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero).str());
EXPECT_EQ(
"ieee,preserve-sign",
DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign).str());
EXPECT_EQ(
"preserve-sign,ieee",
DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE).str());
EXPECT_EQ(
"preserve-sign,positive-zero",
DenormalMode(DenormalMode::PreserveSign, DenormalMode::PositiveZero).str());
}
TEST(FloatingPointModeTest, DenormalModeIsSimple) {
EXPECT_TRUE(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).isSimple());
EXPECT_FALSE(DenormalMode(DenormalMode::IEEE,
DenormalMode::Invalid).isSimple());
EXPECT_FALSE(DenormalMode(DenormalMode::PreserveSign,
DenormalMode::PositiveZero).isSimple());
}
TEST(FloatingPointModeTest, DenormalModeIsValid) {
EXPECT_TRUE(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).isValid());
EXPECT_FALSE(DenormalMode(DenormalMode::IEEE, DenormalMode::Invalid).isValid());
EXPECT_FALSE(DenormalMode(DenormalMode::Invalid, DenormalMode::IEEE).isValid());
EXPECT_FALSE(DenormalMode(DenormalMode::Invalid,
DenormalMode::Invalid).isValid());
}
TEST(FloatingPointModeTest, DenormalModeConstructor) {
EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
DenormalMode::getInvalid());
EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
DenormalMode::getIEEE());
EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
DenormalMode::getPreserveSign());
EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
DenormalMode::getPositiveZero());
}
}